summaryrefslogtreecommitdiff
path: root/sql/sql_derived.cc
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2021-04-21 09:01:01 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2021-04-21 09:01:01 +0300
commit80ed136e6dd4a021b1fc9b7bd7077bf989c3d247 (patch)
treecc24f0e4e9241920329865a1b66c1d086aaeaa9a /sql/sql_derived.cc
parent675c22c065110be03a5fab82442d2c3dc32aefff (diff)
parenta0588d54a20488b17a178244989e1abc5151a88a (diff)
downloadmariadb-git-80ed136e6dd4a021b1fc9b7bd7077bf989c3d247.tar.gz
Merge 10.4 into 10.5
Diffstat (limited to 'sql/sql_derived.cc')
-rw-r--r--sql/sql_derived.cc33
1 files changed, 32 insertions, 1 deletions
diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc
index 35b4294707f..ecd5e7c21fe 100644
--- a/sql/sql_derived.cc
+++ b/sql/sql_derived.cc
@@ -1,6 +1,6 @@
/*
Copyright (c) 2002, 2011, Oracle and/or its affiliates.
- Copyright (c) 2010, 2020, MariaDB
+ Copyright (c) 2010, 2021, MariaDB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -596,6 +596,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)
@@ -760,7 +786,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()))