2
votes

I use django on webfaction, and I've got a "MySql query taking too long" message, the sql is

SELECT (1) AS `a` FROM `main_userprofile` WHERE `main_userprofile`.`id` = 98

This is a rather simple sql, why the query taken too long?

here it is the 'create table':

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 | 

the id is the primary key

the explain:

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 | 
+----+-------------+------------------+-------+---------------+---------+---------+-------+------+-------------+
1
what does EXPLAIN PLAN tell you when you run the query?Lieven Keersmaekers
try to check the table with mysqlcheck (dev.mysql.com/doc/refman/5.0/en/mysqlcheck.html)newtover

1 Answers

0
votes

Seems like id is not indexed, isn't it. Is id the primary key of your table? Could you post the result of SHOW CREATE TABLE main_userprofile;?