Skip to content

Commit 1be9c51

Browse files
spetruniaAlexey Botchkov
authored andcommitted
MDEV-25202: JSON_TABLE: Early table reference leads to unexpected result set
- Address review input. No functional changes.
1 parent 0fedaf2 commit 1be9c51

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

sql/json_table.cc

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,16 @@ static
135135
table_map get_disallowed_table_deps(JOIN *join, table_map table_func_bit)
136136
{
137137
table_map disallowed_tables= 0;
138-
if (get_disallowed_table_deps_for_list(table_func_bit, join->join_list,
139-
&disallowed_tables))
140-
return disallowed_tables;
141-
else
138+
if (!get_disallowed_table_deps_for_list(table_func_bit, join->join_list,
139+
&disallowed_tables))
142140
{
141+
// We haven't found the table with table_func_bit in all tables?
143142
DBUG_ASSERT(0);
144-
return disallowed_tables;
145143
}
144+
return disallowed_tables;
146145
}
147146

148147

149-
150148
/*
151149
A table that produces output rows for JSON_TABLE().
152150
*/
@@ -1229,10 +1227,10 @@ void Table_function_json_table::end_nested_path()
12291227

12301228
bool push_table_function_arg_context(LEX *lex, MEM_ROOT *alloc)
12311229
{
1232-
// Walk the context stack until we find a context that is select-level
1233-
// context.
1230+
// Walk the context stack until we find a context that is used for resolving
1231+
// the SELECT's WHERE clause.
12341232
List_iterator<Name_resolution_context> it(lex->context_stack);
1235-
Name_resolution_context *ctx= NULL;
1233+
Name_resolution_context *ctx;
12361234
while ((ctx= it++))
12371235
{
12381236
if (ctx->select_lex && ctx == &ctx->select_lex->context)
@@ -1242,6 +1240,10 @@ bool push_table_function_arg_context(LEX *lex, MEM_ROOT *alloc)
12421240

12431241
// Then, create a copy of it and return it.
12441242
Name_resolution_context *new_ctx= new (alloc) Name_resolution_context;
1243+
1244+
// Note: not all fields of *ctx are initialized yet at this point.
1245+
// We will get all of the fields filled in Table_function_json_table::setup
1246+
// (search for the "Prepare the name resolution context" comment).
12451247
*new_ctx= *ctx;
12461248
return lex->push_context(new_ctx);
12471249
}
@@ -1274,8 +1276,8 @@ int Table_function_json_table::setup(THD *thd, TABLE_LIST *sql_table,
12741276
save_is_item_list_lookup= thd->lex->current_select->is_item_list_lookup;
12751277
thd->lex->current_select->is_item_list_lookup= 0;
12761278

1277-
// Prepare the name resolution context. First, copy the context that
1278-
// is using for name resolution of the WHERE clause
1279+
// Prepare the name resolution context. First, copy the context that is
1280+
// used for name resolution of the WHERE clause
12791281
*m_context= thd->lex->current_select->context;
12801282

12811283
// Then, restrict it to only allow to refer to tables that come before the

0 commit comments

Comments
 (0)