[MDEV-26681] ROW_NUMBER is not available within compound statement blocks Created: 2021-09-25  Updated: 2021-10-06  Resolved: 2021-10-06

Status: Closed
Project: MariaDB Server
Component/s: Server, Stored routines
Affects Version/s: 10.7
Fix Version/s: 10.7.1

Type: Bug Priority: Critical
Reporter: Elena Stepanova Assignee: Rucha Deodhar
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Problem/Incident
is caused by MDEV-10075 Provide index of error causing error ... Closed
Relates
relates to MDEV-26606 ROW_NUMBER property value isn't passe... Closed

 Description   

This is in a way complementary to MDEV-26606, with some luck it has the same root cause, although I'm not sure about it

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 = error_index, msg = message_text, err = mysql_errno;
    select i, rnum, msg, err;
  end while;
end $
--delimiter ;
 
get diagnostics condition 1 @rnum = error_index, @msg = message_text, @err = mysql_errno;
select @rnum, @msg, @err;
get diagnostics condition 2 @rnum = error_index, @msg = message_text, @err = mysql_errno;
select @rnum, @msg, @err;

(To run via the client, remember to change --delimiter lines).

10.7 d552e092c9 Within the compound block

+------+------+---------------------------------------+------+
| i    | rnum | msg                                   | err  |
+------+------+---------------------------------------+------+
|    1 |    1 | Duplicate entry '1' for key 'PRIMARY' | 1062 |
+------+------+---------------------------------------+------+
1 row in set (0.001 sec)
 
+------+------+----------------------------------------+------+
| i    | rnum | msg                                    | err  |
+------+------+----------------------------------------+------+
|    2 |    1 | Data truncated for column 'a' at row 3 | 1265 |
+------+------+----------------------------------------+------+
1 row in set (0.001 sec)

Outside the compound block

MariaDB [test]> get diagnostics condition 1 @rnum = error_index, @msg = message_text, @err = mysql_errno;
Query OK, 0 rows affected (0.000 sec)
 
MariaDB [test]> select @rnum, @msg, @err;
+-------+---------------------------------------+------+
| @rnum | @msg                                  | @err |
+-------+---------------------------------------+------+
|     2 | Duplicate entry '1' for key 'PRIMARY' | 1062 |
+-------+---------------------------------------+------+
1 row in set (0.000 sec)
 
MariaDB [test]> get diagnostics condition 2 @rnum = error_index, @msg = message_text, @err = mysql_errno;
Query OK, 0 rows affected (0.000 sec)
 
MariaDB [test]> select @rnum, @msg, @err;
+-------+----------------------------------------+------+
| @rnum | @msg                                   | @err |
+-------+----------------------------------------+------+
|     3 | Data truncated for column 'a' at row 3 | 1265 |
+-------+----------------------------------------+------+
1 row in set (0.000 sec)

So, other diagnostics are equally available within the block and outside, but ERROR_INDEX is not.

Same applies to traditional stored procedures, naturally.



 Comments   
Comment by Rucha Deodhar [ 2021-09-26 ]

Patch (only includes test case):
https://github.com/MariaDB/server/commit/882fcade515a1a381c27a1bbee056f4223530428
https://github.com/MariaDB/server/commit/5a99eb4878b6b3bb00bef0cc552f707d32b91574

Fixed after MDEV-26606 . Same root cause

Comment by Sergei Golubchik [ 2021-09-28 ]

this is ok

Generated at Thu Feb 08 09:47:09 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.