MySQLでインデックスが効いているか確かめる方法

explain SELECT ~~

もしくは

desc SELECT ~~

これで調べられる.

possible_keys は候補の鍵,
key は実際に使われている鍵.

mysql> explain select id from data where id=10102 and flg!=2;

                                                                                                                                                                                                              • +
id select_type table type possible_keys key key_len ref rows Extra
                                                                                                                                                                                                              • +
1 SIMPLE user_card ref PRIMARY,i2 PRIMARY 4 const 18 Using where
                                                                                                                                                                                                              • +

1 row in set (0.00 sec)