Skip to content

Commit

Permalink
WL#12589 - Add more information to Duplicate Key Error
Browse files Browse the repository at this point in the history
Description:
The current error information for duplicate key lists
the key value and key name. In some scenarios this
may not be sufficient.

Solution:
Add the tablename for the key into the error message.

Changed the contribution patch, as guidelines
urges us not to implement any new options.
The extended error information on the duplicate key is now
default. Due to internal policy it was not fitting to
include the query text as part of the error message.
A lot of tests was re recorded and changed.

Many thanks to Facebook for this idea.

Change-Id: Iaa1305e2732415a1c197b262160b0d91af11936d
  • Loading branch information
jensevenb committed Jul 5, 2019
1 parent ea37c29 commit 045af14
Show file tree
Hide file tree
Showing 289 changed files with 3,607 additions and 3,582 deletions.
2 changes: 1 addition & 1 deletion mysql-test/extra/binlog_tests/binlog.test
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ SHOW SESSION VARIABLES LIKE "%_checks";
--echo # INSERT INTO t1 VALUES(2)
--echo # foreign_key_checks=1 and unique_checks=1
--echo # It should not change current session's variables, even error happens
call mtr.add_suppression("Slave SQL.*Could not execute Write_rows_v1 event on table test.t1; Duplicate entry .2. for key .PRIMARY., Error_code: 1062");
call mtr.add_suppression("Slave SQL.*Could not execute Write_rows_v1 event on table test.t1; Duplicate entry .2. for key .t1.PRIMARY., Error_code: 1062");
--error 1062
BINLOG '
dfLtTBMBAAAAKQAAAKsBAAAAABcAAAAAAAEABHRlc3QAAnQxAAEDAAE=
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/extra/rpl_tests/rpl_conflicts.test
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ if (`SELECT @@global.binlog_format != 'ROW' OR @@global.slave_exec_mode = 'STRIC
--let $errno= query_get_value("SHOW SLAVE STATUS", Last_SQL_Errno, 1)
--eval SELECT "$errno" as 'Last_SQL_Errno'

call mtr.add_suppression("Slave SQL.*Duplicate entry .1. for key .PRIMARY.* Error_code: MY-001062");
call mtr.add_suppression("Slave SQL.*Duplicate entry .1. for key .t1.PRIMARY.* Error_code: MY-001062");
call mtr.add_suppression("The slave coordinator and worker threads are stopped, possibly leaving data in inconsistent state");

SELECT * FROM t1;
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/extra/rpl_tests/rpl_loaddata.test
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ save_master_pos;
connection slave;
# 1062 = ER_DUP_ENTRY
--let $er_inconsistent_error= convert_error(ER_INCONSISTENT_ERROR)
call mtr.add_suppression("Slave SQL.*Error .Duplicate entry .10. for key .b.. on query.* Error_code: MY-001062");
call mtr.add_suppression("Slave SQL.*Error .Duplicate entry .10. for key .t1.b.. on query.* Error_code: MY-001062");
--eval call mtr.add_suppression("Slave SQL.*Query caused different errors on master and slave.*Error on master:.*error code=1062.*Error on slave:.*Error_code: MY-0$er_inconsistent_error")
call mtr.add_suppression("The slave coordinator and worker threads are stopped, possibly leaving data in inconsistent state");
--let $slave_sql_errno= 1062
Expand Down
12 changes: 6 additions & 6 deletions mysql-test/r/auto_increment.result
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
Warnings:
Note 1003 /* select#1 */ select last_insert_id() AS `last_insert_id()`
insert into t1 set i = 254;
ERROR 23000: Duplicate entry '254' for key 'PRIMARY'
ERROR 23000: Duplicate entry '254' for key 't1.PRIMARY'
select last_insert_id();
last_insert_id()
255
insert into t1 set i = null;
ERROR 23000: Duplicate entry '255' for key 'PRIMARY'
ERROR 23000: Duplicate entry '255' for key 't1.PRIMARY'
select last_insert_id();
last_insert_id()
255
Expand Down Expand Up @@ -187,7 +187,7 @@ select last_insert_id();
last_insert_id()
2
insert into t1 values (NULL, 10);
ERROR 23000: Duplicate entry '10' for key 'b'
ERROR 23000: Duplicate entry '10' for key 't1.b'
select last_insert_id();
last_insert_id()
2
Expand Down Expand Up @@ -440,7 +440,7 @@ key (rowid), unique(val));
replace into t1 (val) values ('1'),('2');
replace into t1 (val) values ('1'),('2');
insert into t1 (val) values ('1'),('2');
ERROR 23000: Duplicate entry '1' for key 'val'
ERROR 23000: Duplicate entry '1' for key 't1.val'
select * from t1;
rowid val
3 1
Expand All @@ -462,7 +462,7 @@ Warning 1681 Integer display width is deprecated and will be removed in a future
INSERT INTO t1 VALUES(0, 0);
INSERT INTO t1 VALUES(1, 1);
ALTER TABLE t1 CHANGE t1 t1 INT(10) auto_increment;
ERROR 23000: ALTER TABLE causes auto_increment resequencing, resulting in duplicate entry '1' for key 'PRIMARY'
ERROR 23000: ALTER TABLE causes auto_increment resequencing, resulting in duplicate entry '1' for key 't1.PRIMARY'
DROP TABLE t1;
create table t1 (a int primary key auto_increment, b int, c int, d timestamp default current_timestamp, unique(b),unique(c));
insert into t1 values(null,1,1,now());
Expand All @@ -488,7 +488,7 @@ CREATE TABLE t1 ( a INT );
INSERT INTO t1 VALUES (1), (1);
CREATE TABLE t2 ( a INT AUTO_INCREMENT KEY );
INSERT INTO t2 SELECT a FROM t1;
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
ERROR 23000: Duplicate entry '1' for key 't2.PRIMARY'
UPDATE t2 SET a = 2;
SELECT a FROM t2;
a
Expand Down
56 changes: 28 additions & 28 deletions mysql-test/r/commit_1innodb.result
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ set autocommit=0;
flush status;
insert into t2 (a) values (1001);
insert into t1 (a) values (f2(1));
ERROR 23000: Duplicate entry '1' for key 'a'
ERROR 23000: Duplicate entry '1' for key 't2.a'
select * from t2;
a
1001
Expand All @@ -35,7 +35,7 @@ select * from t2;
a
insert into t2 (a) values (1002);
insert into t3 (a) select f2(2) from t1;
ERROR 23000: Duplicate entry '2' for key 'a'
ERROR 23000: Duplicate entry '2' for key 't2.a'
select * from t2;
a
1002
Expand All @@ -44,7 +44,7 @@ select * from t2;
a
insert into t2 (a) values (1003);
update t1 set a= a + f2(3);
ERROR 23000: Duplicate entry '3' for key 'a'
ERROR 23000: Duplicate entry '3' for key 't2.a'
select * from t2;
a
1003
Expand All @@ -53,7 +53,7 @@ select * from t2;
a
insert into t2 (a) values (1004);
update t1, t3 set t1.a = 0, t3.a = 0 where (f2(4) = 4) and (t1.a = t3.a);
ERROR 23000: Duplicate entry '4' for key 'a'
ERROR 23000: Duplicate entry '4' for key 't2.a'
select * from t2;
a
1004
Expand All @@ -62,7 +62,7 @@ select * from t2;
a
insert into t2 (a) values (1005);
delete from t1 where (a = f2(5));
ERROR 23000: Duplicate entry '5' for key 'a'
ERROR 23000: Duplicate entry '5' for key 't2.a'
select * from t2;
a
1005
Expand All @@ -71,7 +71,7 @@ select * from t2;
a
insert into t2 (a) values (1006);
delete from t1, t3 using t1, t3 where (f2(6) = 6) ;
ERROR 23000: Duplicate entry '6' for key 'a'
ERROR 23000: Duplicate entry '6' for key 't2.a'
select * from t2;
a
1006
Expand All @@ -80,7 +80,7 @@ select * from t2;
a
insert into t2 (a) values (1007);
replace t1 values (f2(7));
ERROR 23000: Duplicate entry '7' for key 'a'
ERROR 23000: Duplicate entry '7' for key 't2.a'
select * from t2;
a
1007
Expand All @@ -89,7 +89,7 @@ select * from t2;
a
insert into t2 (a) values (1008);
replace into t3 (a) select f2(8) from t1;
ERROR 23000: Duplicate entry '8' for key 'a'
ERROR 23000: Duplicate entry '8' for key 't2.a'
select * from t2;
a
1008
Expand All @@ -98,7 +98,7 @@ select * from t2;
a
insert into t2 (a) values (1009);
select f2(9) from t1 ;
ERROR 23000: Duplicate entry '9' for key 'a'
ERROR 23000: Duplicate entry '9' for key 't2.a'
select * from t2;
a
1009
Expand All @@ -107,7 +107,7 @@ select * from t2;
a
insert into t2 (a) values (1010);
show databases where (f2(10) = 10);
ERROR 23000: Duplicate entry '10' for key 'a'
ERROR 23000: Duplicate entry '10' for key 't2.a'
select * from t2;
a
1010
Expand All @@ -116,7 +116,7 @@ select * from t2;
a
insert into t2 (a) values (1011);
show tables where (f2(11) = 11);
ERROR 23000: Duplicate entry '11' for key 'a'
ERROR 23000: Duplicate entry '11' for key 't2.a'
select * from t2;
a
1011
Expand All @@ -125,7 +125,7 @@ select * from t2;
a
insert into t2 (a) values (1012);
show triggers where (f2(12) = 12);
ERROR 23000: Duplicate entry '12' for key 'a'
ERROR 23000: Duplicate entry '12' for key 't2.a'
select * from t2;
a
1012
Expand All @@ -134,7 +134,7 @@ select * from t2;
a
insert into t2 (a) values (1013);
show table status where (f2(13) = 13);
ERROR 23000: Duplicate entry '13' for key 'a'
ERROR 23000: Duplicate entry '13' for key 't2.a'
select * from t2;
a
1013
Expand All @@ -143,7 +143,7 @@ select * from t2;
a
insert into t2 (a) values (1014);
show open tables where (f2(14) = 14);
ERROR 23000: Duplicate entry '14' for key 'a'
ERROR 23000: Duplicate entry '14' for key 't2.a'
select * from t2;
a
1014
Expand All @@ -152,7 +152,7 @@ select * from t2;
a
insert into t2 (a) values (1015);
show columns in information_schema.routines where (f2(15) = 15);
ERROR 23000: Duplicate entry '15' for key 'a'
ERROR 23000: Duplicate entry '15' for key 't2.a'
select * from t2;
a
1015
Expand All @@ -161,7 +161,7 @@ select * from t2;
a
insert into t2 (a) values (1016);
show status where (f2(16) = 16);
ERROR 23000: Duplicate entry '16' for key 'a'
ERROR 23000: Duplicate entry '16' for key 't2.a'
select * from t2;
a
1016
Expand All @@ -170,7 +170,7 @@ select * from t2;
a
insert into t2 (a) values (1017);
show variables where (f2(17) = 17);
ERROR 23000: Duplicate entry '17' for key 'a'
ERROR 23000: Duplicate entry '17' for key 't2.a'
select * from t2;
a
1017
Expand All @@ -179,7 +179,7 @@ select * from t2;
a
insert into t2 (a) values (1018);
show charset where (f2(18) = 18);
ERROR 23000: Duplicate entry '18' for key 'a'
ERROR 23000: Duplicate entry '18' for key 't2.a'
select * from t2;
a
1018
Expand All @@ -188,7 +188,7 @@ select * from t2;
a
insert into t2 (a) values (1019);
show collation where (f2(19) = 19);
ERROR 23000: Duplicate entry '19' for key 'a'
ERROR 23000: Duplicate entry '19' for key 't2.a'
select * from t2;
a
1019
Expand All @@ -200,7 +200,7 @@ a
create procedure dummy() begin end;
insert into t2 (a) values (1020);
show procedure status where (f2(20) = 20);
ERROR 23000: Duplicate entry '20' for key 'a'
ERROR 23000: Duplicate entry '20' for key 't2.a'
select * from t2;
a
1020
Expand All @@ -210,7 +210,7 @@ a
drop procedure dummy;
insert into t2 (a) values (1021);
show function status where (f2(21) = 21);
ERROR 23000: Duplicate entry '21' for key 'a'
ERROR 23000: Duplicate entry '21' for key 't2.a'
select * from t2;
a
1021
Expand All @@ -220,7 +220,7 @@ a
insert into t2 (a) values (1022);
prepare stmt from "insert into t1 (a) values (f2(22))";
execute stmt;
ERROR 23000: Duplicate entry '22' for key 'a'
ERROR 23000: Duplicate entry '22' for key 't2.a'
select * from t2;
a
1022
Expand All @@ -229,7 +229,7 @@ select * from t2;
a
insert into t2 (a) values (1023);
do (f2(23));
ERROR 23000: Duplicate entry '23' for key 'a'
ERROR 23000: Duplicate entry '23' for key 't2.a'
select * from t2;
a
1023
Expand All @@ -243,7 +243,7 @@ insert into t2 (a) values (24);
end|
insert into t2 (a) values (1024);
call bug12713_call();
ERROR 23000: Duplicate entry '24' for key 'a'
ERROR 23000: Duplicate entry '24' for key 't2.a'
select * from t2;
a
24
Expand All @@ -256,7 +256,7 @@ Testing select_to_file
=======================================================================
insert into t2 (a) values (1025);
select f2(25) into outfile "../tmp/dml.out" from t1;
ERROR 23000: Duplicate entry '25' for key 'a'
ERROR 23000: Duplicate entry '25' for key 't2.a'
select * from t2;
a
1025
Expand All @@ -265,7 +265,7 @@ select * from t2;
a
insert into t2 (a) values (1026);
load data infile "../../std_data/words.dat" ignore into table t1 (a) set a:=f2(26);
ERROR 23000: Duplicate entry '26' for key 'a'
ERROR 23000: Duplicate entry '26' for key 't2.a'
select * from t2;
a
1026
Expand All @@ -277,7 +277,7 @@ Testing select_dumpvar
=======================================================================
insert into t2 (a) values (1027);
select f2(27) into @foo;
ERROR 23000: Duplicate entry '27' for key 'a'
ERROR 23000: Duplicate entry '27' for key 't2.a'
select * from t2;
a
1027
Expand Down Expand Up @@ -531,7 +531,7 @@ SUCCESS
#
insert ignore t1 set a=2;
Warnings:
Warning 1062 Duplicate entry '2' for key 'a'
Warning 1062 Duplicate entry '2' for key 't1.a'
call p_verify_status_increment(2, 2, 1, 0);
SUCCESS

Expand Down
Loading

0 comments on commit 045af14

Please sign in to comment.