mysql> CREATE TABLE `ptest` (
-> `id` int(11) NOT NULL AUTO_INCREMENT,
-> name char(15),
-> PRIMARY KEY (`id`,`name`)
-> ) ENGINE=InnoDB
-> PARTITION BY LINEAR KEY(`name`)
-> PARTITIONS 3;
Query OK, 0 rows affected (0.27 sec)
mysql> insert into ptest(name) values('orders_id'),('products_id'),('customers_id');
Query OK, 3 rows affected (0.08 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> EXPLAIN PARTITIONS SELECT count(*) FROM ptest WHERE name = 'orders_id';
+----+-------------+-------+------------+-------+---------------+---------+---------+------+------+--------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------------+-------+---------------+---------+---------+------+------+--------------------------+
| 1 | SIMPLE | ptest | p1 | index | NULL | PRIMARY | 19 | NULL | 2 | Using where; Using index |
+----+-------------+-------+------------+-------+---------------+---------+---------+------+------+--------------------------+
1 row in set (0.00 sec)
mysql> insert into ptest(name) values('orders_id'),('products_id'),('customers_id'), ('order_id');
Query OK, 4 rows affected (0.10 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> EXPLAIN PARTITIONS SELECT count(*) FROM ptest WHERE name = 'orders_id';
+----+-------------+-------+------------+-------+---------------+---------+---------+------+------+--------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------------+-------+---------------+---------+---------+------+------+--------------------------+
| 1 | SIMPLE | ptest | p1 | index | NULL | PRIMARY | 19 | NULL | 4 | Using where; Using index |
+----+-------------+-------+------------+-------+---------------+---------+---------+------+------+--------------------------+
1 row in set (0.00 sec)
mysql> EXPLAIN PARTITIONS SELECT count(*) FROM ptest WHERE name = 'order_id';
+----+-------------+-------+------------+-------+---------------+---------+---------+------+------+--------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------------+-------+---------------+---------+---------+------+------+--------------------------+
| 1 | SIMPLE | ptest | p2 | index | NULL | PRIMARY | 19 | NULL | 3 | Using where; Using index |
+----+-------------+-------+------------+-------+---------------+---------+---------+------+------+--------------------------+
1 row in set (0.00 sec)
mysql> EXPLAIN PARTITIONS SELECT count(*) FROM ptest WHERE name = 'products_id';
+----+-------------+-------+------------+-------+---------------+---------+---------+------+------+--------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------------+-------+---------------+---------+---------+------+------+--------------------------+
| 1 | SIMPLE | ptest | p1 | index | NULL | PRIMARY | 19 | NULL | 4 | Using where; Using index |
+----+-------------+-------+------------+-------+---------------+---------+---------+------+------+--------------------------+
1 row in set (0.00 sec)