From e02077aa03c9451bd89cccb75c6e52597f1c12cf Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Tue, 23 Apr 2024 09:55:49 +0400 Subject: [PATCH] MDEV-21076 NOT NULL and UNIQUE constraints cause SUM() to yield an incorrect result This problem was earlier fixed by the patch for MDEV 33344. Adding a test case only. --- mysql-test/main/func_regexp.result | 14 ++++++++++++++ mysql-test/main/func_regexp.test | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/mysql-test/main/func_regexp.result b/mysql-test/main/func_regexp.result index e0a4702c095..8e32732e12d 100644 --- a/mysql-test/main/func_regexp.result +++ b/mysql-test/main/func_regexp.result @@ -178,4 +178,18 @@ select 'foo' regexp x from t1 order by x desc; 0 1 drop table t1; +# +# MDEV-21076 NOT NULL and UNIQUE constraints cause SUM() to yield an incorrect result +# +CREATE TABLE t0(c0 INT NOT NULL, c1 CHAR UNIQUE); +INSERT INTO t0 VALUES (0, 1); +INSERT INTO t0 VALUES (0, ''); +SELECT (c1 RLIKE c1), (c0 IS NULL) FROM t0; +(c1 RLIKE c1) (c0 IS NULL) +1 0 +1 0 +SELECT SUM(a.t) FROM (SELECT (c1 RLIKE c1) = (c0 IS NULL) as t FROM t0) as a; +SUM(a.t) +0 +DROP TABLE t0; # End of 10.5 tests diff --git a/mysql-test/main/func_regexp.test b/mysql-test/main/func_regexp.test index b9e2ef197d6..48a273f6979 100644 --- a/mysql-test/main/func_regexp.test +++ b/mysql-test/main/func_regexp.test @@ -121,4 +121,16 @@ select 'foo' regexp x from t1 order by x asc; select 'foo' regexp x from t1 order by x desc; drop table t1; +--echo # +--echo # MDEV-21076 NOT NULL and UNIQUE constraints cause SUM() to yield an incorrect result +--echo # + +CREATE TABLE t0(c0 INT NOT NULL, c1 CHAR UNIQUE); +INSERT INTO t0 VALUES (0, 1); +INSERT INTO t0 VALUES (0, ''); +SELECT (c1 RLIKE c1), (c0 IS NULL) FROM t0; +SELECT SUM(a.t) FROM (SELECT (c1 RLIKE c1) = (c0 IS NULL) as t FROM t0) as a; +DROP TABLE t0; + + --echo # End of 10.5 tests