因为表量已经达到1个亿了。现在想做个优化,先按照 create_time 时间进行分区吧。
create_time 是varchar类型。
CREATE TABLE orders (id varchar(40) NOT NULL ,order_no VARCHAR(20) NOT NULL,create_time VARCHAR(20) NOT NULL,amount DECIMAL(10,2) NOT NULL,PRIMARY KEY (id, create_time)
) ENGINE=InnoDB
PARTITION BY range columns(create_time)
(PARTITION p_2018 VALUES LESS THAN ('2019'),PARTITION p_2019 VALUES LESS THAN ('2020'),PARTITION p_2020 VALUES LESS THAN ('2021'),PARTITION p_other VALUES LESS THAN MAXVALUE
);
插入数据的截图:
然后查看各个分区表的数据量:
SELECT PARTITION_NAME,TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME = 'orders(这里是填表名)';