Skip to content

Commit d66c171

Browse files
committed
Fixed the bug mdev-12554.
When the WHERE condition is always FALSE then JOIN::join_tab is NULL.
1 parent 54a995c commit d66c171

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

mysql-test/r/cte_recursive.result

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2759,3 +2759,15 @@ set standard_compliant_cte=default;
27592759
select @@standard_compliant_cte;
27602760
@@standard_compliant_cte
27612761
1
2762+
#
2763+
# mdev-12554: impossible where in recursive select
2764+
#
2765+
CREATE TABLE t1 (i int);
2766+
INSERT INTO t1 VALUES (1),(2);
2767+
WITH RECURSIVE
2768+
cte(f) AS ( SELECT i FROM t1 UNION SELECT f FROM t1, cte WHERE 1=0 )
2769+
SELECT * FROM cte;
2770+
f
2771+
1
2772+
2
2773+
DROP TABLE t1;

mysql-test/t/cte_recursive.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,3 +1834,15 @@ drop table objects, modules, module_arguments, module_results;
18341834
set standard_compliant_cte=default;
18351835
select @@standard_compliant_cte;
18361836

1837+
--echo #
1838+
--echo # mdev-12554: impossible where in recursive select
1839+
--echo #
1840+
1841+
CREATE TABLE t1 (i int);
1842+
INSERT INTO t1 VALUES (1),(2);
1843+
1844+
WITH RECURSIVE
1845+
cte(f) AS ( SELECT i FROM t1 UNION SELECT f FROM t1, cte WHERE 1=0 )
1846+
SELECT * FROM cte;
1847+
1848+
DROP TABLE t1;

sql/sql_union.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ bool st_select_lex_unit::exec_recursive()
12611261
!is_unrestricted);
12621262
if (!with_element->rec_result->first_rec_table_to_update)
12631263
with_element->rec_result->first_rec_table_to_update= rec_table;
1264-
if (with_element->level == 1)
1264+
if (with_element->level == 1 && rec_table->reginfo.join_tab)
12651265
rec_table->reginfo.join_tab->preread_init_done= true;
12661266
}
12671267
for (Item_subselect *sq= with_element->sq_with_rec_ref.first;

0 commit comments

Comments
 (0)