我使用sqlyog图形编辑器运行一条sql语句,想用extrt看看它到底使用了那条索引。该如何弄?

解决方案 »

  1.   


    mysql> explain select * from TableName12 limit 1;
    +----+-------------+-------------+------+---------------+------+---------+------+------+-------+
    | id | select_type | table       | type | possible_keys | key  | key_len | ref  | rows | Extra |
    +----+-------------+-------------+------+---------------+------+---------+------+------+-------+
    |  1 | SIMPLE      | TableName12 | ALL  | NULL          | NULL | NULL    | NULL |    1 |       | 
    +----+-------------+-------------+------+---------------+------+---------+------+------+-------+
      

  2.   

    哟西,原来是关键字哦。。了解了。请问一下,我在goods_id,goods_sn,goods_name上建立了联合索引,但是查询的时候没有使用到explain select * from ecs_goods where goods_id > 1000 and goods_sn = 000181 and goods_name = '商品' goods_id是主键
      

  3.   

    show index from ecs_goods 看一下你的索引信息以供分析。不使用索引的原因很多。 比如有索引,但MYSQL认为使用索引开销更大。 或者你创建的索引根本不对。
    create index xxx on ecs_goods (goods_sn ,goods_name ,goods_id )
      

  4.   

    看了下说明。原来type里算ALL就不用了。靠!