1
我使用Django上webfaction,和我有一個「MySQL查詢時間太長」的消息, 的SQL是MySQL查詢時間太長 - Django的上webfaction
SELECT (1) AS `a` FROM `main_userprofile` WHERE `main_userprofile`.`id` = 98
這是一個相當簡單的SQL ,爲什麼查詢時間過長?
這裏是 '創建表':
main_userprofile | CREATE TABLE `main_userprofile` ( `id` int(11) NOT NULL auto_increment, `user_id` int(11) NOT NULL, `sex` smallint(6) NOT NULL, `active_number` varchar(64) NOT NULL, `phone_number` varchar(32) NOT NULL, `work_number` varchar(32) NOT NULL, ... ... PRIMARY KEY (`id`), UNIQUE KEY `user_id` (`user_id`) ) ENGINE=MyISAM AUTO_INCREMENT=1652 DEFAULT CHARSET=utf8 |
的id是主鍵
的解釋:
explain SELECT (1) AS `a` FROM `main_userprofile` WHERE `main_userprofile`.`id` = 98; +----+-------------+------------------+-------+---------------+---------+---------+-------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+------------------+-------+---------------+---------+---------+-------+------+-------------+ | 1 | SIMPLE | main_userprofile | const | PRIMARY | PRIMARY | 4 | const | 1 | Using index | +----+-------------+------------------+-------+---------------+---------+---------+-------+------+-------------+
EXPLAIN PLAN在運行查詢時告訴你什麼? – 2010-04-13 06:44:14
嘗試用mysqlcheck的檢查表 (http://dev.mysql.com/doc/refman/5.0/en/mysqlcheck.html) – newtover 2010-04-15 08:06:07