revision-id: f5f6af6bee4271f48c76a5b3724a974e426a5c70 (mariadb-10.5.2-574-gf5f6af6bee4) parent(s): 0f14bc492c4409b61705b9c6a7a5bdb55301eefc author: Sergei Petrunia committer: Sergei Petrunia timestamp: 2021-04-12 16:18:12 +0300 message: MDEV-25346: JSON_TABLE: Server crashes in Item_field::fix_outer_field ... Use a function instead of lambda (TODO: squash this with previous patch for MDEV-25346) --- sql/sql_derived.cc | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 90e0b6068f9..29741cb1adb 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -23,7 +23,6 @@ #include "mariadb.h" /* NO_EMBEDDED_ACCESS_CHECKS */ -#include <functional> #include "sql_priv.h" #include "unireg.h" #include "sql_derived.h" @@ -597,6 +596,25 @@ bool mysql_derived_init(THD *thd, LEX *lex, TABLE_LIST *derived) } +/* + @brief + Reset the Name_resolution_context::outer_context for all ON expression + contexts in the given nested join. Do this recursively for all nested joins + it contains. +*/ + +static void reset_on_clauses_context(List<TABLE_LIST>& join_list) +{ + List_iterator<TABLE_LIST> li(join_list); + while (TABLE_LIST *table= li++) + { + if (table->on_context) + table->on_context->outer_context= NULL; + if (table->nested_join) + reset_on_clauses_context(table->nested_join->join_list); + } +} + /* Create temporary table structure (but do not fill it) @@ -765,19 +783,7 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived) sl->context.outer_context= 0; // And for ON clauses, if there are any - std::function<void(List<TABLE_LIST>&)> reset_context= - [&](List<TABLE_LIST> &join_list) - { - List_iterator<TABLE_LIST> li(join_list); - while (TABLE_LIST *table= li++) - { - if (table->on_context) - table->on_context->outer_context= NULL; - if (table->nested_join) - reset_context(table->nested_join->join_list); - } - }; - reset_context(*sl->join_list); + reset_on_clauses_context(*sl->join_list); if (!derived->is_with_table_recursive_reference() || (!derived->with->with_anchor &&