Skip to content

Commit 1b5fb40

Browse files
committed
MDEV-32308 Server crash on cleanup of non-fully-constructed-due-to-an-error CTE
Cleanup sequence comes after error state when not all units were prepared. The With_element without rec_result was created for following unit: "select 1 AS `1` union select 'x' AS x from x" the error happened in select "select x AS x" so above unit was not prepared. The case seems to be legal and the presence of rec_result must be checked during the cleanup.
1 parent 16d91f8 commit 1b5fb40

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

mysql-test/main/cte_recursive.result

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5857,3 +5857,10 @@ b rank() over (order by c)
58575857
drop view v1;
58585858
drop table t1;
58595859
# End of 10.4 tests
5860+
#
5861+
# MDEV-32308: Server crash on cleanup of
5862+
# non-fully-constructed-due-to-an-error CTE
5863+
#
5864+
SELECT ( WITH RECURSIVE x AS ( WITH x AS ( SELECT 1 FROM t14 ) SELECT x ) , t14 AS ( SELECT 1 UNION SELECT 'x' FROM x ) SELECT x FROM x WHERE ( SELECT x FROM x ) ) ;
5865+
ERROR 42S22: Unknown column 'x' in 'SELECT'
5866+
# End of 10.6 tests

mysql-test/main/cte_recursive.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4056,3 +4056,12 @@ drop view v1;
40564056
drop table t1;
40574057

40584058
--echo # End of 10.4 tests
4059+
4060+
--echo #
4061+
--echo # MDEV-32308: Server crash on cleanup of
4062+
--echo # non-fully-constructed-due-to-an-error CTE
4063+
--echo #
4064+
--error ER_BAD_FIELD_ERROR
4065+
SELECT ( WITH RECURSIVE x AS ( WITH x AS ( SELECT 1 FROM t14 ) SELECT x ) , t14 AS ( SELECT 1 UNION SELECT 'x' FROM x ) SELECT x FROM x WHERE ( SELECT x FROM x ) ) ;
4066+
4067+
--echo # End of 10.6 tests

sql/sql_union.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2622,7 +2622,8 @@ bool st_select_lex_unit::cleanup()
26222622
With_element *with_elem= with_element;
26232623
while ((with_elem= with_elem->get_next_mutually_recursive()) !=
26242624
with_element)
2625-
with_elem->rec_result->cleanup_count++;
2625+
if (with_elem->rec_result)
2626+
with_elem->rec_result->cleanup_count++;
26262627
DBUG_RETURN(FALSE);
26272628
}
26282629
}

0 commit comments

Comments
 (0)