revision-id: acc8c7068fa3d866305763cf6f62175ad1525650 (mariadb-10.4.3-42-gacc8c7068fa) parent(s): 04e00aa034ade8aeba0b49f014b892b76b138c52 author: Oleksandr Byelkin committer: Oleksandr Byelkin timestamp: 2019-03-07 11:30:06 +0100 message: Fix of prepared CREATE VIEW with global ORDER/GROUP --- sql/sql_union.cc | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/sql/sql_union.cc b/sql/sql_union.cc index a1d86959218..56b9c792771 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -1240,15 +1240,6 @@ bool st_select_lex_unit::prepare(TABLE_LIST *derived_arg, allocation in setup_ref_array(). */ fake_select_lex->n_child_sum_items+= global_parameters()->n_sum_items; - - saved_error= fake_select_lex->join-> - prepare(fake_select_lex->table_list.first, - 0, 0, - global_parameters()->order_list.elements, // og_num - global_parameters()->order_list.first, // order - false, NULL, NULL, NULL, - fake_select_lex, this); - fake_select_lex->table_list.empty(); } } else @@ -1259,6 +1250,26 @@ bool st_select_lex_unit::prepare(TABLE_LIST *derived_arg, */ table->reset_item_list(&item_list, intersect_mark ? 1 : 0); } + if (fake_select_lex != NULL && + (thd->stmt_arena->is_stmt_prepare() || + (thd->lex->context_analysis_only & CONTEXT_ANALYSIS_ONLY_VIEW))) + { + if (!fake_select_lex->join && + !(fake_select_lex->join= + new JOIN(thd, item_list, thd->variables.option_bits, result))) + { + fake_select_lex->table_list.empty(); + DBUG_RETURN(TRUE); + } + saved_error= fake_select_lex->join-> + prepare(fake_select_lex->table_list.first, + 0, 0, + global_parameters()->order_list.elements, // og_num + global_parameters()->order_list.first, // order + false, NULL, NULL, NULL, + fake_select_lex, this); + fake_select_lex->table_list.empty(); + } } thd->lex->current_select= lex_select_save;