Last active
August 29, 2015 14:26
-
-
Save karupanerura/c2bd0bb3ae0c6d40bdf1 to your computer and use it in GitHub Desktop.
Using filesortが付くのが納得いかない…。
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
CREATE TABLE `foo` ( | |
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, | |
`created_at` datetime NOT NULL, | |
PRIMARY KEY (`id`,`created_at`) | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8 | |
PARTITION BY RANGE COLUMNS(created_at) ( | |
PARTITION p201505 VALUES LESS THAN ('2015-06-01') COMMENT = '2015-06-01' ENGINE = InnoDB, | |
PARTITION p201506 VALUES LESS THAN ('2015-07-01') COMMENT = '2015-07-01' ENGINE = InnoDB, | |
PARTITION p201507 VALUES LESS THAN ('2015-08-01') COMMENT = '2015-08-01' ENGINE = InnoDB, | |
PARTITION p201508 VALUES LESS THAN ('2015-09-01') ENGINE = InnoDB | |
); |
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 `id`, `created_at` FROM `foo` WHERE `id` IN (1, 2, 3, 4, 5) ORDER BY created_at DESC LIMIT 5; |
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
+----+-------------+---------------+---------------------------------+-------+---------------+---------+---------+------+------+------------------------------------------+ | |
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | Extra | | |
+----+-------------+---------------+---------------------------------+-------+---------------+---------+---------+------+------+------------------------------------------+ | |
| 1 | SIMPLE | foo | p201505,p201506,p201507,p201508 | range | PRIMARY | PRIMARY | 4 | NULL | 15 | Using where; Using index; Using filesort | | |
+----+-------------+---------------+---------------------------------+-------+---------------+---------+---------+------+------+------------------------------------------+ | |
1 row in set (0.00 sec) |
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
[root@localhost] test> SHOW INDEX FROM foo; | |
+---------------+------------+------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | |
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | | |
+---------------+------------+------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | |
| foo | 0 | PRIMARY | 1 | id | A | XXXXXXXX | NULL | NULL | | BTREE | | | | |
| foo | 0 | PRIMARY | 2 | created_at | A | XXXXXXXX | NULL | NULL | | BTREE | | | | |
+---------------+------------+------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | |
4 rows in set (0.91 sec) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment