maria-developers team mailing list archive
-
maria-developers team
-
Mailing list archive
-
Message #12436
Re: 65af1d07771: MDEV-23178: Qualified asterisk not supported in INSERT .. RETURNING
Hi, Rucha!
On Oct 22, Rucha Deodhar wrote:
> revision-id: 65af1d07771 (mariadb-10.5.4-108-g65af1d07771)
> parent(s): bbd70fcc43c
> author: Rucha Deodhar <rucha.deodhar@xxxxxxxxxxx>
> committer: Rucha Deodhar <rucha.deodhar@xxxxxxxxxxx>
> timestamp: 2020-08-06 17:23:49 +0530
> message:
>
> MDEV-23178: Qualified asterisk not supported in INSERT .. RETURNING
>
> 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.
>
> diff --git a/mysql-test/main/insert_returning.result b/mysql-test/main/insert_returning.result
> index e664e02bedc..e1bab6f0329 100644
> --- a/mysql-test/main/insert_returning.result
> +++ b/mysql-test/main/insert_returning.result
> @@ -89,6 +89,9 @@ total val1 id1 && id1 id1 UPPER(val1) f(id1)
good tests!
> 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;
What about
INSERT t1 SELECT t2.* FROM t2 RETURNING t1.*;
can your is_insert_or_replace_returning distinguish between the first
and the second asterisk?
Regards,
Sergei
VP of MariaDB Server Engineering
and security@xxxxxxxxxxx