简体   繁体   English

mysql索引未优化查询

[英]mysql index not optimizing query

I have mysql MyISAM table on which I am doing a simple select id from mytable limit 1; 我有mysql MyISAM表,我正在select id from mytable limit 1;做一个简单的select id from mytable limit 1; . This just freezes the system. 这只会冻结系统。

I tried explain select id from mytable limit 1; 我试图explain select id from mytable limit 1; . Again it freezes my system. 再次冻结了我的系统。 Table demographics: 50k records, 10 mbs size, 2 indexes (primary key autoincrement), 8 columns. 表的人口统计数据:50k记录,10 mbs大小,2个索引(主键自动递增),8列。

I am clueless why the explain statement failed, as it is supposed to display the query plan, nothing else. 我不知道为什么explain语句失败,因为它应该显示查询计划,而没有别的。 Neither the table size is enormous nor the number of records, then why is mysql working so slow? 表的大小既不是巨大的,也不是记录的数目,那么为什么mysql运行这么慢? Rather, what am I missing here? 相反,我在这里想念什么?

It was due a waiting state on mytable. 这是由于mytable处于等待状态。 eggyal gave me the clue to use show processlist . eggyal给了我使用show processlist的线索。 It showed: 这显示了:

+-----+---------+-----------------+----------------+---------+------+---------------------------------+----------------------------------------------------+
| Id  | User    | Host            | db             | Command | Time | State                           | Info                                               |
+-----+---------+-----------------+----------------+---------+------+---------------------------------+----------------------------------------------------+
| 349 | root    | localhost:56612 | mydb           | Query   | 3582 | Waiting for table metadata lock | ALTER TABLE `mytable` ADD INDEX(`fk_to_02`) |

I planted a kill 349 to terminate that wait chain, and now the explain statement works as expected. 我植入了kill 349来终止该等待链,现在说明语句可以按预期工作。

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

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