diff options
author | Oleksandr Byelkin <sanja@mariadb.com> | 2020-06-22 18:21:21 +0200 |
---|---|---|
committer | Oleksandr Byelkin <sanja@mariadb.com> | 2020-10-12 17:07:33 +0200 |
commit | 1df5a92df899d033841d77c34e1512e2b118b2ec (patch) | |
tree | ff7879dbeb9f0afd8ef95cfa4aad0b5ba741ea20 /sql/sql_insert.cc | |
parent | 861cd4ce286e7b41cc38facfc86c358e15161a74 (diff) | |
download | mariadb-git-bb-10.5-MDEV-21916.tar.gz |
MDEV-21916: COM_STMT_BULK_EXECUTE with RETURNING insert wrong valuesbb-10.5-MDEV-21916
To allocate new net buffer to avoid changing bufer we are reading.
Diffstat (limited to 'sql/sql_insert.cc')
-rw-r--r-- | sql/sql_insert.cc | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 4ad4c478937..ef2fa954bd6 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -710,6 +710,7 @@ bool mysql_insert(THD *thd, TABLE_LIST *table_list, Name_resolution_context *context; Name_resolution_context_state ctx_state; SELECT_LEX *returning= thd->lex->has_returning() ? thd->lex->returning() : 0; + unsigned char *readbuff= NULL; #ifndef EMBEDDED_LIBRARY char *query= thd->query(); @@ -771,7 +772,25 @@ bool mysql_insert(THD *thd, TABLE_LIST *table_list, /* Prepares LEX::returing_list if it is not empty */ if (returning) + { result->prepare(returning->item_list, NULL); + if (thd->is_bulk_op()) + { + /* + It is RETURNING which needs network buffer to write result set and + it is array binfing which need network buffer to read parameters. + So we allocate yet another network buffer. + The old buffer will be freed at the end of operation. + */ + DBUG_ASSERT(thd->protocol == &thd->protocol_binary); + readbuff= thd->net.buff; // old buffer + if (net_allocate_new_packet(&thd->net, thd, MYF(MY_THREAD_SPECIFIC))) + { + readbuff= NULL; // failure, net_allocate_new_packet keeps old buffer + goto abort; + } + } + } /* mysql_prepare_insert sets table_list->table if it was not set */ table= table_list->table; @@ -1304,7 +1323,8 @@ values_loop_end: thd->lex->current_select->save_leaf_tables(thd); thd->lex->current_select->first_cond_optimization= 0; } - + if (readbuff) + my_free(readbuff); DBUG_RETURN(FALSE); abort: @@ -1318,6 +1338,8 @@ abort: if (!joins_freed) free_underlaid_joins(thd, thd->lex->first_select_lex()); thd->abort_on_warning= 0; + if (readbuff) + my_free(readbuff); DBUG_RETURN(retval); } |