简体   繁体   English

Mysql查询花费的时间太长-WebFaction上的Django

[英]MySql query taking too long - django on webfaction

I use django on webfaction, and I've got a "MySql query taking too long" message, the sql is 我在webfaction上使用django,并且出现了“ MySql查询花费的时间太长”的消息,sql是

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

This is a rather simple sql, why the query taken too long? 这是一个相当简单的sql,为什么查询花费的时间太长?

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 id是主键

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 | 
+----+-------------+------------------+-------+---------------+---------+---------+-------+------+-------------+

Seems like id is not indexed, isn't it. 好像id没有被索引,不是吗。 Is id the primary key of your table? id是表的主键吗? Could you post the result of SHOW CREATE TABLE main_userprofile; 您可以发布SHOW CREATE TABLE main_userprofile;的结果SHOW CREATE TABLE main_userprofile; ?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM