zabbix大表分区优化

history_uint表日增长5000w,分区表结构如下

CREATE TABLE `history_uint` (
  `itemid` bigint(20) unsigned NOT NULL,
  `clock` int(11) NOT NULL DEFAULT '0',
  `value` bigint(20) unsigned NOT NULL DEFAULT '0',
  `ns` int(11) NOT NULL DEFAULT '0',
  KEY `history_unit_x` (`itemid`,`clock`) USING BTREE
)ENGINE=InnoDB
PARTITION BY RANGE(clock)
SUBPARTITION BY HASH(itemid)
SUBPARTITIONS 16
( PARTITION p20181201 VALUES LESS THAN (1545580800),
  PARTITION p20190101 VALUES LESS THAN (1546790400),
  PARTITION p20190201 VALUES LESS THAN (1549209600),
  PARTITION p20190301 VALUES LESS THAN (1551628800) 
)

获取时间戳:

select UNIX_TIMESTAMP('2019-04-01')

增加分区:

ALTER TABLE history_uint ADD PARTITION (PARTITION  p20190401  VALUES LESS THAN (1552233600));

建议:创建分区的同时建议插入测试数据生成子分区,不然在高并发下会有大量Waiting for table metadata lock

删除分区:

ALTER TABLE history_uint TRUNCATE PARTITION p20181201;

ALTER TABLE history_uint drop PARTITION  p20181201

分析分区:

ALTER TABLE history_uint ANALYZE PARTITION  p20181201

ALTER TABLE history_uint CHECK PARTITION  p20181201

ALTER TABLE history_uint OPTIMIZE PARTITION  p20181201

 

获取分区表信息:

SELECT  *  FROM information_schema.partitions  WHERE  table_name = 'history_uint'

你可能感兴趣的:(表空间)