mysql 唯一性约束报错_怪异的MySQL Online DDL报错Duplicate entry

今天线上执行Online DDL的时候发现一个奇怪的报错,觉得比较意义,遂整理如下。线上数据库版本:percona server 5.7.14

报错现场:每次执行的时候重复报错记录都不一样

mysql> ALTER TABLE `xxx` modify `bm_pay_trade_no` varchar(50) NOT NULL COMMENT 'xxxx';

ERROR 1062 (23000): Duplicate entry 'sss' for key 'uniq_xxx'

mysql> select * from xxx where xxxx='sss';

...此处只有一条记录,并没有重复值...

按照常理来说这列有唯一索引约束不应该报错的哈,更不会产生Duplicate entry。我隐约记得这个问题很熟悉,貌似之前在哪遇到过。可以看我之前文章MySQL Online DDL和MySQL在线DDL工具pt-osc。

看看官网的解释吧:https://dev.mysql.com/doc/refman/5.7/en/innodb-create-index-limitations.html

When running an online DDL operation, the thread that runs the ALTER TABLE statement applies an “online log” of DML operations that were run concurrently on the same table from other connection threads. When the DML operations are applied, it is possible to encounter a dup

你可能感兴趣的:(mysql,唯一性约束报错)