From 5c0b63458bcb09e84e4ef8114560b8ef64a4191d Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 7 Oct 2021 18:19:56 +0200 Subject: [PATCH] MDEV-26693 ROW_NUMBER is wrong upon INSERT or UPDATE on Spider table in case of a bulk insert the server sends all rows to the engine, and then the engine replies that there was ER_DUP_ENTRY somewhere. the exact number of the row that caused the error is unknown. --- sql/sql_insert.cc | 9 +++- .../spider/r/error_row_number.result | 45 +++++++++++++++++++ .../mysql-test/spider/t/error_row_number.test | 37 +++++++++++++++ 3 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 storage/spider/mysql-test/spider/r/error_row_number.result create mode 100644 storage/spider/mysql-test/spider/t/error_row_number.test diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index f5bade9d02b..3dff6722a3d 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1158,8 +1158,13 @@ values_loop_end: table->file->ha_release_auto_increment(); if (using_bulk_insert) { - if (unlikely(table->file->ha_end_bulk_insert()) && - !error) + /* + if my_error() wasn't called yet on some specific row, end_bulk_insert() + can still do it, but the error shouldn't be for any specific row number + */ + if (!error) + thd->get_stmt_da()->reset_current_row_for_warning(0); + if (unlikely(table->file->ha_end_bulk_insert()) && !error) { table->file->print_error(my_errno,MYF(0)); error=1; diff --git a/storage/spider/mysql-test/spider/r/error_row_number.result b/storage/spider/mysql-test/spider/r/error_row_number.result new file mode 100644 index 00000000000..cc2b54878a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/error_row_number.result @@ -0,0 +1,45 @@ +# +# MDEV-26693 ROW_NUMBER is wrong upon INSERT or UPDATE on Spider table +# +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +connection child2_1; +create database auto_test_remote; +use auto_test_remote; +create table ta_r (id int primary key); +connection master_1; +create table spd (id int primary key) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +insert into spd values (1),(2),(1); +ERROR 23000: Duplicate entry '1' for key 'PRIMARY' +get diagnostics condition 1 @n = row_number; +select @n; +@n +0 +delete from spd; +insert into spd values (1),(2),(3),(13); +update spd set id = id + 10; +ERROR 23000: Duplicate entry '13' for key 'PRIMARY' +get diagnostics condition 1 @n = row_number; +select @n; +@n +0 +drop table spd; +connection child2_1; +drop database auto_test_remote; +connection master_1; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 diff --git a/storage/spider/mysql-test/spider/t/error_row_number.test b/storage/spider/mysql-test/spider/t/error_row_number.test new file mode 100644 index 00000000000..408e739656a --- /dev/null +++ b/storage/spider/mysql-test/spider/t/error_row_number.test @@ -0,0 +1,37 @@ +--echo # +--echo # MDEV-26693 ROW_NUMBER is wrong upon INSERT or UPDATE on Spider table +--echo # + +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--connection child2_1 +create database auto_test_remote; +use auto_test_remote; +create table ta_r (id int primary key); + +--connection master_1 +evalp create table spd (id int primary key) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; + +--error ER_DUP_ENTRY +insert into spd values (1),(2),(1); +get diagnostics condition 1 @n = row_number; +select @n; + +delete from spd; +insert into spd values (1),(2),(3),(13); +--error ER_DUP_ENTRY +update spd set id = id + 10; +get diagnostics condition 1 @n = row_number; +select @n; + +drop table spd; +--connection child2_1 +drop database auto_test_remote; +--connection master_1 +--disable_query_log +--disable_result_log +--source test_deinit.inc