Browse Source

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.
bb-10.6-MDEV-35511
Oleksandr Byelkin 2 years ago
parent
commit
1b5fb40b6d
  1. 7
      mysql-test/main/cte_recursive.result
  2. 9
      mysql-test/main/cte_recursive.test
  3. 3
      sql/sql_union.cc

7
mysql-test/main/cte_recursive.result

@ -5857,3 +5857,10 @@ b rank() over (order by c)
drop view v1;
drop table t1;
# End of 10.4 tests
#
# MDEV-32308: Server crash on cleanup of
# non-fully-constructed-due-to-an-error CTE
#
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 ) ) ;
ERROR 42S22: Unknown column 'x' in 'SELECT'
# End of 10.6 tests

9
mysql-test/main/cte_recursive.test

@ -4056,3 +4056,12 @@ drop view v1;
drop table t1;
--echo # End of 10.4 tests
--echo #
--echo # MDEV-32308: Server crash on cleanup of
--echo # non-fully-constructed-due-to-an-error CTE
--echo #
--error ER_BAD_FIELD_ERROR
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 ) ) ;
--echo # End of 10.6 tests

3
sql/sql_union.cc

@ -2622,7 +2622,8 @@ bool st_select_lex_unit::cleanup()
With_element *with_elem= with_element;
while ((with_elem= with_elem->get_next_mutually_recursive()) !=
with_element)
with_elem->rec_result->cleanup_count++;
if (with_elem->rec_result)
with_elem->rec_result->cleanup_count++;
DBUG_RETURN(FALSE);
}
}

Loading…
Cancel
Save