简体   繁体   中英

mysql index not optimizing query

I have mysql MyISAM table on which I am doing a simple select id from mytable limit 1; . This just freezes the system.

I tried 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.

I am clueless why the explain statement failed, as it is supposed to display the query plan, nothing else. Neither the table size is enormous nor the number of records, then why is mysql working so slow? Rather, what am I missing here?

It was due a waiting state on mytable. eggyal gave me the clue to use 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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