summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRucha Deodhar <rucha.deodhar@mariadb.com>2021-10-18 13:27:36 +0530
committerRucha Deodhar <rucha.deodhar@mariadb.com>2021-10-20 09:04:09 +0530
commit5703d7ce1c2fc4cbd95c9b7747343923afc74571 (patch)
tree1bb593237c2ee48fe42f04608e4f36e985c49eb2
parentc27f04ede5a92f37d0b22e5c90523bcccb1af37a (diff)
downloadmariadb-git-bb-10.7-row_number-MDEV-26830.tar.gz
MDEV-26830: Wrong ROW_NUMBER in diagnostics upon INSERT IGNORE withbb-10.7-row_number-MDEV-26830
CHECK violation Analysis: When there is constraint fail we return non-zero value for view_check_option(). So we continue the loop which doesn't increment the counter because it increments at the end of the loop. Fix: Increment m_current_row_for_warning() at the beginning of loop. This will also fix similar bugs if any, about counter not incrementing correctly because of continue.
-rw-r--r--mysql-test/main/get_diagnostics.result18
-rw-r--r--mysql-test/main/get_diagnostics.test14
-rw-r--r--sql/sql_insert.cc4
3 files changed, 34 insertions, 2 deletions
diff --git a/mysql-test/main/get_diagnostics.result b/mysql-test/main/get_diagnostics.result
index 14137bde36d..558138d456f 100644
--- a/mysql-test/main/get_diagnostics.result
+++ b/mysql-test/main/get_diagnostics.result
@@ -1716,3 +1716,21 @@ SELECT @row_num;
@row_num
105
DROP PROCEDURE resignal_syntax;
+#
+# MDEV-26830: Wrong ROW_NUMBER in diagnostics upon INSERT IGNORE with
+# CHECK violation
+#
+CREATE TABLE t1 (a INT, CHECK(a>0));
+INSERT IGNORE INTO t1 VALUES (1),(0),(2),(0);
+Warnings:
+Warning 4025 CONSTRAINT `CONSTRAINT_1` failed for `test`.`t1`
+Warning 4025 CONSTRAINT `CONSTRAINT_1` failed for `test`.`t1`
+GET DIAGNOSTICS CONDITION 1 @n= ROW_NUMBER;
+SELECT @n;
+@n
+2
+GET DIAGNOSTICS CONDITION 2 @n= ROW_NUMBER;
+SELECT @n;
+@n
+4
+DROP TABLE t1;
diff --git a/mysql-test/main/get_diagnostics.test b/mysql-test/main/get_diagnostics.test
index 5c3071b4fe7..3bea7d80674 100644
--- a/mysql-test/main/get_diagnostics.test
+++ b/mysql-test/main/get_diagnostics.test
@@ -1601,3 +1601,17 @@ GET DIAGNOSTICS CONDITION 1 @row_num= ROW_NUMBER;
SELECT @row_num;
DROP PROCEDURE resignal_syntax;
+
+--echo #
+--echo # MDEV-26830: Wrong ROW_NUMBER in diagnostics upon INSERT IGNORE with
+--echo # CHECK violation
+--echo #
+
+CREATE TABLE t1 (a INT, CHECK(a>0));
+INSERT IGNORE INTO t1 VALUES (1),(0),(2),(0);
+GET DIAGNOSTICS CONDITION 1 @n= ROW_NUMBER;
+SELECT @n;
+GET DIAGNOSTICS CONDITION 2 @n= ROW_NUMBER;
+SELECT @n;
+
+DROP TABLE t1;
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 3dff6722a3d..9ad29eba04a 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -842,7 +842,7 @@ bool mysql_insert(THD *thd, TABLE_LIST *table_list,
switch_to_nullable_trigger_fields(*values, table);
}
its.rewind ();
- thd->get_stmt_da()->reset_current_row_for_warning(1);
+ thd->get_stmt_da()->reset_current_row_for_warning(0);
/* Restore the current context. */
ctx_state.restore_state(context, table_list);
@@ -1009,6 +1009,7 @@ bool mysql_insert(THD *thd, TABLE_LIST *table_list,
while ((values= its++))
{
+ thd->get_stmt_da()->inc_current_row_for_warning();
if (fields.elements || !value_count)
{
/*
@@ -1125,7 +1126,6 @@ bool mysql_insert(THD *thd, TABLE_LIST *table_list,
if (unlikely(error))
break;
info.accepted_rows++;
- thd->get_stmt_da()->inc_current_row_for_warning();
}
its.rewind();
iteration++;