diff options
author | Igor Babaev <igor@askmonty.org> | 2018-12-01 15:06:04 -0800 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2018-12-01 15:06:04 -0800 |
commit | 46960365b102b1b446c300ed4da606e63ddfab5d (patch) | |
tree | ce2eefc5d12d7b26affd96f576dcd6908922d170 /sql/sql_union.cc | |
parent | 3e5162d814c522da6b0f19c3f6baae1ab5035db8 (diff) | |
download | mariadb-git-46960365b102b1b446c300ed4da606e63ddfab5d.tar.gz |
MDEV-17871 Crash when running explain with CTE
When the with clause of a query contains a recursive CTE that is not used
then processing of EXPLAIN for this query does not require optimization
of the unit specifying this CTE. In this case if 'derived' is the
TABLE_LIST object created for this CTE then derived->derived_result is NULL
and any assignment to derived->derived_result->table causes a crash.
After fixing this problem in the code of st_select_lex_unit::prepare()
EXPLAIN for such a query worked without crashes. Yet an execution
plan for the recursive CTE appeared there. The cause of this problem was
an incorrect condition used in JOIN::save_explain_data_intern() that
determined whether CTE was to be optimized or not. A similar condition was
used in select_describe() and this patch has corrected it as well.
Diffstat (limited to 'sql/sql_union.cc')
-rw-r--r-- | sql/sql_union.cc | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 44879f66edf..eb66dce25e3 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -694,8 +694,11 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result, instantiate_tmp_table, false)) goto err; if (!derived->table) - derived->table= derived->derived_result->table= - with_element->rec_result->rec_tables.head(); + { + derived->table= with_element->rec_result->rec_tables.head(); + if (derived->derived_result) + derived->derived_result->table= derived->table; + } with_element->mark_as_with_prepared_anchor(); is_rec_result_table_created= true; } |