Bug #21072 Duplicate key error in NDB references wrong key: Added new...

 Bug #21072  Duplicate key error in NDB references wrong key: Added new printout for duplicate key error when key is unknown
parent 7e682728
...@@ -112,9 +112,9 @@ unique key(a) ...@@ -112,9 +112,9 @@ unique key(a)
) engine=ndb; ) engine=ndb;
insert into t1 values(1, 'aAa'); insert into t1 values(1, 'aAa');
insert into t1 values(2, 'aaa'); insert into t1 values(2, 'aaa');
ERROR 23000: Duplicate entry '2' for key 'PRIMARY' ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
insert into t1 values(3, 'AAA'); insert into t1 values(3, 'AAA');
ERROR 23000: Duplicate entry '3' for key 'PRIMARY' ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
select * from t1 order by p; select * from t1 order by p;
p a p a
1 aAa 1 aAa
...@@ -138,9 +138,9 @@ unique key(a) ...@@ -138,9 +138,9 @@ unique key(a)
) engine=ndb; ) engine=ndb;
insert into t1 values (1,'A'),(2,'b '),(3,'C '),(4,'d '),(5,'E'),(6,'f'); insert into t1 values (1,'A'),(2,'b '),(3,'C '),(4,'d '),(5,'E'),(6,'f');
insert into t1 values(99,'b'); insert into t1 values(99,'b');
ERROR 23000: Duplicate entry '99' for key 'PRIMARY' ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
insert into t1 values(99,'a '); insert into t1 values(99,'a ');
ERROR 23000: Duplicate entry '99' for key 'PRIMARY' ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
select a,length(a) from t1 order by a; select a,length(a) from t1 order by a;
a length(a) a length(a)
A 1 A 1
......
...@@ -22,7 +22,7 @@ select * from t1 where b = 4 order by a; ...@@ -22,7 +22,7 @@ select * from t1 where b = 4 order by a;
a b c a b c
3 4 6 3 4 6
insert into t1 values(8, 2, 3); insert into t1 values(8, 2, 3);
ERROR 23000: Duplicate entry '8' for key 'PRIMARY' ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
select * from t1 order by a; select * from t1 order by a;
a b c a b c
1 2 3 1 2 3
...@@ -93,7 +93,7 @@ a b c ...@@ -93,7 +93,7 @@ a b c
1 1 1 1 1 1
4 4 NULL 4 4 NULL
insert into t1 values(5,1,1); insert into t1 values(5,1,1);
ERROR 23000: Duplicate entry '5' for key 'PRIMARY' ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
drop table t1; drop table t1;
CREATE TABLE t2 ( CREATE TABLE t2 (
a int unsigned NOT NULL PRIMARY KEY, a int unsigned NOT NULL PRIMARY KEY,
...@@ -116,7 +116,7 @@ select * from t2 where b = 4 order by a; ...@@ -116,7 +116,7 @@ select * from t2 where b = 4 order by a;
a b c a b c
3 4 6 3 4 6
insert into t2 values(8, 2, 3); insert into t2 values(8, 2, 3);
ERROR 23000: Duplicate entry '8' for key 'PRIMARY' ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
select * from t2 order by a; select * from t2 order by a;
a b c a b c
1 2 3 1 2 3
...@@ -181,7 +181,7 @@ pk a ...@@ -181,7 +181,7 @@ pk a
3 NULL 3 NULL
4 4 4 4
insert into t1 values (5,0); insert into t1 values (5,0);
ERROR 23000: Duplicate entry '5' for key 'PRIMARY' ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
select * from t1 order by pk; select * from t1 order by pk;
pk a pk a
-1 NULL -1 NULL
...@@ -214,7 +214,7 @@ pk a b c ...@@ -214,7 +214,7 @@ pk a b c
0 NULL 18 NULL 0 NULL 18 NULL
1 3 19 abc 1 3 19 abc
insert into t2 values(2,3,19,'abc'); insert into t2 values(2,3,19,'abc');
ERROR 23000: Duplicate entry '2' for key 'PRIMARY' ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
select * from t2 order by pk; select * from t2 order by pk;
pk a b c pk a b c
-1 1 17 NULL -1 1 17 NULL
...@@ -634,7 +634,7 @@ create table t1 (a int primary key, b varchar(1000) not null, unique key (b)) ...@@ -634,7 +634,7 @@ create table t1 (a int primary key, b varchar(1000) not null, unique key (b))
engine=ndb charset=utf8; engine=ndb charset=utf8;
insert into t1 values (1, repeat(_utf8 0xe288ab6474, 200)); insert into t1 values (1, repeat(_utf8 0xe288ab6474, 200));
insert into t1 values (2, repeat(_utf8 0xe288ab6474, 200)); insert into t1 values (2, repeat(_utf8 0xe288ab6474, 200));
ERROR 23000: Duplicate entry '2' for key 'PRIMARY' ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
select a, sha1(b) from t1; select a, sha1(b) from t1;
a sha1(b) a sha1(b)
1 08f5d02c8b8bc244f275bdfc22c42c5cab0d9d7d 1 08f5d02c8b8bc244f275bdfc22c42c5cab0d9d7d
......
...@@ -18,7 +18,7 @@ pk1 b c ...@@ -18,7 +18,7 @@ pk1 b c
2 2 2 2 2 2
4 1 1 4 1 1
UPDATE t1 set pk1 = 1, c = 2 where pk1 = 4; UPDATE t1 set pk1 = 1, c = 2 where pk1 = 4;
ERROR 23000: Duplicate entry '1' for key 'PRIMARY' ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
select * from t1 order by pk1; select * from t1 order by pk1;
pk1 b c pk1 b c
0 0 0 0 0 0
......
...@@ -2031,6 +2031,17 @@ void handler::print_keydup_error(uint key_nr, const char *msg) ...@@ -2031,6 +2031,17 @@ void handler::print_keydup_error(uint key_nr, const char *msg)
/* Write the duplicated key in the error message */ /* Write the duplicated key in the error message */
char key[MAX_KEY_LENGTH]; char key[MAX_KEY_LENGTH];
String str(key,sizeof(key),system_charset_info); String str(key,sizeof(key),system_charset_info);
if (key_nr == MAX_KEY)
{
/* Key is unknown */
str.length(0);
key_nr= -1;
my_printf_error(ER_DUP_ENTRY, msg,
MYF(0), str.c_ptr(), "*UNKNOWN*");
}
else
{
/* Table is opened and defined at this point */ /* Table is opened and defined at this point */
key_unpack(&str,table,(uint) key_nr); key_unpack(&str,table,(uint) key_nr);
uint max_length=MYSQL_ERRMSG_SIZE-(uint) strlen(msg); uint max_length=MYSQL_ERRMSG_SIZE-(uint) strlen(msg);
...@@ -2041,6 +2052,7 @@ void handler::print_keydup_error(uint key_nr, const char *msg) ...@@ -2041,6 +2052,7 @@ void handler::print_keydup_error(uint key_nr, const char *msg)
} }
my_printf_error(ER_DUP_ENTRY, msg, my_printf_error(ER_DUP_ENTRY, msg,
MYF(0), str.c_ptr(), table->key_info[key_nr].name); MYF(0), str.c_ptr(), table->key_info[key_nr].name);
}
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment