Last active
August 29, 2015 13:57
-
-
Save vidluther/9370018 to your computer and use it in GitHub Desktop.
with and without hints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT count(DISTINCT a.id) FROM wp_bp_activity a USE INDEX (type) WHERE a.is_spam = 0 AND a.id IN (957935) AND a.type != 'activity_comment' ORDER BY a.date_recorded DESC | |
-> ; | |
+----------------------+ | |
| count(DISTINCT a.id) | | |
+----------------------+ | |
| 1 | | |
+----------------------+ | |
1 row in set (2.31 sec) | |
mysql> SELECT count(DISTINCT a.id) FROM wp_bp_activity a WHERE a.is_spam = 0 AND a.id IN (957935) AND a.type != 'activity_comment' ORDER BY a.date_recorded DESC; | |
+----------------------+ | |
| count(DISTINCT a.id) | | |
+----------------------+ | |
| 1 | | |
+----------------------+ | |
1 row in set (0.00 sec) | |
# To prove it's not a query cache.. | |
SELECT count(DISTINCT a.id) FROM wp_bp_activity a WHERE a.is_spam = 0 AND a.id IN (957925) AND a.type != 'activity_comment' ORDER BY a.date_recorded DESC; | |
+----------------------+ | |
| count(DISTINCT a.id) | | |
+----------------------+ | |
| 0 | | |
+----------------------+ | |
1 row in set (0.00 sec) | |
mysql> SELECT count(DISTINCT a.id) FROM wp_bp_activity a USE INDEX (type) WHERE a.is_spam = 0 AND a.id IN (957925) AND a.type != 'activity_comment' ORDER BY a.date_recorded DESC; | |
+----------------------+ | |
| count(DISTINCT a.id) | | |
+----------------------+ | |
| 0 | | |
+----------------------+ | |
1 row in set (3.86 sec) | |
### Explain with the HINT | |
EXPLAIN SELECT count(DISTINCT a.id) FROM wp_bp_activity a USE INDEX (type) WHERE a.is_spam = 0 AND a.id IN (957935) AND a.type != 'activity_comment' ORDER BY a.date_recorded DESC | |
-> ; | |
+----+-------------+-------+-------+---------------+------+---------+------+--------+-------------+ | |
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | | |
+----+-------------+-------+-------+---------------+------+---------+------+--------+-------------+ | |
| 1 | SIMPLE | a | range | type | type | 227 | NULL | 620546 | Using where | | |
+----+-------------+-------+-------+---------------+------+---------+------+--------+-------------+ | |
1 row in set (0.00 sec) | |
### Explain without the Hint | |
EXPLAIN SELECT count(DISTINCT a.id) FROM wp_bp_activity a WHERE a.is_spam = 0 AND a.id IN (957935) AND a.type != 'activity_comment' ORDER BY a.date_recorded DESC; | |
+----+-------------+-------+-------+----------------------+---------+---------+-------+------+-------+ | |
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | | |
+----+-------------+-------+-------+----------------------+---------+---------+-------+------+-------+ | |
| 1 | SIMPLE | a | const | PRIMARY,type,is_spam | PRIMARY | 8 | const | 1 | | | |
+----+-------------+-------+-------+----------------------+---------+---------+-------+------+-------+ | |
1 row in set (0.01 sec) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment