Skip to content
Merged
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
10 changes: 10 additions & 0 deletions mysql-test/main/subselect.result
Original file line number Diff line number Diff line change
Expand Up @@ -7642,3 +7642,13 @@ Warning 1292 Truncated incorrect DECIMAL value: 'e'
DROP VIEW v1;
DROP TABLE t1, t2, t3;
# End of 10.10 tests
#
# MDEV-37905: UNCACHEABLE_RAND inconsistently set on unions
#
create table t1 (a int);
insert into t1 (a) values (1);
select * from t1 where 1 in (select 1 union select 2 union select RAND());
a
1
drop table t1;
# End of 12.2 tests
10 changes: 10 additions & 0 deletions mysql-test/main/subselect.test
Original file line number Diff line number Diff line change
Expand Up @@ -6501,3 +6501,13 @@ DROP VIEW v1;
DROP TABLE t1, t2, t3;

--echo # End of 10.10 tests

--echo #
--echo # MDEV-37905: UNCACHEABLE_RAND inconsistently set on unions
--echo #
create table t1 (a int);
insert into t1 (a) values (1);
select * from t1 where 1 in (select 1 union select 2 union select RAND());
drop table t1;

--echo # End of 12.2 tests
10 changes: 10 additions & 0 deletions mysql-test/main/subselect_no_exists_to_in.result
Original file line number Diff line number Diff line change
Expand Up @@ -7644,6 +7644,16 @@ Warning 1292 Truncated incorrect DECIMAL value: 'e'
DROP VIEW v1;
DROP TABLE t1, t2, t3;
# End of 10.10 tests
#
# MDEV-37905: UNCACHEABLE_RAND inconsistently set on unions
#
create table t1 (a int);
insert into t1 (a) values (1);
select * from t1 where 1 in (select 1 union select 2 union select RAND());
a
1
drop table t1;
# End of 12.2 tests
set optimizer_switch=default;
select @@optimizer_switch like '%exists_to_in=off%';
@@optimizer_switch like '%exists_to_in=off%'
Expand Down
10 changes: 10 additions & 0 deletions mysql-test/main/subselect_no_mat.result
Original file line number Diff line number Diff line change
Expand Up @@ -7639,6 +7639,16 @@ Warning 1292 Truncated incorrect DECIMAL value: 'e'
DROP VIEW v1;
DROP TABLE t1, t2, t3;
# End of 10.10 tests
#
# MDEV-37905: UNCACHEABLE_RAND inconsistently set on unions
#
create table t1 (a int);
insert into t1 (a) values (1);
select * from t1 where 1 in (select 1 union select 2 union select RAND());
a
1
drop table t1;
# End of 12.2 tests
set optimizer_switch=default;
select @@optimizer_switch like '%materialization=on%';
@@optimizer_switch like '%materialization=on%'
Expand Down
10 changes: 10 additions & 0 deletions mysql-test/main/subselect_no_opts.result
Original file line number Diff line number Diff line change
Expand Up @@ -7637,4 +7637,14 @@ Warning 1292 Truncated incorrect DECIMAL value: 'e'
DROP VIEW v1;
DROP TABLE t1, t2, t3;
# End of 10.10 tests
#
# MDEV-37905: UNCACHEABLE_RAND inconsistently set on unions
#
create table t1 (a int);
insert into t1 (a) values (1);
select * from t1 where 1 in (select 1 union select 2 union select RAND());
a
1
drop table t1;
# End of 12.2 tests
set @optimizer_switch_for_subselect_test=null;
10 changes: 10 additions & 0 deletions mysql-test/main/subselect_no_scache.result
Original file line number Diff line number Diff line change
Expand Up @@ -7648,6 +7648,16 @@ Warning 1292 Truncated incorrect DECIMAL value: 'e'
DROP VIEW v1;
DROP TABLE t1, t2, t3;
# End of 10.10 tests
#
# MDEV-37905: UNCACHEABLE_RAND inconsistently set on unions
#
create table t1 (a int);
insert into t1 (a) values (1);
select * from t1 where 1 in (select 1 union select 2 union select RAND());
a
1
drop table t1;
# End of 12.2 tests
set optimizer_switch=default;
select @@optimizer_switch like '%subquery_cache=on%';
@@optimizer_switch like '%subquery_cache=on%'
Expand Down
10 changes: 10 additions & 0 deletions mysql-test/main/subselect_no_semijoin.result
Original file line number Diff line number Diff line change
Expand Up @@ -7638,6 +7638,16 @@ DROP VIEW v1;
DROP TABLE t1, t2, t3;
# End of 10.10 tests
#
# MDEV-37905: UNCACHEABLE_RAND inconsistently set on unions
#
create table t1 (a int);
insert into t1 (a) values (1);
select * from t1 where 1 in (select 1 union select 2 union select RAND());
a
1
drop table t1;
# End of 12.2 tests
#
# MDEV-19714: JOIN::pseudo_bits_cond is not visible in EXPLAIN FORMAT=JSON
#
CREATE TABLE t1 ( a INT );
Expand Down
10 changes: 9 additions & 1 deletion sql/sql_lex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5160,13 +5160,20 @@ bool st_select_lex::optimize_unflattened_subqueries(bool const_only)
bool has_rand= false;
for (SELECT_LEX *sl= un->first_select(); sl && !has_rand;
sl= sl->next_select())
has_rand= sl->uncacheable & UNCACHEABLE_RAND;
has_rand= (sl->uncacheable & UNCACHEABLE_RAND);
if (has_rand)
{
for (SELECT_LEX *sl= un->first_select(); sl; sl= sl->next_select())
sl->uncacheable |= UNCACHEABLE_UNITED;
}

/*
If any SELECT in the unit is marked as UNCACHEABLE_RAND, then the
unit itself should also be marked as UNCACHEABLE_RAND.
*/
DBUG_ASSERT(has_rand ==
static_cast<bool>(un->uncacheable & UNCACHEABLE_RAND));

if (is_correlated_unit)
{
/*
Expand Down Expand Up @@ -11403,6 +11410,7 @@ SELECT_LEX_UNIT *LEX::parsed_select_expr_cont(SELECT_LEX_UNIT *unit,
}
last->link_neighbour(sel1);
sel1->set_master_unit(unit);
unit->uncacheable|= sel1->uncacheable;
sel1->set_linkage_and_distinct(unit_type, distinct);
unit->pre_last_parse= last;
return unit;
Expand Down