summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRucha Deodhar <rucha.deodhar@mariadb.com>2021-10-20 01:30:04 +0530
committerRucha Deodhar <rucha.deodhar@mariadb.com>2021-10-20 01:30:04 +0530
commit394bb653b0bd2f61a1054ce280ae895fb0d4c659 (patch)
tree6be3245bd5e3dac0a39ec7389abc7d2630e5f8fe
parent3c857a07d9286d310f2c09dff8389d7b9fae3e74 (diff)
downloadmariadb-git-394bb653b0bd2f61a1054ce280ae895fb0d4c659.tar.gz
MDEV-26695: Number of an invalid row is not calculated for table valuebb-10.7-row_number-MDEV-26695
constructor Analysis: counter does not increment while sending rows for table value constructor and so row_number assumes the default value (0 in this case). Fix: Increment the counter to avoid counter using default value.
-rw-r--r--mysql-test/main/get_diagnostics.result11
-rw-r--r--mysql-test/main/get_diagnostics.test11
-rw-r--r--sql/sql_tvc.cc15
3 files changed, 33 insertions, 4 deletions
diff --git a/mysql-test/main/get_diagnostics.result b/mysql-test/main/get_diagnostics.result
index 6b3793c2795..1767695e405 100644
--- a/mysql-test/main/get_diagnostics.result
+++ b/mysql-test/main/get_diagnostics.result
@@ -1747,3 +1747,14 @@ SELECT @n, @m;
@n @m
1 Column count doesn't match value count at row 1
DROP TABLE t1;
+#
+# Number of an invalid row is not calculated for table value constructor
+#
+CREATE TABLE t (a CHAR(1)) VALUES ('a'),('b'),('foo');
+Warnings:
+Warning 1406 Data too long for column 'a' at row 3
+GET DIAGNOSTICS CONDITION 1 @n= ROW_NUMBER;
+SELECT @n;
+@n
+3
+DROP TABLE t;
diff --git a/mysql-test/main/get_diagnostics.test b/mysql-test/main/get_diagnostics.test
index a7ad74a2c13..cfa14abccba 100644
--- a/mysql-test/main/get_diagnostics.test
+++ b/mysql-test/main/get_diagnostics.test
@@ -1640,3 +1640,14 @@ GET DIAGNOSTICS CONDITION 1 @n= ROW_NUMBER, @m= MESSAGE_TEXT;
SELECT @n, @m;
DROP TABLE t1;
+
+--echo #
+--echo # Number of an invalid row is not calculated for table value constructor
+--echo #
+
+CREATE TABLE t (a CHAR(1)) VALUES ('a'),('b'),('foo');
+
+GET DIAGNOSTICS CONDITION 1 @n= ROW_NUMBER;
+SELECT @n;
+
+DROP TABLE t;
diff --git a/sql/sql_tvc.cc b/sql/sql_tvc.cc
index 49f319b3856..a191ec9c328 100644
--- a/sql/sql_tvc.cc
+++ b/sql/sql_tvc.cc
@@ -422,7 +422,9 @@ bool table_value_constr::exec(SELECT_LEX *sl)
DBUG_ENTER("table_value_constr::exec");
List_iterator_fast<List_item> li(lists_of_values);
List_item *elem;
+ THD *cur_thd= sl->parent_lex->thd;
ha_rows send_records= 0;
+ int rc;
if (select_options & SELECT_DESCRIBE)
DBUG_RETURN(false);
@@ -438,16 +440,21 @@ bool table_value_constr::exec(SELECT_LEX *sl)
while ((elem= li++))
{
+ cur_thd->get_stmt_da()->inc_current_row_for_warning();
if (send_records >= sl->master_unit()->lim.get_select_limit())
- break;
- int rc=
- result->send_data_with_check(*elem, sl->master_unit(), send_records);
+ goto reset_counter_and_exit;
+ rc= result->send_data_with_check(*elem, sl->master_unit(), send_records);
if (!rc)
send_records++;
else if (rc > 0)
- DBUG_RETURN(true);
+ goto reset_counter_and_exit;
}
+reset_counter_and_exit:
+ cur_thd->get_stmt_da()->reset_current_row_for_warning(0);
+ if (rc>0)
+ DBUG_RETURN(true);
+
if (result->send_eof())
DBUG_RETURN(true);