探索mysql的分区

下面的表employees是根据store_id列值来进行分区的——用range来分区的
CREATE TABLE employees (
    id INT NOT NULL,
    fname VARCHAR(30),
    lname VARCHAR(30),
    hired DATE NOT NULL DEFAULT '1970-01-01',
    separated DATE NOT NULL DEFAULT '9999-12-31',
    job_code INT NOT NULL,
    store_id INT NOT NULL
)
PARTITION BY RANGE (store_id) (
    PARTITION p0 VALUES LESS THAN (6),
    PARTITION p1 VALUES LESS THAN (11),
    PARTITION p2 VALUES LESS THAN (16),  PARTITION p3 VALUES LESS THAN MAXVALUE );

下面的代码是list而不是range来分区的,根据store_id的值来进行分区

CREATE TABLE employees (
    id INT NOT NULL,
    fname VARCHAR(30),
    lname VARCHAR(30),
    hired DATE NOT NULL DEFAULT '1970-01-01',
    separated DATE NOT NULL DEFAULT '9999-12-31',
    job_code INT,
    store_id INT
)
PARTITION BY LIST(store_id) (
    PARTITION pNorth VALUES IN (3,5,6,9,17),
    PARTITION pEast VALUES IN (1,2,10,11,19,20),
    PARTITION pWest VALUES IN (4,12,13,14,18),
    PARTITION pCentral VALUES IN (7,8,15,16)
);


下面的语句可以查看每一个分区里有多少行记录
mysql> SELECT PARTITION_NAME,TABLE_ROWS -> FROM INFORMATION_SCHEMA.PARTITIONS -> WHERE TABLE_NAME = 'employees'; 
+----------------+------------+
| PARTITION_NAME | TABLE_ROWS |
  p0               1

p1 4

p2 0

p3 0

下面这条语句返回的是p1分区中的所有记录:
SELECT * FROM employees PARTITION (p1);

你可能感兴趣的:(mysql,list,Partitioning,range)