Skip to content

Commit 5cf0662

Browse files
committed
MDEV-13749: Server crashes in _ma_unique_hash / JOIN_CACHE::generate_full_extensions on INTERSECT
Expect index except unique constrain in case of heap table conversion.
1 parent 92993d9 commit 5cf0662

File tree

4 files changed

+183
-14
lines changed

4 files changed

+183
-14
lines changed

mysql-test/r/intersect.result

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,4 +702,74 @@ intersect
702702
(select 3 from dual having t.i <> 3));
703703
i
704704
drop table t;
705+
#
706+
# MDEV-13749: Server crashes in _ma_unique_hash /
707+
# JOIN_CACHE::generate_full_extensions on INTERSECT
708+
#
709+
CREATE TABLE t1 (a varchar(32)) ENGINE=MyISAM;
710+
INSERT INTO t1 VALUES
711+
('Jakarta'),('Lisbon'),('Honolulu'),('Lusaka'),('Barcelona'),('Taipei'),
712+
('Brussels'),('Orlando'),('Osaka'),('Quito'),('Lima'),('Tunis'),
713+
('Unalaska'),('Rotterdam'),('Zagreb'),('Ufa'),('Ryazan'),('Xiamen'),
714+
('London'),('Izmir'),('Samara'),('Bern'),('Zhengzhou'),('Vladivostok'),
715+
('Yangon'),('Victoria'),('Warsaw'),('Luanda'),('Leon'),('Bangkok'),
716+
('Wellington'),('Zibo'),('Qiqihar'),('Delhi'),('Hamburg'),('Ottawa'),
717+
('Vaduz');
718+
CREATE TABLE t2 (b varchar(32)) ENGINE=MyISAM;
719+
INSERT INTO t2 VALUES
720+
('Gaza'),('Jeddah'),('Beirut'),('Incheon'),('Tbilisi'),('Izmir'),
721+
('Quito'),('Riga'),('Freetown'),('Zagreb'),('Caracas'),('Orlando'),
722+
('Kingston'),('Turin'),('Xinyang'),('Osaka'),('Albany'),('Geneva'),
723+
('Omsk'),('Kazan'),('Quezon'),('Indore'),('Odessa'),('Xiamen'),
724+
('Winnipeg'),('Yakutsk'),('Nairobi'),('Ufa'),('Helsinki'),('Vilnius'),
725+
('Aden'),('Liverpool'),('Honolulu'),('Frankfurt'),('Glasgow'),
726+
('Vienna'),('Jackson'),('Jakarta'),('Sydney'),('Oslo'),('Novgorod'),
727+
('Norilsk'),('Izhevsk'),('Istanbul'),('Nice');
728+
CREATE TABLE t3 (c varchar(32)) ENGINE=MyISAM;
729+
INSERT INTO t3 VALUES
730+
('Nicosia'),('Istanbul'),('Richmond'),('Stockholm'),('Dublin'),
731+
('Wichita'),('Warsaw'),('Glasgow'),('Winnipeg'),('Irkutsk'),('Quito'),
732+
('Xiamen'),('Berlin'),('Rome'),('Denver'),('Dallas'),('Kabul'),
733+
('Prague'),('Izhevsk'),('Tirana'),('Sofia'),('Detroit'),('Sorbonne');
734+
select count(*) from (
735+
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
736+
INTERSECT
737+
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
738+
) a;
739+
count(*)
740+
14848
741+
drop table t1,t2,t3;
742+
CREATE TABLE t1 (a varchar(32) not null) ENGINE=MyISAM;
743+
INSERT INTO t1 VALUES
744+
('Jakarta'),('Lisbon'),('Honolulu'),('Lusaka'),('Barcelona'),('Taipei'),
745+
('Brussels'),('Orlando'),('Osaka'),('Quito'),('Lima'),('Tunis'),
746+
('Unalaska'),('Rotterdam'),('Zagreb'),('Ufa'),('Ryazan'),('Xiamen'),
747+
('London'),('Izmir'),('Samara'),('Bern'),('Zhengzhou'),('Vladivostok'),
748+
('Yangon'),('Victoria'),('Warsaw'),('Luanda'),('Leon'),('Bangkok'),
749+
('Wellington'),('Zibo'),('Qiqihar'),('Delhi'),('Hamburg'),('Ottawa'),
750+
('Vaduz');
751+
CREATE TABLE t2 (b varchar(32) not null) ENGINE=MyISAM;
752+
INSERT INTO t2 VALUES
753+
('Gaza'),('Jeddah'),('Beirut'),('Incheon'),('Tbilisi'),('Izmir'),
754+
('Quito'),('Riga'),('Freetown'),('Zagreb'),('Caracas'),('Orlando'),
755+
('Kingston'),('Turin'),('Xinyang'),('Osaka'),('Albany'),('Geneva'),
756+
('Omsk'),('Kazan'),('Quezon'),('Indore'),('Odessa'),('Xiamen'),
757+
('Winnipeg'),('Yakutsk'),('Nairobi'),('Ufa'),('Helsinki'),('Vilnius'),
758+
('Aden'),('Liverpool'),('Honolulu'),('Frankfurt'),('Glasgow'),
759+
('Vienna'),('Jackson'),('Jakarta'),('Sydney'),('Oslo'),('Novgorod'),
760+
('Norilsk'),('Izhevsk'),('Istanbul'),('Nice');
761+
CREATE TABLE t3 (c varchar(32) not null) ENGINE=MyISAM;
762+
INSERT INTO t3 VALUES
763+
('Nicosia'),('Istanbul'),('Richmond'),('Stockholm'),('Dublin'),
764+
('Wichita'),('Warsaw'),('Glasgow'),('Winnipeg'),('Irkutsk'),('Quito'),
765+
('Xiamen'),('Berlin'),('Rome'),('Denver'),('Dallas'),('Kabul'),
766+
('Prague'),('Izhevsk'),('Tirana'),('Sofia'),('Detroit'),('Sorbonne');
767+
select count(*) from (
768+
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
769+
INTERSECT
770+
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
771+
) a;
772+
count(*)
773+
14848
774+
drop table t1,t2,t3;
705775
# End of 10.3 tests

mysql-test/t/intersect.test

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,81 @@ select i from t where
205205
drop table t;
206206

207207

208+
--echo #
209+
--echo # MDEV-13749: Server crashes in _ma_unique_hash /
210+
--echo # JOIN_CACHE::generate_full_extensions on INTERSECT
211+
--echo #
212+
213+
CREATE TABLE t1 (a varchar(32)) ENGINE=MyISAM;
214+
INSERT INTO t1 VALUES
215+
('Jakarta'),('Lisbon'),('Honolulu'),('Lusaka'),('Barcelona'),('Taipei'),
216+
('Brussels'),('Orlando'),('Osaka'),('Quito'),('Lima'),('Tunis'),
217+
('Unalaska'),('Rotterdam'),('Zagreb'),('Ufa'),('Ryazan'),('Xiamen'),
218+
('London'),('Izmir'),('Samara'),('Bern'),('Zhengzhou'),('Vladivostok'),
219+
('Yangon'),('Victoria'),('Warsaw'),('Luanda'),('Leon'),('Bangkok'),
220+
('Wellington'),('Zibo'),('Qiqihar'),('Delhi'),('Hamburg'),('Ottawa'),
221+
('Vaduz');
222+
223+
CREATE TABLE t2 (b varchar(32)) ENGINE=MyISAM;
224+
INSERT INTO t2 VALUES
225+
('Gaza'),('Jeddah'),('Beirut'),('Incheon'),('Tbilisi'),('Izmir'),
226+
('Quito'),('Riga'),('Freetown'),('Zagreb'),('Caracas'),('Orlando'),
227+
('Kingston'),('Turin'),('Xinyang'),('Osaka'),('Albany'),('Geneva'),
228+
('Omsk'),('Kazan'),('Quezon'),('Indore'),('Odessa'),('Xiamen'),
229+
('Winnipeg'),('Yakutsk'),('Nairobi'),('Ufa'),('Helsinki'),('Vilnius'),
230+
('Aden'),('Liverpool'),('Honolulu'),('Frankfurt'),('Glasgow'),
231+
('Vienna'),('Jackson'),('Jakarta'),('Sydney'),('Oslo'),('Novgorod'),
232+
('Norilsk'),('Izhevsk'),('Istanbul'),('Nice');
233+
234+
CREATE TABLE t3 (c varchar(32)) ENGINE=MyISAM;
235+
INSERT INTO t3 VALUES
236+
('Nicosia'),('Istanbul'),('Richmond'),('Stockholm'),('Dublin'),
237+
('Wichita'),('Warsaw'),('Glasgow'),('Winnipeg'),('Irkutsk'),('Quito'),
238+
('Xiamen'),('Berlin'),('Rome'),('Denver'),('Dallas'),('Kabul'),
239+
('Prague'),('Izhevsk'),('Tirana'),('Sofia'),('Detroit'),('Sorbonne');
240+
241+
select count(*) from (
242+
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
243+
INTERSECT
244+
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
245+
) a;
246+
247+
drop table t1,t2,t3;
248+
249+
CREATE TABLE t1 (a varchar(32) not null) ENGINE=MyISAM;
250+
INSERT INTO t1 VALUES
251+
('Jakarta'),('Lisbon'),('Honolulu'),('Lusaka'),('Barcelona'),('Taipei'),
252+
('Brussels'),('Orlando'),('Osaka'),('Quito'),('Lima'),('Tunis'),
253+
('Unalaska'),('Rotterdam'),('Zagreb'),('Ufa'),('Ryazan'),('Xiamen'),
254+
('London'),('Izmir'),('Samara'),('Bern'),('Zhengzhou'),('Vladivostok'),
255+
('Yangon'),('Victoria'),('Warsaw'),('Luanda'),('Leon'),('Bangkok'),
256+
('Wellington'),('Zibo'),('Qiqihar'),('Delhi'),('Hamburg'),('Ottawa'),
257+
('Vaduz');
258+
259+
CREATE TABLE t2 (b varchar(32) not null) ENGINE=MyISAM;
260+
INSERT INTO t2 VALUES
261+
('Gaza'),('Jeddah'),('Beirut'),('Incheon'),('Tbilisi'),('Izmir'),
262+
('Quito'),('Riga'),('Freetown'),('Zagreb'),('Caracas'),('Orlando'),
263+
('Kingston'),('Turin'),('Xinyang'),('Osaka'),('Albany'),('Geneva'),
264+
('Omsk'),('Kazan'),('Quezon'),('Indore'),('Odessa'),('Xiamen'),
265+
('Winnipeg'),('Yakutsk'),('Nairobi'),('Ufa'),('Helsinki'),('Vilnius'),
266+
('Aden'),('Liverpool'),('Honolulu'),('Frankfurt'),('Glasgow'),
267+
('Vienna'),('Jackson'),('Jakarta'),('Sydney'),('Oslo'),('Novgorod'),
268+
('Norilsk'),('Izhevsk'),('Istanbul'),('Nice');
269+
270+
CREATE TABLE t3 (c varchar(32) not null) ENGINE=MyISAM;
271+
INSERT INTO t3 VALUES
272+
('Nicosia'),('Istanbul'),('Richmond'),('Stockholm'),('Dublin'),
273+
('Wichita'),('Warsaw'),('Glasgow'),('Winnipeg'),('Irkutsk'),('Quito'),
274+
('Xiamen'),('Berlin'),('Rome'),('Denver'),('Dallas'),('Kabul'),
275+
('Prague'),('Izhevsk'),('Tirana'),('Sofia'),('Detroit'),('Sorbonne');
276+
277+
select count(*) from (
278+
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
279+
INTERSECT
280+
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
281+
) a;
282+
283+
drop table t1,t2,t3;
284+
208285
--echo # End of 10.3 tests

storage/maria/ha_maria.cc

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3964,18 +3964,39 @@ Item *ha_maria::idx_cond_push(uint keyno_arg, Item* idx_cond_arg)
39643964

39653965
int ha_maria::find_unique_row(uchar *record, uint constrain_no)
39663966
{
3967-
MARIA_UNIQUEDEF *def= file->s->uniqueinfo + constrain_no;
3968-
ha_checksum unique_hash= _ma_unique_hash(def, record);
3969-
int rc= _ma_check_unique(file, def, record, unique_hash, HA_OFFSET_ERROR);
3970-
if (rc)
3971-
{
3972-
file->cur_row.lastpos= file->dup_key_pos;
3973-
if ((*file->read_record)(file, record, file->cur_row.lastpos))
3974-
return -1;
3975-
file->update|= HA_STATE_AKTIV; /* Record is read */
3976-
}
3977-
// invert logic
3978-
return (rc ? 0 : 1);
3967+
int rc;
3968+
if (file->s->state.header.uniques)
3969+
{
3970+
DBUG_ASSERT(file->s->state.header.uniques > constrain_no);
3971+
MARIA_UNIQUEDEF *def= file->s->uniqueinfo + constrain_no;
3972+
ha_checksum unique_hash= _ma_unique_hash(def, record);
3973+
rc= _ma_check_unique(file, def, record, unique_hash, HA_OFFSET_ERROR);
3974+
if (rc)
3975+
{
3976+
file->cur_row.lastpos= file->dup_key_pos;
3977+
if ((*file->read_record)(file, record, file->cur_row.lastpos))
3978+
return -1;
3979+
file->update|= HA_STATE_AKTIV; /* Record is read */
3980+
}
3981+
// invert logic
3982+
rc= !MY_TEST(rc);
3983+
}
3984+
else
3985+
{
3986+
/*
3987+
It is case when just unique index used instead unicue constrain
3988+
(conversion from heap table).
3989+
*/
3990+
DBUG_ASSERT(file->s->state.header.keys > constrain_no);
3991+
MARIA_KEY key;
3992+
file->once_flags|= USE_PACKED_KEYS;
3993+
(*file->s->keyinfo[constrain_no].make_key)
3994+
(file, &key, constrain_no, file->lastkey_buff2, record, 0, 0);
3995+
rc= maria_rkey(file, record, constrain_no, key.data, key.data_length,
3996+
HA_READ_KEY_EXACT);
3997+
rc= MY_TEST(rc);
3998+
}
3999+
return rc;
39794000
}
39804001

39814002
struct st_mysql_storage_engine maria_storage_engine=

storage/maria/ma_rkey.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ int maria_rkey(MARIA_HA *info, uchar *buf, int inx, const uchar *key_data,
4646
info->last_key_func= search_flag;
4747
keyinfo= info->last_key.keyinfo;
4848

49-
key_buff= info->lastkey_buff+info->s->base.max_key_length;
49+
key_buff= info->lastkey_buff2;
5050

5151
if (info->once_flags & USE_PACKED_KEYS)
5252
{
@@ -55,7 +55,8 @@ int maria_rkey(MARIA_HA *info, uchar *buf, int inx, const uchar *key_data,
5555
key is already packed!; This happens when we are using a MERGE TABLE
5656
In this key 'key_part_map' is the length of the key !
5757
*/
58-
bmove(key_buff, key_data, keypart_map);
58+
if (key_buff != key_data)
59+
bmove(key_buff, key_data, keypart_map);
5960
key.data= key_buff;
6061
key.keyinfo= keyinfo;
6162
key.data_length= keypart_map;

0 commit comments

Comments
 (0)