Skip to content

Commit a6fb647

Browse files
sanja-byelkinspetrunia
authored andcommitted
MDEV-10419: crash in mariadb 10.1.16-MariaDB-1~trusty
Fixed initialization and usage of THD reference in subselect engines.
1 parent addb38f commit a6fb647

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

mysql-test/r/view.result

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5561,6 +5561,21 @@ test.v1 check Error 'test.v1' is not BASE TABLE
55615561
test.v1 check status Operation failed
55625562
drop view v1;
55635563
drop table t1;
5564+
#
5565+
# MDEV-10419: crash in mariadb 10.1.16-MariaDB-1~trusty
5566+
#
5567+
CREATE TABLE t1 (c1 CHAR(13));
5568+
CREATE TABLE t2 (c2 CHAR(13));
5569+
CREATE FUNCTION f() RETURNS INT RETURN 0;
5570+
CREATE OR REPLACE VIEW v1 AS select f() from t1 where c1 in (select c2 from t2);
5571+
DROP FUNCTION f;
5572+
SHOW CREATE VIEW v1;
5573+
View Create View character_set_client collation_connection
5574+
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `f`() AS `f()` from `t1` where `test`.`t1`.`c1` in (select `test`.`t2`.`c2` from `t2`) latin1 latin1_swedish_ci
5575+
Warnings:
5576+
Warning 1356 View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
5577+
drop view v1;
5578+
drop table t1,t2;
55645579
# -----------------------------------------------------------------
55655580
# -- End of 5.5 tests.
55665581
# -----------------------------------------------------------------

mysql-test/t/view.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5495,6 +5495,21 @@ alter table v1 check partition p1;
54955495
drop view v1;
54965496
drop table t1;
54975497

5498+
5499+
--echo #
5500+
--echo # MDEV-10419: crash in mariadb 10.1.16-MariaDB-1~trusty
5501+
--echo #
5502+
CREATE TABLE t1 (c1 CHAR(13));
5503+
CREATE TABLE t2 (c2 CHAR(13));
5504+
5505+
CREATE FUNCTION f() RETURNS INT RETURN 0;
5506+
CREATE OR REPLACE VIEW v1 AS select f() from t1 where c1 in (select c2 from t2);
5507+
DROP FUNCTION f;
5508+
5509+
SHOW CREATE VIEW v1;
5510+
5511+
drop view v1;
5512+
drop table t1,t2;
54985513
--echo # -----------------------------------------------------------------
54995514
--echo # -- End of 5.5 tests.
55005515
--echo # -----------------------------------------------------------------

sql/item_subselect.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3830,7 +3830,7 @@ int subselect_uniquesubquery_engine::scan_table()
38303830
}
38313831

38323832
table->file->extra_opt(HA_EXTRA_CACHE,
3833-
current_thd->variables.read_buff_size);
3833+
get_thd()->variables.read_buff_size);
38343834
table->null_row= 0;
38353835
for (;;)
38363836
{
@@ -4268,7 +4268,7 @@ table_map subselect_union_engine::upper_select_const_tables()
42684268
void subselect_single_select_engine::print(String *str,
42694269
enum_query_type query_type)
42704270
{
4271-
select_lex->print(thd, str, query_type);
4271+
select_lex->print(get_thd(), str, query_type);
42724272
}
42734273

42744274

@@ -4799,6 +4799,7 @@ my_bitmap_init_memroot(MY_BITMAP *map, uint n_bits, MEM_ROOT *mem_root)
47994799

48004800
bool subselect_hash_sj_engine::init(List<Item> *tmp_columns, uint subquery_id)
48014801
{
4802+
THD *thd= get_thd();
48024803
select_union *result_sink;
48034804
/* Options to create_tmp_table. */
48044805
ulonglong tmp_create_options= thd->variables.option_bits | TMP_TABLE_ALL_COLUMNS;
@@ -6032,6 +6033,7 @@ bool
60326033
subselect_rowid_merge_engine::init(MY_BITMAP *non_null_key_parts,
60336034
MY_BITMAP *partial_match_key_parts)
60346035
{
6036+
THD *thd= get_thd();
60356037
/* The length in bytes of the rowids (positions) of tmp_table. */
60366038
uint rowid_length= tmp_table->file->ref_length;
60376039
ha_rows row_count= tmp_table->file->stats.records;
@@ -6570,7 +6572,7 @@ bool subselect_table_scan_engine::partial_match()
65706572
}
65716573

65726574
tmp_table->file->extra_opt(HA_EXTRA_CACHE,
6573-
current_thd->variables.read_buff_size);
6575+
get_thd()->variables.read_buff_size);
65746576
for (;;)
65756577
{
65766578
error= tmp_table->file->ha_rnd_next(tmp_table->record[0]);

sql/item_subselect.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,8 @@ class subselect_engine: public Sql_alloc
762762
ROWID_MERGE_ENGINE, TABLE_SCAN_ENGINE};
763763

764764
subselect_engine(Item_subselect *si,
765-
select_result_interceptor *res)
765+
select_result_interceptor *res):
766+
thd(NULL)
766767
{
767768
result= res;
768769
item= si;
@@ -778,7 +779,7 @@ class subselect_engine: public Sql_alloc
778779
Should be called before prepare().
779780
*/
780781
void set_thd(THD *thd_arg);
781-
THD * get_thd() { return thd; }
782+
THD * get_thd() { return thd ? thd : current_thd; }
782783
virtual int prepare(THD *)= 0;
783784
virtual void fix_length_and_dec(Item_cache** row)= 0;
784785
/*

0 commit comments

Comments
 (0)