[MDEV-30272] trigger sql_mode set to 'NO_UNSIGNED_SUBTRACTION' has no effect after upgrade from 10.3.37 to 10.4.27 Created: 2022-12-19  Updated: 2022-12-26

Status: Open
Project: MariaDB Server
Component/s: Data Manipulation - Update, Triggers
Affects Version/s: 10.4.27
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Daniel Gavrila Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Environment:

Linux 4.19.0-22-amd64 #1 SMP Debian 4.19.260-1 (2022-09-29) x86_64 GNU/Linux



 Description   

After upgrading from 10.3.37 to 10.4.27 a trigger stopped working.

The trigger relied on sql_mode: NO_UNSIGNED_SUBTRACTION to set a temporary negative value out of subtraction from two BIGINT UNSIGNED values.

Code that is working on 10.3 and stopped working on 10.4.27

create database test;
use test;
 
MariaDB [test]> select @@sql_mode;
+------------+
| @@sql_mode |
+------------+
|            |
+------------+
1 row in set (0.000 sec)
 
MariaDB [test]> select @@global.sql_mode;
+-------------------+
| @@global.sql_mode |
+-------------------+
|                   |
+-------------------+
1 row in set (0.000 sec)
 
 
/**/
create table article (id int unsigned not null auto_increment primary key, size bigint unsigned default 0);
insert into article values(NULL, 10);
 
DELIMITER $$
SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';
CREATE TRIGGER article_update_quota BEFORE UPDATE ON `article`
FOR EACH ROW
BEGIN
  DECLARE _size_diff BIGINT DEFAULT 0;
  IF OLD.size != NEW.size THEN
    *SET _size_diff = NEW.size - OLD.size;*
  END IF;
END;
SET sql_mode = @@global.sql_mode;
$$
 
DELIMITER ;
update article set size=9; // FAILS with "BIGINT value is out of range in 'NEW.size - OLD.size'" altough trigger sql_mode: NO_UNSIGNED_SUBTRACTION


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