From 8c9b2f3429fd385ded604ec048f1fcbd89c3a846 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Sat, 15 Feb 2014 01:21:46 +0400 Subject: MDEV-5581: Server crashes in in JOIN::prepare on 2nd execution of PS with materialization+semijoin - The problem was that JOIN::prepare() tried to set TABLE::maybe_null for a table in join. Non-merged semi-join tables 1) are present as join's base tables on second EXECUTE, but 2) do not yet have a TABLE object. Worked around the problem by putting mixed_implicit_grouping into JOIN object, and then passing it to JTBM tables in setup_jtbm_semi_joins(). --- sql/opt_subselect.cc | 1 + sql/sql_select.cc | 4 ++-- sql/sql_select.h | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'sql') diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index 60eee3fd48f..f19d9550f68 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -5204,6 +5204,7 @@ bool setup_jtbm_semi_joins(JOIN *join, List *join_list, if (!(*join_where)->fixed) (*join_where)->fix_fields(join->thd, join_where); } + table->table->maybe_null= test(join->mixed_implicit_grouping); } if ((nested_join= table->nested_join)) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 6f96a432a97..8d85d46f244 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -616,7 +616,7 @@ JOIN::prepare(Item ***rref_pointer_array, aggregate functions in the SELECT list is a MySQL exptenstion that is allowed only if the ONLY_FULL_GROUP_BY sql mode is not set. */ - bool mixed_implicit_grouping= false; + mixed_implicit_grouping= false; if ((~thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY) && select_lex->with_sum_func && !group_list) { @@ -655,7 +655,7 @@ JOIN::prepare(Item ***rref_pointer_array, Note: this loop doesn't touch tables inside merged semi-joins, because subquery-to-semijoin conversion has not been done yet. This is intended. */ - if (mixed_implicit_grouping) + if (mixed_implicit_grouping && tbl->table) tbl->table->maybe_null= 1; } diff --git a/sql/sql_select.h b/sql/sql_select.h index be595972671..569c0394d6e 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -1110,7 +1110,8 @@ public: */ JOIN *tmp_join; ROLLUP rollup; ///< Used with rollup - + + bool mixed_implicit_grouping; bool select_distinct; ///< Set if SELECT DISTINCT /** If we have the GROUP BY statement in the query, -- cgit v1.2.1