mariadb/mysql-test/r/subselect_nulls.result
Sergei Golubchik c5975eaea1 MDEV-7339 Server crashes in Item_func_trig_cond::val_int
Item_in_subselect::pushed_cond_guards[] array is allocated only when
left_expr->maybe_null. And it is used (for row expressions) when
left_expr->element_index(i)->maybe_null.

For left_expr being a multi-column subquery, its maybe_null is
always false when the subquery doesn't use tables (see
Item_singlerow_subselect::fix_length_and_dec()
and subselect_single_select_engine::fix_length_and_dec()),
otherwise it's always true.

But row elements can be NULL regardless, so let's always allocate
pushed_cond_guards for multi-column subqueries, no matter whether
its maybe_null was forced to true or false.
2017-07-12 10:39:02 +02:00

123 lines
2 KiB
Text

drop table if exists x1;
drop table if exists x2;
set @tmp_subselect_nulls=@@optimizer_switch;
set optimizer_switch='semijoin=off';
create table x1(k int primary key, d1 int, d2 int);
create table x2(k int primary key, d1 int, d2 int);
insert into x1 values
(10, 10, 10),
(20, 20, 20),
(21, 20, null),
(30, null, 30),
(40, 40, 40);
insert into x2 values
(10, 10, 10),
(20, 20, 20),
(21, 20, null),
(30, null, 30);
select *
from x1
where (d1, d2) in (select d1, d2
from x2);
k d1 d2
10 10 10
20 20 20
select *
from x1
where (d1, d2) in (select d1, d2
from x2) is true;
k d1 d2
10 10 10
20 20 20
select *
from x1
where (d1, d2) in (select d1, d2
from x2) is false;
k d1 d2
40 40 40
select *
from x1
where (d1, d2) in (select d1, d2
from x2) is unknown;
k d1 d2
21 20 NULL
30 NULL 30
select *
from x1
where d1 in (select d1
from x2
where x1.d2=x2.d2);
k d1 d2
10 10 10
20 20 20
select *
from x1
where d1 in (select d1
from x2
where x1.d2=x2.d2) is true;
k d1 d2
10 10 10
20 20 20
select *
from x1
where d1 in (select d1
from x2
where x1.d2=x2.d2) is false;
k d1 d2
21 20 NULL
40 40 40
select *
from x1
where d1 in (select d1
from x2
where x1.d2=x2.d2) is unknown;
k d1 d2
30 NULL 30
select *
from x1
where 1 in (select 1
from x2
where x1.d1=x2.d1 and x1.d2=x2.d2);
k d1 d2
10 10 10
20 20 20
select *
from x1
where 1 in (select 1
from x2
where x1.d1=x2.d1 and x1.d2=x2.d2) is true;
k d1 d2
10 10 10
20 20 20
select *
from x1
where 1 in (select 1
from x2
where x1.d1=x2.d1 and x1.d2=x2.d2) is false;
k d1 d2
21 20 NULL
30 NULL 30
40 40 40
select *
from x1
where 1 in (select 1
from x2
where x1.d1=x2.d1 and x1.d2=x2.d2) is unknown;
k d1 d2
select *
from x1
where exists (select *
from x2
where x1.d1=x2.d1 and x1.d2=x2.d2);
k d1 d2
10 10 10
20 20 20
set optimizer_switch= @tmp_subselect_nulls;
drop table x1;
drop table x2;
select (select 1, 2) in (select 3, 4);
(select 1, 2) in (select 3, 4)
0
select (select NULL, NULL) in (select 3, 4);
(select NULL, NULL) in (select 3, 4)
NULL