mercredi 7 janvier 2015

MySQL explain qury: using temporary table vs more rows examined


Can you tell me which explain plan is better?!


First:



+----+-------------+-------+-------+---------------+------+---------+------+--------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+------+---------+------+--------+--------------------------+
| 1 | SIMPLE | a | range | uni | uni | 11 | NULL | 122431 | Using where; Using index |
+----+-------------+-------+-------+---------------+------+---------+------+--------+--------------------------+
1 row in set (0.00 sec)


Second:



+----+-------------+-------+-------+--------------------------------------------+------------------+---------+------+-------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+--------------------------------------------+------------------+---------+------+-------+----------------------------------------------+
| 1 | SIMPLE | a | range | uni,cid_tgid_mediaid,cid_tgid_clickmediaid | cid_tgid_mediaid | 8 | NULL | 15197 | Using where; Using temporary; Using filesort |
+----+-------------+-------+-------+--------------------------------------------+------------------+---------+------+-------+----------------------------------------------+
1 row in set (0.00 sec)


For the first query I forced mysql to use unique index but I got 122431 examined. In the second explain query mysql used a index and it created a temporary table but there is less rows examined.


Can you help me?





Aucun commentaire:

Enregistrer un commentaire