1
0
mirror of https://github.com/MariaDB/server.git synced 2025-09-16 16:42:28 +03:00

MDEV-23178: Qualified asterisk not supported in INSERT .. RETURNING

Analysis: When we have INSERT/REPLACE returning with qualified asterisk in the
RETURNING clause, '*' is not resolved properly because of wrong context.
context->table_list is NULL or has incorrect table because context->table_list
has tables from the FROM clause. For INSERT/REPLACE...SELECT...RETURNING,
context->table_list has table we are inserting from. While in other
INSERT/REPLACE syntax, context->table_list is NULL because there is no FROM
clause.
Fix: If filling fields instead of '*' for qualified asterisk in RETURNING,
use first_name_resolution_table for correct resolution of item.
This commit is contained in:
Rucha Deodhar
2021-07-17 16:36:55 +05:30
parent 091743c6d8
commit 5518c3209b
8 changed files with 283 additions and 17 deletions

View File

@@ -7492,7 +7492,7 @@ static bool setup_natural_join_row_types(THD *thd,
****************************************************************************/
int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
List<Item> *sum_func_list, SELECT_LEX *select_lex)
List<Item> *sum_func_list, SELECT_LEX *select_lex, bool returning_field)
{
Item *item;
List_iterator<Item> it(fields);
@@ -7532,7 +7532,7 @@ int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
else if (insert_fields(thd, ((Item_field*) item)->context,
((Item_field*) item)->db_name.str,
((Item_field*) item)->table_name.str, &it,
any_privileges, &select_lex->hidden_bit_fields))
any_privileges, &select_lex->hidden_bit_fields, returning_field))
{
if (arena)
thd->restore_active_arena(arena, &backup);
@@ -7678,7 +7678,7 @@ int setup_returning_fields(THD* thd, TABLE_LIST* table_list)
if (!thd->lex->has_returning())
return 0;
return setup_wild(thd, table_list, thd->lex->returning()->item_list, NULL,
thd->lex->returning())
thd->lex->returning(), true)
|| setup_fields(thd, Ref_ptr_array(), thd->lex->returning()->item_list,
MARK_COLUMNS_READ, NULL, NULL, false);
}
@@ -8005,7 +8005,7 @@ bool get_key_map_from_key_list(key_map *map, TABLE *table,
bool
insert_fields(THD *thd, Name_resolution_context *context, const char *db_name,
const char *table_name, List_iterator<Item> *it,
bool any_privileges, uint *hidden_bit_fields)
bool any_privileges, uint *hidden_bit_fields, bool returning_field)
{
Field_iterator_table_ref field_iterator;
bool found;
@@ -8034,7 +8034,7 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name,
*/
TABLE_LIST *first= context->first_name_resolution_table;
TABLE_LIST *TABLE_LIST::* next= &TABLE_LIST::next_name_resolution_table;
if (table_name)
if (table_name && !returning_field)
{
first= context->table_list;
next= &TABLE_LIST::next_local;