diff options
author | Rucha Deodhar <rucha.deodhar@mariadb.com> | 2021-07-17 16:36:55 +0530 |
---|---|---|
committer | Rucha Deodhar <rucha.deodhar@mariadb.com> | 2021-07-22 21:56:18 +0530 |
commit | 5518c3209b2505108cc7732f2ef94334573d4c27 (patch) | |
tree | a628c17d26659fecd34493d84e467bf887432b56 /sql | |
parent | 091743c6d88986dc10ff7b1bd2ff3a644739ac0f (diff) | |
download | mariadb-git-5518c3209b2505108cc7732f2ef94334573d4c27.tar.gz |
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.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/item.h | 2 | ||||
-rw-r--r-- | sql/sql_base.cc | 10 | ||||
-rw-r--r-- | sql/sql_base.h | 4 | ||||
-rw-r--r-- | sql/sql_select.cc | 2 |
4 files changed, 9 insertions, 9 deletions
diff --git a/sql/item.h b/sql/item.h index f71959e308e..74ffce6153f 100644 --- a/sql/item.h +++ b/sql/item.h @@ -3366,7 +3366,7 @@ public: friend bool insert_fields(THD *thd, Name_resolution_context *context, const char *db_name, const char *table_name, List_iterator<Item> *it, - bool any_privileges); + bool any_privileges, bool returning_field); }; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 04f8ed858f0..bb076ba9f3f 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -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; diff --git a/sql/sql_base.h b/sql/sql_base.h index 0c90a95b5b0..79f54dfe1ed 100644 --- a/sql/sql_base.h +++ b/sql/sql_base.h @@ -176,11 +176,11 @@ bool fill_record_n_invoke_before_triggers(THD *thd, 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); + uint *hidden_bit_fields, bool returning_field); void make_leaves_list(THD *thd, List<TABLE_LIST> &list, TABLE_LIST *tables, bool full_table_list, TABLE_LIST *boundary); int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields, - List<Item> *sum_func_list, SELECT_LEX *sl); + List<Item> *sum_func_list, SELECT_LEX *sl, bool returning_field); int setup_returning_fields(THD* thd, TABLE_LIST* table_list); bool setup_fields(THD *thd, Ref_ptr_array ref_pointer_array, List<Item> &item, enum_column_usage column_usage, diff --git a/sql/sql_select.cc b/sql/sql_select.cc index ab54bd3b94d..80bc24cd3cd 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1268,7 +1268,7 @@ JOIN::prepare(TABLE_LIST *tables_init, COND *conds_init, uint og_num, real_og_num+= select_lex->order_list.elements; DBUG_ASSERT(select_lex->hidden_bit_fields == 0); - if (setup_wild(thd, tables_list, fields_list, &all_fields, select_lex)) + if (setup_wild(thd, tables_list, fields_list, &all_fields, select_lex, false)) DBUG_RETURN(-1); if (select_lex->setup_ref_array(thd, real_og_num)) DBUG_RETURN(-1); |