diff options
author | Rucha Deodhar <rucha.deodhar@mariadb.com> | 2020-08-06 17:23:49 +0530 |
---|---|---|
committer | Rucha Deodhar <rucha.deodhar@mariadb.com> | 2020-10-23 12:57:02 +0530 |
commit | 6d881a271a977fe60c9c731ab19c6dd001cb69e2 (patch) | |
tree | 212eed9218a664850b21a6f7049f904cf7c50c73 /sql | |
parent | bbd70fcc43cc889e4593594ee5ca436fe1433aac (diff) | |
download | mariadb-git-bb-10.5-MDEV-23178.tar.gz |
MDEV-23178: Qualified asterisk not supported in INSERT .. RETURNINGbb-10.5-MDEV-23178
Anaylsis: When we have INSERT/REPLACE...RETURNING and have qualified asterisk,
table_name is not NULL and context->table_list is either NULL or has
incorrect reference because context->table_list has tables from the FROM clause.
context->table_list has incorrect reference (has table from the FROM clause
instead of table we are inserting into) for INSERT/REPLACE...SELECT...RETURNING
because we have a FROM clause from the SELECT statement.
For INSERT/REPLACE...RETURNING it is NULL because there is no FROM clause.
Fix: If table_name is not null, check if we have INSERT/REPLACE...RETURNING.
If so, the reference should be the table we are inserting into and not
the table in the FROM clause.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/sql_base.cc | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 45ce4be3eb5..4ce7b034029 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -7959,7 +7959,7 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name, bool any_privileges, uint *hidden_bit_fields) { Field_iterator_table_ref field_iterator; - bool found; + bool found, is_insert_or_replace_returning= false; char name_buff[SAFE_NAME_LEN+1]; DBUG_ENTER("insert_fields"); DBUG_PRINT("arena", ("stmt arena: %p",thd->stmt_arena)); @@ -7978,13 +7978,31 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name, found= FALSE; + if ((thd->lex->sql_command == SQLCOM_INSERT_SELECT || + thd->lex->sql_command == SQLCOM_REPLACE_SELECT || + thd->lex->sql_command == SQLCOM_INSERT || + thd->lex->sql_command == SQLCOM_REPLACE) && + thd->lex->has_returning()) + is_insert_or_replace_returning= true; + /* If table names are qualified, then loop over all tables used in the query, else treat natural joins as leaves and do not iterate over their underlying tables. + Also, When we have INSERT/REPLACE...RETURNING and have qualified asterisk, + table_name is not NULL and context->table_list is either NULL or has + incorrect reference because context->table_list has tables from the + FROM clause. + context->table_list has incorrect reference (has table from the FROM clause + instead of table we are inserting into) for + INSERT/REPLACE...SELECT...RETURNING because we have a FROM clause from the + SELECT statement. For INSERT/REPLACE...RETURNING it is NULL because + there is no FROM clause. */ - for (TABLE_LIST *tables= (table_name ? context->table_list : - context->first_name_resolution_table); + for (TABLE_LIST *tables= (table_name ? (is_insert_or_replace_returning ? + context->first_name_resolution_table : + context->table_list) : + (context->first_name_resolution_table)); tables; tables= (table_name ? tables->next_local : tables->next_name_resolution_table) |