【 TiDB 使用环境】生产环境 /测试/ Poc
【 TiDB 版本】v6.5.2 v7.5.2 v8.1.0
【复现路径】创建column range 分区表,插入数据,新增分区,插入重复数据
【遇到的问题:问题现象及影响】违背唯一约束,插入了重复数据
截图此页面*
-- 创建分区表
CREATE TABLE `p1` (
`id` bigint(12) NOT NULL,
`create_time` datetime NOT NULL,
`brand_type` varchar(8) NOT NULL DEFAULT 'Y' COMMENT '品牌',
PRIMARY KEY (`id`,`create_time`,`brand_type`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY RANGE COLUMNS(`brand_type`,`create_time`)
(
PARTITION `p20240520A` VALUES LESS THAN ('A','2024-05-20 00:00:00'),
PARTITION `p20240520B` VALUES LESS THAN ('B','2024-05-20 00:00:00'),
PARTITION `p20240520C` VALUES LESS THAN ('C','2024-05-20 00:00:00'),
PARTITION `p20240520Z` VALUES LESS THAN ('Z','2024-05-20 00:00:00'));
-- 插入数据
INSERT INTO `test`.`p1`(`id`, `create_time`, `brand_type`) VALUES (1, '2024-05-19 00:00:01', 'A');
INSERT INTO `test`.`p1`(`id`, `create_time`, `brand_type`) VALUES (2, '2024-05-19 00:00:01', 'B');
INSERT INTO `test`.`p1`(`id`, `create_time`, `brand_type`) VALUES (3, '2024-05-19 00:00:01', 'C');
INSERT INTO `test`.`p1`(`id`, `create_time`, `brand_type`) VALUES (4, '2024-05-19 00:00:01', 'Z');
-- 添加分区
alter table test.p1 add PARTITION (
PARTITION `p20240521A` VALUES LESS THAN ('A','2024-05-21 00:00:00'),
PARTITION `p20240521B` VALUES LESS THAN ('B','2024-05-21 00:00:00'),
PARTITION `p20240521C` VALUES LESS THAN ('C','2024-05-21 00:00:00'),
PARTITION `p20240521Z` VALUES LESS THAN ('Z','2024-05-21 00:00:00'));
-- 本该失败,却插入成功
INSERT INTO `test`.`p1`(`id`, `create_time`, `brand_type`) VALUES (2, '2024-05-19 00:00:01', 'B');
INSERT INTO `test`.`p1`(`id`, `create_time`, `brand_type`) VALUES (3, '2024-05-19 00:00:01', 'C');
INSERT INTO `test`.`p1`(`id`, `create_time`, `brand_type`) VALUES (4, '2024-05-19 00:00:01', 'Z');
select * from test.p1;