我有这种形式的插入查询:
on INSERT into abc values .... on DUPLICATE KEY UPDATE ....
在我没有分区的原始表中,唯一键是打开的,(subject_id, object_id)
但现在我正在分区ts
,我被迫拥有唯一键,(subject_id, object_id, ts)
因为 mysql 要求在所有唯一键中都有分区键。
这意味着我的插入查询将失败,因为插入具有相同的 subject_id 和 object_id(来自以前的插入),但不同的时间戳将被视为唯一的新行,并将被插入而不是所需的更新。
有什么解决方法吗?
CREATE TABLE `abc` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`subject_id` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
`object_id` varchar(36) COLLATE utf8_unicode_ci NOT NULL,
`ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`,`ts`),
UNIQUE KEY `userint_sub_type_obj` (`subject_id`,`object_id`, `ts`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
/*!50100 PARTITION BY RANGE (unix_timestamp(ts))
(PARTITION p2012_08_27 VALUES LESS THAN (1346025600) ENGINE = InnoDB,
PARTITION p2012_08_28 VALUES LESS THAN (1346112000) ENGINE = InnoDB,
PARTITION p2012_08_29 VALUES LESS THAN (1346198400) ENGINE = InnoDB,
PARTITION p2012_08_30 VALUES LESS THAN (1346284800) ENGINE = InnoDB,
PARTITION p2012_08_31 VALUES LESS THAN (1346371200) ENGINE = InnoDB) */