[MDEV-22493] @@warning_count gets reset before execution of SELECT Created: 2020-05-07  Updated: 2023-04-27

Status: Open
Project: MariaDB Server
Component/s: Variables
Affects Version/s: 5.5, 10.1, 10.2, 10.3, 10.4, 10.5
Fix Version/s: 10.4, 10.5

Type: Bug Priority: Minor
Reporter: Elena Stepanova Assignee: Oleksandr Byelkin
Resolution: Unresolved Votes: 0
Labels: upstream


 Description   

Note: It may well be expected behavior. However, as recent experience has shown, it is counter-intuitive, so if it works so by design, it should be explicitly documented, probably here.

create table t1 (a int);
create table if not exists t1 (b int);
select @@warning_count or (select count(*) from t1);

f56ff9a644

MariaDB [test]> create table t1 (a int);
Query OK, 0 rows affected (0.234 sec)
 
MariaDB [test]> create table if not exists t1 (b int);
Query OK, 0 rows affected, 1 warning (0.001 sec)
 
MariaDB [test]> select @@warning_count or (select count(*) from t1);
+----------------------------------------------+
| @@warning_count or (select count(*) from t1) |
+----------------------------------------------+
|                                            0 |
+----------------------------------------------+
1 row in set (0.003 sec)

The intuitive expectation here is that when the SELECT is executed, the value of @warning_count is still 1, and SELECT will return true without even executing the right part of OR. However, it doesn't happen, at the moment of execution the value of @@warning_count is already 0. Apparently, it gets reset before SELECT starts.

Also reproducible on active versions of MySQL, but equally unclear from MySQL documentation whether it's expected behavior.



 Comments   
Comment by Sergei Golubchik [ 2020-05-07 ]

if I recall correctly, @@warning_count is reset at the beginning of every statement that uses tables. If that's the case then the behavior is correct.

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