summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRucha Deodhar <rucha.deodhar@mariadb.com>2021-10-06 23:43:16 +0530
committerRucha Deodhar <rucha.deodhar@mariadb.com>2021-10-07 00:31:19 +0530
commit5cc9cf9a05582307abefd8f3b57548945da86b1a (patch)
treedf0867a44b2b6308af23c6c03fdb09505e669f0f
parentaf95c991dd67bd50e9f2958750395a9d66d2035a (diff)
downloadmariadb-git-bb-10.7-MDEV-26606.tar.gz
MDEV-26681: ROW_NUMBER is not available within compound statement blocksbb-10.7-MDEV-26606
Fixed after patch MDEV-26606 because root cause was same. Analysis: m_current_row_for_warning is reset to 1 during cleanup phase of stored procedure. When we perform a copy because some statement of procedure created warning, this reset value is passed to push _warning(). Fix: Add a parameter in relevant functions to pass correct value of error index and don't use m_current_row_for_warning directly.
-rw-r--r--mysql-test/main/get_diagnostics.result33
-rw-r--r--mysql-test/main/get_diagnostics.test32
-rw-r--r--sql/lex.h2
3 files changed, 65 insertions, 2 deletions
diff --git a/mysql-test/main/get_diagnostics.result b/mysql-test/main/get_diagnostics.result
index 280dd671e43..7bd1bde10de 100644
--- a/mysql-test/main/get_diagnostics.result
+++ b/mysql-test/main/get_diagnostics.result
@@ -1638,3 +1638,36 @@ SELECT @ind, @msg;
@ind @msg
0 Invalid condition number
DROP TABLE t1;
+#
+# MDEV-26681: ROW_NUMBER is not available within compound statement blocks
+#
+CREATE OR REPLACE TABLE t1 (pk INT PRIMARY KEY, a CHAR(3));
+INSERT IGNORE INTO t1 VALUES (1,'foo'),(1,'bar'),(2,'foobar');
+Warnings:
+Warning 1062 Duplicate entry '1' for key 'PRIMARY'
+Warning 1265 Data truncated for column 'a' at row 3
+BEGIN NOT ATOMIC
+DECLARE i INT DEFAULT 0;
+DECLARE rnum INT DEFAULT -1;
+DECLARE msg VARCHAR(1024) DEFAULT '';
+DECLARE err INT DEFAULT -1;
+WHILE i < @@warning_count
+DO
+SET i = i + 1;
+GET DIAGNOSTICS CONDITION i rnum = ROW_NUMBER, msg = MESSAGE_TEXT, err = MYSQL_ERRNO;
+SELECT i, rnum, msg, err;
+END WHILE;
+END |
+i rnum msg err
+1 2 Duplicate entry '1' for key 'PRIMARY' 1062
+i rnum msg err
+2 3 Data truncated for column 'a' at row 3 1265
+GET DIAGNOSTICS CONDITION 1 @rnum = ROW_NUMBER, @msg = MESSAGE_TEXT, @err = MYSQL_ERRNO;
+select @rnum, @msg, @err;
+@rnum @msg @err
+2 Duplicate entry '1' for key 'PRIMARY' 1062
+GET DIAGNOSTICS CONDITION 2 @rnum = ROW_NUMBER, @msg = MESSAGE_TEXT, @err = MYSQL_ERRNO;
+SELECT @rnum, @msg, @err;
+@rnum @msg @err
+3 Data truncated for column 'a' at row 3 1265
+DROP TABLE t1;
diff --git a/mysql-test/main/get_diagnostics.test b/mysql-test/main/get_diagnostics.test
index 59b054bcc9b..83ea1dee343 100644
--- a/mysql-test/main/get_diagnostics.test
+++ b/mysql-test/main/get_diagnostics.test
@@ -1520,3 +1520,35 @@ GET DIAGNOSTICS CONDITION 5 @ind = ROW_NUMBER, @msg = MESSAGE_TEXT;
SELECT @ind, @msg;
DROP TABLE t1;
+
+--echo #
+--echo # MDEV-26681: ROW_NUMBER is not available within compound statement blocks
+--echo #
+
+CREATE OR REPLACE TABLE t1 (pk INT PRIMARY KEY, a CHAR(3));
+INSERT IGNORE INTO t1 VALUES (1,'foo'),(1,'bar'),(2,'foobar');
+
+DELIMITER |;
+
+BEGIN NOT ATOMIC
+ DECLARE i INT DEFAULT 0;
+ DECLARE rnum INT DEFAULT -1;
+ DECLARE msg VARCHAR(1024) DEFAULT '';
+ DECLARE err INT DEFAULT -1;
+ WHILE i < @@warning_count
+ DO
+ SET i = i + 1;
+ GET DIAGNOSTICS CONDITION i rnum = ROW_NUMBER, msg = MESSAGE_TEXT, err = MYSQL_ERRNO;
+ SELECT i, rnum, msg, err;
+ END WHILE;
+END |
+
+DELIMITER ;|
+
+GET DIAGNOSTICS CONDITION 1 @rnum = ROW_NUMBER, @msg = MESSAGE_TEXT, @err = MYSQL_ERRNO;
+select @rnum, @msg, @err;
+
+GET DIAGNOSTICS CONDITION 2 @rnum = ROW_NUMBER, @msg = MESSAGE_TEXT, @err = MYSQL_ERRNO;
+SELECT @rnum, @msg, @err;
+
+DROP TABLE t1;
diff --git a/sql/lex.h b/sql/lex.h
index 1ae577328ee..4ce88ccc2ee 100644
--- a/sql/lex.h
+++ b/sql/lex.h
@@ -567,8 +567,6 @@ SYMBOL symbols[] = {
{ "ROWS", SYM(ROWS_SYM)},
{ "ROWTYPE", SYM(ROWTYPE_MARIADB_SYM)},
{ "ROW_COUNT", SYM(ROW_COUNT_SYM)},
- /** sql_function and condition_property_name for GET DIAGNOSTICS */
- { "ROW_NUMBER", SYM(ROW_NUMBER_SYM)},
{ "ROW_FORMAT", SYM(ROW_FORMAT_SYM)},
/** sql_function and condition_property_name for GET DIAGNOSTICS */
{ "ROW_NUMBER", SYM(ROW_NUMBER_SYM)},