Skip to content

Commit 04ee961

Browse files
MDEV-19049 Server crashes in check_duplicate_long_entry_key, ASAN stack-buffer-overflow in Field_blob::get_key_image
Long Unique keys should always be last unique key.
1 parent 9e0ed0f commit 04ee961

File tree

4 files changed

+47
-38
lines changed

4 files changed

+47
-38
lines changed

mysql-test/main/long_unique.result

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ t1 CREATE TABLE `t1` (
184184
`a` blob DEFAULT NULL,
185185
`c` int(11) DEFAULT NULL,
186186
`db_row_hash_1` int(11) DEFAULT NULL,
187-
UNIQUE KEY `a` (`a`) USING HASH,
188-
UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`)
187+
UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
188+
UNIQUE KEY `a` (`a`) USING HASH
189189
) ENGINE=MyISAM DEFAULT CHARSET=latin1
190190
insert into t1 values(45,1,55),(46,1,55);
191191
ERROR 23000: Duplicate entry '55' for key 'db_row_hash_1'
@@ -507,13 +507,13 @@ t1 CREATE TABLE `t1` (
507507
`db_row_hash_1` int(11) DEFAULT NULL,
508508
`db_row_hash_2` int(11) DEFAULT NULL,
509509
`db_row_hash_3` int(11) DEFAULT NULL,
510+
UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
511+
UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`),
512+
UNIQUE KEY `db_row_hash_3` (`db_row_hash_3`),
510513
UNIQUE KEY `a` (`a`) USING HASH,
511514
UNIQUE KEY `c` (`c`) USING HASH,
512515
UNIQUE KEY `d` (`d`) USING HASH,
513-
UNIQUE KEY `e` (`e`) USING HASH,
514-
UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
515-
UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`),
516-
UNIQUE KEY `db_row_hash_3` (`db_row_hash_3`)
516+
UNIQUE KEY `e` (`e`) USING HASH
517517
) ENGINE=MyISAM DEFAULT CHARSET=latin1
518518
alter table t1 add column db_row_hash_7 int, add column db_row_hash_5 int , add column db_row_hash_4 int ;
519519
alter table t1 drop column db_row_hash_7,drop column db_row_hash_3, drop column db_row_hash_4;
@@ -543,17 +543,17 @@ t1 CREATE TABLE `t1` (
543543
`db_row_hash_1` int(11) DEFAULT NULL,
544544
`db_row_hash_2` int(11) DEFAULT NULL,
545545
`db_row_hash_5` int(11) DEFAULT NULL,
546-
UNIQUE KEY `d` (`d`) USING HASH,
547-
UNIQUE KEY `e` (`e`) USING HASH,
548546
UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
549-
UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`)
547+
UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`),
548+
UNIQUE KEY `d` (`d`) USING HASH,
549+
UNIQUE KEY `e` (`e`) USING HASH
550550
) ENGINE=MyISAM DEFAULT CHARSET=latin1
551551
show keys from t1;
552552
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
553-
t1 0 d 1 d A NULL NULL NULL YES HASH
554-
t1 0 e 1 e A NULL NULL NULL YES HASH
555553
t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE
556554
t1 0 db_row_hash_2 1 db_row_hash_2 A NULL NULL NULL YES BTREE
555+
t1 0 d 1 d A NULL NULL NULL YES HASH
556+
t1 0 e 1 e A NULL NULL NULL YES HASH
557557
#add column with unique index on blob;
558558
alter table t1 add column a blob unique;
559559
show create table t1;
@@ -567,18 +567,18 @@ t1 CREATE TABLE `t1` (
567567
`db_row_hash_2` int(11) DEFAULT NULL,
568568
`db_row_hash_5` int(11) DEFAULT NULL,
569569
`a` blob DEFAULT NULL,
570-
UNIQUE KEY `d` (`d`) USING HASH,
571-
UNIQUE KEY `e` (`e`) USING HASH,
572570
UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
573571
UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`),
572+
UNIQUE KEY `d` (`d`) USING HASH,
573+
UNIQUE KEY `e` (`e`) USING HASH,
574574
UNIQUE KEY `a` (`a`) USING HASH
575575
) ENGINE=MyISAM DEFAULT CHARSET=latin1
576576
show keys from t1;
577577
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
578-
t1 0 d 1 d A NULL NULL NULL YES HASH
579-
t1 0 e 1 e A NULL NULL NULL YES HASH
580578
t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE
581579
t1 0 db_row_hash_2 1 db_row_hash_2 A NULL NULL NULL YES BTREE
580+
t1 0 d 1 d A NULL NULL NULL YES HASH
581+
t1 0 e 1 e A NULL NULL NULL YES HASH
582582
t1 0 a 1 a A NULL NULL NULL YES HASH
583583
#try to change the blob unique column name;
584584
#this will change index to b tree;
@@ -594,19 +594,19 @@ t1 CREATE TABLE `t1` (
594594
`db_row_hash_2` int(11) DEFAULT NULL,
595595
`db_row_hash_5` int(11) DEFAULT NULL,
596596
`a` int(11) DEFAULT NULL,
597-
UNIQUE KEY `d` (`d`) USING HASH,
598-
UNIQUE KEY `e` (`e`),
599597
UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
600598
UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`),
601-
UNIQUE KEY `a` (`a`)
599+
UNIQUE KEY `e` (`e`),
600+
UNIQUE KEY `a` (`a`),
601+
UNIQUE KEY `d` (`d`) USING HASH
602602
) ENGINE=MyISAM DEFAULT CHARSET=latin1
603603
show keys from t1;
604604
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
605-
t1 0 d 1 d A NULL NULL NULL YES HASH
606-
t1 0 e 1 e A NULL NULL NULL YES BTREE
607605
t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE
608606
t1 0 db_row_hash_2 1 db_row_hash_2 A NULL NULL NULL YES BTREE
607+
t1 0 e 1 e A NULL NULL NULL YES BTREE
609608
t1 0 a 1 a A NULL NULL NULL YES BTREE
609+
t1 0 d 1 d A NULL NULL NULL YES HASH
610610
alter table t1 add column clm1 blob unique,add column clm2 blob unique;
611611
#try changing the name;
612612
alter table t1 change column clm1 clm_changed1 blob, change column clm2 clm_changed2 blob;
@@ -623,21 +623,21 @@ t1 CREATE TABLE `t1` (
623623
`a` int(11) DEFAULT NULL,
624624
`clm_changed1` blob DEFAULT NULL,
625625
`clm_changed2` blob DEFAULT NULL,
626-
UNIQUE KEY `d` (`d`) USING HASH,
627-
UNIQUE KEY `e` (`e`),
628626
UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
629627
UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`),
628+
UNIQUE KEY `e` (`e`),
630629
UNIQUE KEY `a` (`a`),
630+
UNIQUE KEY `d` (`d`) USING HASH,
631631
UNIQUE KEY `clm1` (`clm_changed1`) USING HASH,
632632
UNIQUE KEY `clm2` (`clm_changed2`) USING HASH
633633
) ENGINE=MyISAM DEFAULT CHARSET=latin1
634634
show keys from t1;
635635
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
636-
t1 0 d 1 d A NULL NULL NULL YES HASH
637-
t1 0 e 1 e A NULL NULL NULL YES BTREE
638636
t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE
639637
t1 0 db_row_hash_2 1 db_row_hash_2 A NULL NULL NULL YES BTREE
638+
t1 0 e 1 e A NULL NULL NULL YES BTREE
640639
t1 0 a 1 a A NULL NULL NULL YES BTREE
640+
t1 0 d 1 d A NULL NULL NULL YES HASH
641641
t1 0 clm1 1 clm_changed1 A NULL NULL NULL YES HASH
642642
t1 0 clm2 1 clm_changed2 A NULL NULL NULL YES HASH
643643
#now drop the unique key;
@@ -655,19 +655,19 @@ t1 CREATE TABLE `t1` (
655655
`a` int(11) DEFAULT NULL,
656656
`clm_changed1` blob DEFAULT NULL,
657657
`clm_changed2` blob DEFAULT NULL,
658-
UNIQUE KEY `d` (`d`) USING HASH,
659-
UNIQUE KEY `e` (`e`),
660658
UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
661659
UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`),
662-
UNIQUE KEY `a` (`a`)
660+
UNIQUE KEY `e` (`e`),
661+
UNIQUE KEY `a` (`a`),
662+
UNIQUE KEY `d` (`d`) USING HASH
663663
) ENGINE=MyISAM DEFAULT CHARSET=latin1
664664
show keys from t1;
665665
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
666-
t1 0 d 1 d A NULL NULL NULL YES HASH
667-
t1 0 e 1 e A NULL NULL NULL YES BTREE
668666
t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE
669667
t1 0 db_row_hash_2 1 db_row_hash_2 A NULL NULL NULL YES BTREE
668+
t1 0 e 1 e A NULL NULL NULL YES BTREE
670669
t1 0 a 1 a A NULL NULL NULL YES BTREE
670+
t1 0 d 1 d A NULL NULL NULL YES HASH
671671
drop table t1;
672672
#now the table with key on multiple columns; the ultimate test;
673673
create table t1(a blob, b int , c varchar(2000) , d text , e varchar(3000) , f longblob , g int , h text ,
@@ -1130,17 +1130,17 @@ t1 CREATE TABLE `t1` (
11301130
`c` blob DEFAULT NULL,
11311131
`d` blob DEFAULT NULL,
11321132
`e` int(11) DEFAULT NULL,
1133+
UNIQUE KEY `e` (`e`),
11331134
UNIQUE KEY `a` (`a`,`c`) USING HASH,
1134-
UNIQUE KEY `b` (`b`,`d`) USING HASH,
1135-
UNIQUE KEY `e` (`e`)
1135+
UNIQUE KEY `b` (`b`,`d`) USING HASH
11361136
) ENGINE=MyISAM DEFAULT CHARSET=latin1
11371137
show keys from t1;
11381138
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
1139+
t1 0 e 1 e A NULL NULL NULL YES BTREE
11391140
t1 0 a 1 a A NULL NULL NULL YES HASH
11401141
t1 0 a 2 c A NULL NULL NULL YES HASH
11411142
t1 0 b 1 b A NULL NULL NULL YES HASH
11421143
t1 0 b 2 d A NULL NULL NULL YES HASH
1143-
t1 0 e 1 e A 0 NULL NULL YES BTREE
11441144
drop table t1;
11451145
#visibility of db_row_hash
11461146
create table t1 (a blob unique , b blob unique);

mysql-test/main/long_unique_innodb.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Table Create Table
99
t1 CREATE TABLE `t1` (
1010
`a` blob DEFAULT NULL,
1111
`c` int(11) DEFAULT NULL,
12-
UNIQUE KEY `a` (`a`) USING HASH,
13-
UNIQUE KEY `c` (`c`)
12+
UNIQUE KEY `c` (`c`),
13+
UNIQUE KEY `a` (`a`) USING HASH
1414
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1515
drop table t1;
1616
#test for concurrent insert of long unique in innodb

mysql-test/main/long_unique_update.result

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ create table t1 (a int primary key, b blob unique , c int unique );
7171
show keys from t1;
7272
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
7373
t1 0 PRIMARY 1 a A 0 NULL NULL BTREE
74-
t1 0 b 1 b A NULL NULL NULL YES HASH
7574
t1 0 c 1 c A NULL NULL NULL YES BTREE
75+
t1 0 b 1 b A NULL NULL NULL YES HASH
7676
insert into t1 values(1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),(6,6,6),(7,7,7);
7777
select * from t1 limit 3;
7878
a b c
@@ -220,18 +220,18 @@ t1 CREATE TABLE `t1` (
220220
`f` int(11) DEFAULT NULL,
221221
`g` text DEFAULT NULL,
222222
PRIMARY KEY (`a`),
223-
UNIQUE KEY `b` (`b`,`c`) USING HASH,
224223
UNIQUE KEY `b_2` (`b`,`f`),
224+
UNIQUE KEY `b` (`b`,`c`) USING HASH,
225225
UNIQUE KEY `e` (`e`,`g`) USING HASH,
226226
UNIQUE KEY `a` (`a`,`b`,`c`,`d`,`e`,`f`,`g`) USING HASH
227227
) ENGINE=MyISAM DEFAULT CHARSET=latin1
228228
show keys from t1;
229229
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
230230
t1 0 PRIMARY 1 a A 0 NULL NULL BTREE
231-
t1 0 b 1 b A NULL NULL NULL YES HASH
232-
t1 0 b 2 c A NULL NULL NULL YES HASH
233231
t1 0 b_2 1 b A NULL NULL NULL YES BTREE
234232
t1 0 b_2 2 f A NULL NULL NULL YES BTREE
233+
t1 0 b 1 b A NULL NULL NULL YES HASH
234+
t1 0 b 2 c A NULL NULL NULL YES HASH
235235
t1 0 e 1 e A NULL NULL NULL YES HASH
236236
t1 0 e 2 g A NULL NULL NULL YES HASH
237237
t1 0 a 1 a A NULL NULL NULL HASH

sql/sql_table.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2773,6 +2773,7 @@ bool quick_rm_table(THD *thd, handlerton *base, const LEX_CSTRING *db,
27732773
- UNIQUE keys where all column are NOT NULL
27742774
- UNIQUE keys that don't contain partial segments
27752775
- Other UNIQUE keys
2776+
- LONG UNIQUE keys
27762777
- Normal keys
27772778
- Fulltext keys
27782779
@@ -2796,6 +2797,14 @@ static int sort_keys(KEY *a, KEY *b)
27962797
{
27972798
if (!(b_flags & HA_NOSAME))
27982799
return -1;
2800+
/*
2801+
Long Unique keys should always be last unique key.
2802+
Before this patch they used to change order wrt to partial keys (MDEV-19049)
2803+
*/
2804+
if (a->algorithm == HA_KEY_ALG_LONG_HASH)
2805+
return 1;
2806+
if (b->algorithm == HA_KEY_ALG_LONG_HASH)
2807+
return -1;
27992808
if ((a_flags ^ b_flags) & HA_NULL_PART_KEY)
28002809
{
28012810
/* Sort NOT NULL keys before other keys */

0 commit comments

Comments
 (0)