Skip to content
/ server Public
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions mysql-test/main/subselect_nulls.result
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,50 @@ drop table t1, t2;
#
# End of 10.10 tests
#
#
# MDEV-32868 SELECT NULL,NULL IN (SUBQUERY) returns 0 instead of NULL
#
create table t1 (a int);
insert into t1 values (1);
create table t2 (a int, b int);
insert into t2 values (null, null);
# Scalar subquery returning NULLs as left part of IN
# All NULLs on left, no match possible -> NULL (subquery has rows)
select (select null, null) in (select 1, 2 from t1) from t1;
(select null, null) in (select 1, 2 from t1)
NULL
# One NULL on left, other column matches -> NULL
select (select null, 2) in (select 1, 2 from t1) from t1;
(select null, 2) in (select 1, 2 from t1)
NULL
# One NULL on left, other column doesn't match -> FALSE
select (select null, 3) in (select 1, 2 from t1) from t1;
(select null, 3) in (select 1, 2 from t1)
0
# Table with NULLs as left part
select (select * from t2) in (select 1, 2 from t1) from t1;
(select * from t2) in (select 1, 2 from t1)
NULL
# Exact match -> TRUE
select (select 1, 2) in (select 1, 2 from t1) from t1;
(select 1, 2) in (select 1, 2 from t1)
1
# No match, no NULLs -> FALSE
select (select 3, 4) in (select 1, 2 from t1) from t1;
(select 3, 4) in (select 1, 2 from t1)
0
# Right side has NULLs
create table t3 (a int, b int);
insert into t3 values (1, null), (null, 2);
# Left matches one column, right has NULL in other -> NULL
select (select 1, 2) in (select * from t3) from t1;
(select 1, 2) in (select * from t3)
NULL
# Both sides have NULLs -> NULL
select (select null, 2) in (select * from t3) from t1;
(select null, 2) in (select * from t3)
NULL
drop table t1, t2, t3;
#
# End of 10.11 tests
#
45 changes: 45 additions & 0 deletions mysql-test/main/subselect_nulls.test
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,48 @@ drop table t1, t2;
--echo #
--echo # End of 10.10 tests
--echo #

--echo #
--echo # MDEV-32868 SELECT NULL,NULL IN (SUBQUERY) returns 0 instead of NULL
--echo #

create table t1 (a int);
insert into t1 values (1);

create table t2 (a int, b int);
insert into t2 values (null, null);

--echo # Scalar subquery returning NULLs as left part of IN
--echo # All NULLs on left, no match possible -> NULL (subquery has rows)
select (select null, null) in (select 1, 2 from t1) from t1;

--echo # One NULL on left, other column matches -> NULL
select (select null, 2) in (select 1, 2 from t1) from t1;

--echo # One NULL on left, other column doesn't match -> FALSE
select (select null, 3) in (select 1, 2 from t1) from t1;

--echo # Table with NULLs as left part
select (select * from t2) in (select 1, 2 from t1) from t1;

--echo # Exact match -> TRUE
select (select 1, 2) in (select 1, 2 from t1) from t1;

--echo # No match, no NULLs -> FALSE
select (select 3, 4) in (select 1, 2 from t1) from t1;

--echo # Right side has NULLs
create table t3 (a int, b int);
insert into t3 values (1, null), (null, 2);

--echo # Left matches one column, right has NULL in other -> NULL
select (select 1, 2) in (select * from t3) from t1;

--echo # Both sides have NULLs -> NULL
select (select null, 2) in (select * from t3) from t1;

drop table t1, t2, t3;

--echo #
--echo # End of 10.11 tests
--echo #
12 changes: 6 additions & 6 deletions sql/sql_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13307,12 +13307,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
{
Json_writer_object trace_const_cond(thd);
trace_const_cond.add("condition_on_constant_tables", const_cond);
if (const_cond->is_expensive())
{
trace_const_cond.add("evaluated", "false")
.add("cause", "expensive cond");
}
else
if (const_cond->can_eval_in_optimize())
{
bool const_cond_result;
{
Expand All @@ -13328,6 +13323,11 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
DBUG_RETURN(1);
}
}
else
{
trace_const_cond.add("evaluated", "false")
.add("cause", "expensive cond");
}
join->exec_const_cond= const_cond;
}

Expand Down