Skip to content

Commit 235b682

Browse files
committed
MDEV-9619: Assertion `null_ref_table' failed in virtual table_map Item_direct_view_ref::used_tables() const on 2nd execution of PS
Refer left expression indirectly in case it changes from execution to execution.
1 parent 2bab29e commit 235b682

16 files changed

+332
-33
lines changed

mysql-test/r/ps.result

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4203,4 +4203,117 @@ execute stmt;
42034203
1
42044204
1
42054205
drop table t1,t2;
4206+
#
4207+
# MDEV-9619: Assertion `null_ref_table' failed in virtual
4208+
# table_map Item_direct_view_ref::used_tables() const on 2nd
4209+
# execution of PS
4210+
#
4211+
CREATE TABLE t1 (f1 VARCHAR(10)) ENGINE=MyISAM;
4212+
CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1;
4213+
INSERT INTO t1 VALUES ('a'),('b');
4214+
CREATE TABLE t2 (f2 VARCHAR(10)) ENGINE=MyISAM;
4215+
INSERT INTO t2 VALUES ('c'),('d');
4216+
PREPARE stmt FROM "SELECT * FROM v1 WHERE f1 = SOME ( SELECT f2 FROM t2 )";
4217+
EXECUTE stmt;
4218+
f1
4219+
EXECUTE stmt;
4220+
f1
4221+
insert into t1 values ('c');
4222+
EXECUTE stmt;
4223+
f1
4224+
c
4225+
EXECUTE stmt;
4226+
f1
4227+
c
4228+
deallocate prepare stmt;
4229+
drop view v1;
4230+
drop table t1,t2;
4231+
CREATE TABLE t1 (f1 VARCHAR(10)) ENGINE=MyISAM;
4232+
CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1;
4233+
INSERT INTO t1 VALUES ('a'),('b');
4234+
CREATE TABLE t2 (f2 VARCHAR(10)) ENGINE=MyISAM;
4235+
INSERT INTO t2 VALUES ('c'),('d');
4236+
PREPARE stmt FROM "SELECT * FROM v1 WHERE (f1,f1) = SOME ( SELECT f2,f2 FROM t2 )";
4237+
EXECUTE stmt;
4238+
f1
4239+
EXECUTE stmt;
4240+
f1
4241+
insert into t1 values ('c');
4242+
EXECUTE stmt;
4243+
f1
4244+
c
4245+
EXECUTE stmt;
4246+
f1
4247+
c
4248+
deallocate prepare stmt;
4249+
drop view v1;
4250+
drop table t1,t2;
4251+
CREATE TABLE t1 (column1 INT) ENGINE=MyISAM;
4252+
INSERT INTO t1 VALUES (3),(9);
4253+
CREATE TABLE t2 (column2 INT) ENGINE=MyISAM;
4254+
INSERT INTO t2 VALUES (1),(4);
4255+
CREATE TABLE t3 (column3 INT) ENGINE=MyISAM;
4256+
INSERT INTO t3 VALUES (6),(8);
4257+
CREATE TABLE t4 (column4 INT) ENGINE=MyISAM;
4258+
INSERT INTO t4 VALUES (2),(5);
4259+
PREPARE stmt FROM "
4260+
SELECT (
4261+
SELECT MAX( table1.column1 ) AS field1
4262+
FROM t1 AS table1
4263+
WHERE (111,table3.column3) IN ( SELECT 111,table2.column2 AS field2 FROM t2 AS table2 )
4264+
) AS sq
4265+
FROM t3 AS table3, t4 AS table4 GROUP BY sq
4266+
";
4267+
EXECUTE stmt;
4268+
sq
4269+
NULL
4270+
EXECUTE stmt;
4271+
sq
4272+
NULL
4273+
deallocate prepare stmt;
4274+
drop table t1,t2,t3,t4;
4275+
create table t1 (a int, b int, c int);
4276+
create table t2 (x int, y int, z int);
4277+
create table t3 as select * from t1;
4278+
insert into t1 values (1,2,3),(4,5,6),(100,200,300),(400,500,600);
4279+
insert into t2 values (1,2,3),(7,8,9),(100,200,300),(400,500,600);
4280+
insert into t3 values (1,2,3),(11,12,13),(100,0,0),(400,500,600);
4281+
set @optimizer_switch_save=@@optimizer_switch;
4282+
set @join_cache_level_save=@@join_cache_level;
4283+
set optimizer_switch='materialization=off';
4284+
set join_cache_level=0;
4285+
select * from t1 where (select a,b from t3 where t3.c=t1.c) in (select x,y from t2 where t1.c= t2.z);
4286+
a b c
4287+
1 2 3
4288+
400 500 600
4289+
prepare stmt from "select * from t1 where (select a,b from t3 where t3.c=t1.c) in (select x,y from t2 where t1.c= t2.z)";
4290+
EXECUTE stmt;
4291+
a b c
4292+
1 2 3
4293+
400 500 600
4294+
EXECUTE stmt;
4295+
a b c
4296+
1 2 3
4297+
400 500 600
4298+
create view v1 as select * from t1;
4299+
create view v2 as select * from t2;
4300+
create view v3 as select * from t3;
4301+
select * from v1 where (select a,b from v3 where v3.c=v1.c) in (select x,y from v2 where v1.c= v2.z);
4302+
a b c
4303+
1 2 3
4304+
400 500 600
4305+
prepare stmt from "select * from v1 where (select a,b from v3 where v3.c=v1.c) in (select x,y from v2 where v1.c= v2.z)";
4306+
EXECUTE stmt;
4307+
a b c
4308+
1 2 3
4309+
400 500 600
4310+
EXECUTE stmt;
4311+
a b c
4312+
1 2 3
4313+
400 500 600
4314+
set optimizer_switch=@optimizer_switch_save;
4315+
set join_cache_level=@join_cache_level_save;
4316+
deallocate prepare stmt;
4317+
drop view v1,v2,v3;
4318+
drop table t1,t2,t3;
42064319
# End of 5.5 tests

mysql-test/t/ps.test

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3740,4 +3740,107 @@ execute stmt;
37403740

37413741
drop table t1,t2;
37423742

3743+
--echo #
3744+
--echo # MDEV-9619: Assertion `null_ref_table' failed in virtual
3745+
--echo # table_map Item_direct_view_ref::used_tables() const on 2nd
3746+
--echo # execution of PS
3747+
--echo #
3748+
3749+
CREATE TABLE t1 (f1 VARCHAR(10)) ENGINE=MyISAM;
3750+
CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1;
3751+
INSERT INTO t1 VALUES ('a'),('b');
3752+
3753+
CREATE TABLE t2 (f2 VARCHAR(10)) ENGINE=MyISAM;
3754+
INSERT INTO t2 VALUES ('c'),('d');
3755+
3756+
PREPARE stmt FROM "SELECT * FROM v1 WHERE f1 = SOME ( SELECT f2 FROM t2 )";
3757+
EXECUTE stmt;
3758+
EXECUTE stmt;
3759+
insert into t1 values ('c');
3760+
EXECUTE stmt;
3761+
EXECUTE stmt;
3762+
3763+
deallocate prepare stmt;
3764+
drop view v1;
3765+
drop table t1,t2;
3766+
3767+
CREATE TABLE t1 (f1 VARCHAR(10)) ENGINE=MyISAM;
3768+
CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1;
3769+
INSERT INTO t1 VALUES ('a'),('b');
3770+
3771+
CREATE TABLE t2 (f2 VARCHAR(10)) ENGINE=MyISAM;
3772+
INSERT INTO t2 VALUES ('c'),('d');
3773+
3774+
PREPARE stmt FROM "SELECT * FROM v1 WHERE (f1,f1) = SOME ( SELECT f2,f2 FROM t2 )";
3775+
EXECUTE stmt;
3776+
EXECUTE stmt;
3777+
insert into t1 values ('c');
3778+
EXECUTE stmt;
3779+
EXECUTE stmt;
3780+
3781+
deallocate prepare stmt;
3782+
drop view v1;
3783+
drop table t1,t2;
3784+
3785+
3786+
3787+
CREATE TABLE t1 (column1 INT) ENGINE=MyISAM;
3788+
INSERT INTO t1 VALUES (3),(9);
3789+
3790+
CREATE TABLE t2 (column2 INT) ENGINE=MyISAM;
3791+
3792+
INSERT INTO t2 VALUES (1),(4);
3793+
3794+
CREATE TABLE t3 (column3 INT) ENGINE=MyISAM;
3795+
INSERT INTO t3 VALUES (6),(8);
3796+
3797+
CREATE TABLE t4 (column4 INT) ENGINE=MyISAM;
3798+
INSERT INTO t4 VALUES (2),(5);
3799+
3800+
PREPARE stmt FROM "
3801+
SELECT (
3802+
SELECT MAX( table1.column1 ) AS field1
3803+
FROM t1 AS table1
3804+
WHERE (111,table3.column3) IN ( SELECT 111,table2.column2 AS field2 FROM t2 AS table2 )
3805+
) AS sq
3806+
FROM t3 AS table3, t4 AS table4 GROUP BY sq
3807+
";
3808+
3809+
EXECUTE stmt;
3810+
EXECUTE stmt;
3811+
3812+
deallocate prepare stmt;
3813+
drop table t1,t2,t3,t4;
3814+
3815+
create table t1 (a int, b int, c int);
3816+
create table t2 (x int, y int, z int);
3817+
create table t3 as select * from t1;
3818+
insert into t1 values (1,2,3),(4,5,6),(100,200,300),(400,500,600);
3819+
insert into t2 values (1,2,3),(7,8,9),(100,200,300),(400,500,600);
3820+
insert into t3 values (1,2,3),(11,12,13),(100,0,0),(400,500,600);
3821+
3822+
3823+
set @optimizer_switch_save=@@optimizer_switch;
3824+
set @join_cache_level_save=@@join_cache_level;
3825+
set optimizer_switch='materialization=off';
3826+
set join_cache_level=0;
3827+
select * from t1 where (select a,b from t3 where t3.c=t1.c) in (select x,y from t2 where t1.c= t2.z);
3828+
prepare stmt from "select * from t1 where (select a,b from t3 where t3.c=t1.c) in (select x,y from t2 where t1.c= t2.z)";
3829+
EXECUTE stmt;
3830+
EXECUTE stmt;
3831+
3832+
create view v1 as select * from t1;
3833+
create view v2 as select * from t2;
3834+
create view v3 as select * from t3;
3835+
select * from v1 where (select a,b from v3 where v3.c=v1.c) in (select x,y from v2 where v1.c= v2.z);
3836+
prepare stmt from "select * from v1 where (select a,b from v3 where v3.c=v1.c) in (select x,y from v2 where v1.c= v2.z)";
3837+
EXECUTE stmt;
3838+
EXECUTE stmt;
3839+
set optimizer_switch=@optimizer_switch_save;
3840+
set join_cache_level=@join_cache_level_save;
3841+
3842+
deallocate prepare stmt;
3843+
drop view v1,v2,v3;
3844+
drop table t1,t2,t3;
3845+
37433846
--echo # End of 5.5 tests

sql/item_row.cc

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ Item_row::Item_row(List<Item> &arg):
4444

4545
//TODO: think placing 2-3 component items in item (as it done for function)
4646
if ((arg_count= arg.elements))
47+
{
4748
items= (Item**) sql_alloc(sizeof(Item*)*arg_count);
49+
if (!items)
50+
{
51+
arg_count= 0;
52+
return;
53+
}
54+
}
4855
else
4956
items= 0;
5057
List_iterator<Item> li(arg);
@@ -53,7 +60,28 @@ Item_row::Item_row(List<Item> &arg):
5360
while ((item= li++))
5461
{
5562
items[i]= item;
56-
i++;
63+
i++;
64+
}
65+
}
66+
67+
68+
Item_row::Item_row(Item *item):
69+
Item(),
70+
used_tables_cache(0),
71+
not_null_tables_cache(0),
72+
arg_count(item->cols()),
73+
const_item_cache(1),
74+
with_null(0)
75+
{
76+
items= (Item**) sql_alloc(sizeof(Item*) * arg_count);
77+
if (!items)
78+
{
79+
arg_count= 0;
80+
return;
81+
}
82+
for (uint i= 0; i < arg_count; i++)
83+
{
84+
items[i]= item->element_index(i);
5785
}
5886
}
5987

sql/item_row.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Item_row: public Item
3535
const_item_cache(item->const_item_cache),
3636
with_null(0)
3737
{}
38+
Item_row(Item *item);
3839

3940
enum Type type() const { return ROW_ITEM; };
4041
void illegal_method_call(const char *);

sql/item_subselect.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,9 @@ Item_in_subselect::Item_in_subselect(Item * left_exp,
13741374
{
13751375
DBUG_ENTER("Item_in_subselect::Item_in_subselect");
13761376
left_expr_orig= left_expr= left_exp;
1377+
/* prepare to possible disassembling the item in convert_subq_to_sj() */
1378+
if (left_exp->type() == Item::ROW_ITEM)
1379+
left_expr_orig= new Item_row(left_exp);
13771380
func= &eq_creator;
13781381
init(select_lex, new select_exists_subselect(this));
13791382
max_columns= UINT_MAX;
@@ -1398,6 +1401,9 @@ Item_allany_subselect::Item_allany_subselect(Item * left_exp,
13981401
{
13991402
DBUG_ENTER("Item_allany_subselect::Item_allany_subselect");
14001403
left_expr_orig= left_expr= left_exp;
1404+
/* prepare to possible disassembling the item in convert_subq_to_sj() */
1405+
if (left_exp->type() == Item::ROW_ITEM)
1406+
left_expr_orig= new Item_row(left_exp);
14011407
func= func_creator(all_arg);
14021408
init(select_lex, new select_exists_subselect(this));
14031409
max_columns= 1;

0 commit comments

Comments
 (0)