1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

MDEV-25362 Incorrect name resolution for subqueries in ON expressions

This patch sets the proper name resolution context for outer references
used in a subquery from an ON clause. Usually this context is more narrow
than the name resolution context of the parent select that were used before
this fix.
This fix revealed another problem that concerned ON expressions used in
from clauses of specifications of derived tables / views / CTEs. The name
resolution outer context for such ON expression must be set to NULL to
prevent name resolution beyond the derived table where it is used.
The solution to resolve this problem applied in sql_derived.cc was provided
by Sergei Petrunia <sergey@mariadb.com>.

The change in sql_parse.cc is not good for 10.4+. A corresponding diff for
10.4+ will be provided in JIRA entry for this bug.

Approved by Oleksandr Byelkin <sanja@mariadb.com>
This commit is contained in:
Igor Babaev
2021-04-16 09:53:16 -07:00
parent 73bf62469e
commit 635b5ce355
5 changed files with 164 additions and 1 deletions

View File

@ -7418,6 +7418,7 @@ mysql_new_select(LEX *lex, bool move_down)
DBUG_RETURN(1);
select_lex->select_number= ++thd->lex->stmt_lex->current_select_number;
select_lex->parent_lex= lex; /* Used in init_query. */
Name_resolution_context *curr_context= lex->context_stack.head();
select_lex->init_query();
select_lex->init_select();
lex->nest_level++;
@ -7448,7 +7449,8 @@ mysql_new_select(LEX *lex, bool move_down)
By default we assume that it is usual subselect and we have outer name
resolution context, if no we will assign it to 0 later
*/
select_lex->context.outer_context= &select_lex->outer_select()->context;
select_lex->context.outer_context= curr_context;
}
else
{