--查看具体分区条件
mysql> select table_name,partition_name,PARTITION_METHOD ,PARTITION_EXPRESSION, partition_DESCRIPTION -> from information_schema.partitions -> where table_schema='sztech' -> and PARTITION_METHOD is not null -> ; +--------------+----------------+------------------+----------------------+-----------------------+ | table_name | partition_name | PARTITION_METHOD | PARTITION_EXPRESSION | partition_DESCRIPTION | +--------------+----------------+------------------+----------------------+-----------------------+ | orders_hash | p0 | HASH | id | NULL | | orders_hash | p1 | HASH | id | NULL | | orders_hash | p2 | HASH | id | NULL | | orders_hash | p3 | HASH | id | NULL | | orders_list | p0 | LIST | store_id | 1,3,4,17 | | orders_list | p1 | LIST | store_id | 2,12,14 | | orders_list | p3 | LIST | store_id | 6,8,20 | | orders_list | p4 | LIST | store_id | 5,7,9 | | orders_list | p2 | LIST | store_id | 10,13,15,18 | | orders_list | p5 | LIST | store_id | 19 | | orders_range | p0 | RANGE | id | 10000 | | orders_range | p1 | RANGE | id | 20000 | | orders_range | p2 | RANGE | id | 30000 | | orders_range | p3 | RANGE | id | 40000 | | orders_range | p4 | RANGE | id | 50000 | +--------------+----------------+------------------+----------------------+-----------------------+ 15 rows in set (0.00 sec)
--查看sql语句使用了哪些分区:可以使用 explain partitions
20000以内,有两个分区 mysql> explain partitions select count(*) from orders_range where id<20000\G
*************************** 1. row *************************** id: 1 select_type: SIMPLE table: orders_range partitions: p0,p1 type: range possible_keys: PRIMARY key: PRIMARY key_len: 4 ref: NULL rows: 9999 Extra: Using where; Using index 1 row in set (0.00 sec)
10000 到 20000,只有一个分区 mysql> explain partitions select count(*) from orders_range where id<20000 and id>10000 \G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: orders_range partitions: p1 type: range possible_keys: PRIMARY key: PRIMARY key_len: 4 ref: NULL rows: 5000 Extra: Using where; Using index 1 row in set (0.00 sec)
mysql> |