Created
February 3, 2015 05:07
-
-
Save yoku0825/d94e1b1af0b2a794fd54 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
mysql56> CREATE TABLE t1 (num int, val varchar(32), key(num)); | |
Query OK, 0 rows affected (0.03 sec) | |
mysql56> | |
mysql56> INSERT INTO t1 VALUES (1, 'one'); | |
Query OK, 1 row affected (0.01 sec) | |
mysql56> | |
mysql56> EXPLAIN SELECT * FROM t1 WHERE num = 1; | |
+----+-------------+-------+------+---------------+------+---------+-------+------+-------+ | |
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | | |
+----+-------------+-------+------+---------------+------+---------+-------+------+-------+ | |
| 1 | SIMPLE | t1 | ref | num | num | 5 | const | 1 | NULL | | |
+----+-------------+-------+------+---------------+------+---------+-------+------+-------+ | |
1 row in set (0.00 sec) | |
mysql56> EXPLAIN SELECT * FROM t1 WHERE num = 1 ORDER BY val; | |
+----+-------------+-------+------+---------------+------+---------+-------+------+-----------------------------+ | |
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | | |
+----+-------------+-------+------+---------------+------+---------+-------+------+-----------------------------+ | |
| 1 | SIMPLE | t1 | ref | num | num | 5 | const | 1 | Using where; Using filesort | | |
+----+-------------+-------+------+---------------+------+---------+-------+------+-----------------------------+ | |
1 row in set (0.00 sec) | |
mysql56> | |
mysql56> ALTER TABLE t1 ADD UNIQUE KEY (num); | |
Query OK, 0 rows affected (0.04 sec) | |
Records: 0 Duplicates: 0 Warnings: 0 | |
mysql56> | |
mysql56> EXPLAIN SELECT * FROM t1 WHERE num = 1 ORDER BY val; | |
+----+-------------+-------+-------+---------------+-------+---------+-------+------+-------+ | |
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | | |
+----+-------------+-------+-------+---------------+-------+---------+-------+------+-------+ | |
| 1 | SIMPLE | t1 | const | num_2,num | num_2 | 5 | const | 1 | NULL | | |
+----+-------------+-------+-------+---------------+-------+---------+-------+------+-------+ | |
1 row in set (0.00 sec) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment