From 2a1035b004dfabcf3a7113be632b0030721a44d6 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 21 Jul 2017 20:09:19 +0300 Subject: MDEV-13351: Server crashes in st_select_lex::set_explain_type upon UNION with window function Make st_select_lex::set_explain_type() take into account that JOIN_TABs it is traversing may be also post-join aggregation JOIN_TABs (which have pos_in_table_list=NULL, etc). --- sql/sql_lex.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'sql/sql_lex.cc') diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 21d7637ec06..f9330bc4375 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -4395,10 +4395,16 @@ void st_select_lex::set_explain_type(bool on_the_fly) if (join) { bool uses_cte= false; - for (JOIN_TAB *tab= first_explain_order_tab(join); tab; - tab= next_explain_order_tab(join, tab)) + for (JOIN_TAB *tab= first_linear_tab(join, WITHOUT_BUSH_ROOTS, + WITH_CONST_TABLES); + tab; + tab= next_linear_tab(join, tab, WITHOUT_BUSH_ROOTS)) { - if (tab->table && tab->table->pos_in_table_list->with) + /* + pos_in_table_list=NULL for e.g. post-join aggregation JOIN_TABs. + */ + if (tab->table && tab->table->pos_in_table_list && + tab->table->pos_in_table_list->with) { uses_cte= true; break; -- cgit v1.2.1