Skip to content

Commit 459b147

Browse files
MDEV-37905: UNCACHEABLE_RAND inconsistently set on unions
We need to ensure that all the unions are marked as UNCACHEABLE_RAND in cases like: select * from t1 where 1 in (select 1 union select 2 union select RAND());
1 parent 49c3c2a commit 459b147

File tree

8 files changed

+84
-0
lines changed

8 files changed

+84
-0
lines changed

mysql-test/main/subselect.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7642,3 +7642,13 @@ Warning 1292 Truncated incorrect DECIMAL value: 'e'
76427642
DROP VIEW v1;
76437643
DROP TABLE t1, t2, t3;
76447644
# End of 10.10 tests
7645+
#
7646+
# MDEV-37905: UNCACHEABLE_RAND inconsistently set on unions
7647+
#
7648+
create table t1 (a int);
7649+
insert into t1 (a) values (1);
7650+
select * from t1 where 1 in (select 1 union select 2 union select RAND());
7651+
a
7652+
1
7653+
drop table t1;
7654+
# End of 12.2 tests

mysql-test/main/subselect.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6501,3 +6501,13 @@ DROP VIEW v1;
65016501
DROP TABLE t1, t2, t3;
65026502

65036503
--echo # End of 10.10 tests
6504+
6505+
--echo #
6506+
--echo # MDEV-37905: UNCACHEABLE_RAND inconsistently set on unions
6507+
--echo #
6508+
create table t1 (a int);
6509+
insert into t1 (a) values (1);
6510+
select * from t1 where 1 in (select 1 union select 2 union select RAND());
6511+
drop table t1;
6512+
6513+
--echo # End of 12.2 tests

mysql-test/main/subselect_no_exists_to_in.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7644,6 +7644,16 @@ Warning 1292 Truncated incorrect DECIMAL value: 'e'
76447644
DROP VIEW v1;
76457645
DROP TABLE t1, t2, t3;
76467646
# End of 10.10 tests
7647+
#
7648+
# MDEV-37905: UNCACHEABLE_RAND inconsistently set on unions
7649+
#
7650+
create table t1 (a int);
7651+
insert into t1 (a) values (1);
7652+
select * from t1 where 1 in (select 1 union select 2 union select RAND());
7653+
a
7654+
1
7655+
drop table t1;
7656+
# End of 12.2 tests
76477657
set optimizer_switch=default;
76487658
select @@optimizer_switch like '%exists_to_in=off%';
76497659
@@optimizer_switch like '%exists_to_in=off%'

mysql-test/main/subselect_no_mat.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7639,6 +7639,16 @@ Warning 1292 Truncated incorrect DECIMAL value: 'e'
76397639
DROP VIEW v1;
76407640
DROP TABLE t1, t2, t3;
76417641
# End of 10.10 tests
7642+
#
7643+
# MDEV-37905: UNCACHEABLE_RAND inconsistently set on unions
7644+
#
7645+
create table t1 (a int);
7646+
insert into t1 (a) values (1);
7647+
select * from t1 where 1 in (select 1 union select 2 union select RAND());
7648+
a
7649+
1
7650+
drop table t1;
7651+
# End of 12.2 tests
76427652
set optimizer_switch=default;
76437653
select @@optimizer_switch like '%materialization=on%';
76447654
@@optimizer_switch like '%materialization=on%'

mysql-test/main/subselect_no_opts.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7637,4 +7637,14 @@ Warning 1292 Truncated incorrect DECIMAL value: 'e'
76377637
DROP VIEW v1;
76387638
DROP TABLE t1, t2, t3;
76397639
# End of 10.10 tests
7640+
#
7641+
# MDEV-37905: UNCACHEABLE_RAND inconsistently set on unions
7642+
#
7643+
create table t1 (a int);
7644+
insert into t1 (a) values (1);
7645+
select * from t1 where 1 in (select 1 union select 2 union select RAND());
7646+
a
7647+
1
7648+
drop table t1;
7649+
# End of 12.2 tests
76407650
set @optimizer_switch_for_subselect_test=null;

mysql-test/main/subselect_no_scache.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7648,6 +7648,16 @@ Warning 1292 Truncated incorrect DECIMAL value: 'e'
76487648
DROP VIEW v1;
76497649
DROP TABLE t1, t2, t3;
76507650
# End of 10.10 tests
7651+
#
7652+
# MDEV-37905: UNCACHEABLE_RAND inconsistently set on unions
7653+
#
7654+
create table t1 (a int);
7655+
insert into t1 (a) values (1);
7656+
select * from t1 where 1 in (select 1 union select 2 union select RAND());
7657+
a
7658+
1
7659+
drop table t1;
7660+
# End of 12.2 tests
76517661
set optimizer_switch=default;
76527662
select @@optimizer_switch like '%subquery_cache=on%';
76537663
@@optimizer_switch like '%subquery_cache=on%'

mysql-test/main/subselect_no_semijoin.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7638,6 +7638,16 @@ DROP VIEW v1;
76387638
DROP TABLE t1, t2, t3;
76397639
# End of 10.10 tests
76407640
#
7641+
# MDEV-37905: UNCACHEABLE_RAND inconsistently set on unions
7642+
#
7643+
create table t1 (a int);
7644+
insert into t1 (a) values (1);
7645+
select * from t1 where 1 in (select 1 union select 2 union select RAND());
7646+
a
7647+
1
7648+
drop table t1;
7649+
# End of 12.2 tests
7650+
#
76417651
# MDEV-19714: JOIN::pseudo_bits_cond is not visible in EXPLAIN FORMAT=JSON
76427652
#
76437653
CREATE TABLE t1 ( a INT );

sql/sql_lex.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5131,6 +5131,19 @@ bool st_select_lex::optimize_unflattened_subqueries(bool const_only)
51315131
else
51325132
un->uncacheable&= ~UNCACHEABLE_DEPENDENT;
51335133
subquery_predicate->is_correlated= is_correlated_unit;
5134+
5135+
#ifdef DBUG_ASSERT_EXISTS
5136+
/*
5137+
If any SELECT in the unit is marked as UNCACHEABLE_RAND, then the
5138+
unit itself should also be marked as UNCACHEABLE_RAND.
5139+
*/
5140+
bool has_rand= false;
5141+
for (SELECT_LEX *sl= un->first_select(); sl && !has_rand;
5142+
sl= sl->next_select())
5143+
has_rand= sl->uncacheable & UNCACHEABLE_RAND;
5144+
DBUG_ASSERT(has_rand ==
5145+
static_cast<bool>(un->uncacheable & UNCACHEABLE_RAND));
5146+
#endif
51345147
}
51355148
}
51365149
return FALSE;
@@ -11351,6 +11364,7 @@ SELECT_LEX_UNIT *LEX::parsed_select_expr_cont(SELECT_LEX_UNIT *unit,
1135111364
}
1135211365
last->link_neighbour(sel1);
1135311366
sel1->set_master_unit(unit);
11367+
unit->uncacheable |= sel1->uncacheable;
1135411368
sel1->set_linkage_and_distinct(unit_type, distinct);
1135511369
unit->pre_last_parse= last;
1135611370
return unit;

0 commit comments

Comments
 (0)