diff options
author | Sergei Petrunia <psergey@askmonty.org> | 2021-04-06 11:27:59 +0300 |
---|---|---|
committer | Alexey Botchkov <holyfoot@askmonty.org> | 2021-04-21 10:21:45 +0400 |
commit | 1be9c51beb836b0cd54e91c5b9dc8866137571c4 (patch) | |
tree | 5f313dcabc9304d09d875e5a23edc4f5adcf3b7d | |
parent | 0fedaf2183c025a8e736d1f25e7eb6742aced1ba (diff) | |
download | mariadb-git-1be9c51beb836b0cd54e91c5b9dc8866137571c4.tar.gz |
MDEV-25202: JSON_TABLE: Early table reference leads to unexpected result set
- Address review input. No functional changes.
-rw-r--r-- | sql/json_table.cc | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/sql/json_table.cc b/sql/json_table.cc index 9fd647dc6c5..dae1c694d78 100644 --- a/sql/json_table.cc +++ b/sql/json_table.cc @@ -135,18 +135,16 @@ static table_map get_disallowed_table_deps(JOIN *join, table_map table_func_bit) { table_map disallowed_tables= 0; - if (get_disallowed_table_deps_for_list(table_func_bit, join->join_list, - &disallowed_tables)) - return disallowed_tables; - else + if (!get_disallowed_table_deps_for_list(table_func_bit, join->join_list, + &disallowed_tables)) { + // We haven't found the table with table_func_bit in all tables? DBUG_ASSERT(0); - return disallowed_tables; } + return disallowed_tables; } - /* A table that produces output rows for JSON_TABLE(). */ @@ -1229,10 +1227,10 @@ void Table_function_json_table::end_nested_path() bool push_table_function_arg_context(LEX *lex, MEM_ROOT *alloc) { - // Walk the context stack until we find a context that is select-level - // context. + // Walk the context stack until we find a context that is used for resolving + // the SELECT's WHERE clause. List_iterator<Name_resolution_context> it(lex->context_stack); - Name_resolution_context *ctx= NULL; + Name_resolution_context *ctx; while ((ctx= it++)) { if (ctx->select_lex && ctx == &ctx->select_lex->context) @@ -1242,6 +1240,10 @@ bool push_table_function_arg_context(LEX *lex, MEM_ROOT *alloc) // Then, create a copy of it and return it. Name_resolution_context *new_ctx= new (alloc) Name_resolution_context; + + // Note: not all fields of *ctx are initialized yet at this point. + // We will get all of the fields filled in Table_function_json_table::setup + // (search for the "Prepare the name resolution context" comment). *new_ctx= *ctx; return lex->push_context(new_ctx); } @@ -1274,8 +1276,8 @@ int Table_function_json_table::setup(THD *thd, TABLE_LIST *sql_table, save_is_item_list_lookup= thd->lex->current_select->is_item_list_lookup; thd->lex->current_select->is_item_list_lookup= 0; - // Prepare the name resolution context. First, copy the context that - // is using for name resolution of the WHERE clause + // Prepare the name resolution context. First, copy the context that is + // used for name resolution of the WHERE clause *m_context= thd->lex->current_select->context; // Then, restrict it to only allow to refer to tables that come before the |