diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2021-04-21 07:25:48 +0300 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2021-04-21 07:25:48 +0300 |
commit | 75c01f39b1b4a6d27d36d075f8baab9bdda7cc7e (patch) | |
tree | dff54cd8894bf7f9b46847fb1d3e03690179cf11 /sql/sql_derived.cc | |
parent | 562bbf5212412437273a469fc59138a939f123cd (diff) | |
parent | 922e676b43c7b5cb0f20ca67c6d2222e2fc5ec03 (diff) | |
download | mariadb-git-75c01f39b1b4a6d27d36d075f8baab9bdda7cc7e.tar.gz |
Merge 10.2 into 10.3
Diffstat (limited to 'sql/sql_derived.cc')
-rw-r--r-- | sql/sql_derived.cc | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 8a76a5372cc..50b0178c6c9 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -562,6 +562,32 @@ bool mysql_derived_init(THD *thd, LEX *lex, TABLE_LIST *derived) /* + @brief + Prevent name resolution out of context of ON expressions in derived tables + + @param + join_list list of tables used in from list of a derived + + @details + The function sets the Name_resolution_context::outer_context to NULL + for all ON expressions contexts in the given join list. It does this + recursively for all nested joins the list contains. +*/ + +static void nullify_outer_context_for_on_clauses(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) + nullify_outer_context_for_on_clauses(table->nested_join->join_list); + } +} + + +/* Create temporary table structure (but do not fill it) @param thd Thread handle @@ -726,7 +752,12 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived) /* prevent name resolving out of derived table */ for (SELECT_LEX *sl= first_select; sl; sl= sl->next_select()) { + // Prevent it for the WHERE clause sl->context.outer_context= 0; + + // And for ON clauses, if there are any + nullify_outer_context_for_on_clauses(*sl->join_list); + if (!derived->is_with_table_recursive_reference() || (!derived->with->with_anchor && !derived->with->is_with_prepared_anchor())) |