From 2e404c98507740ebffcb23cfbf35d10c62916af5 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Tue, 12 Nov 2024 11:06:32 +0400 Subject: [PATCH] MDEV-21029 Incorrect result for expression with the <=> operator and IS NULL Item_func_equal erroneously derived is_null() from the parent class. Overriding it to return false because <=> can never return NULL. --- mysql-test/main/func_equal.result | 11 +++++++++++ mysql-test/main/func_equal.test | 15 +++++++++++++++ sql/item_cmpfunc.h | 1 + 3 files changed, 27 insertions(+) diff --git a/mysql-test/main/func_equal.result b/mysql-test/main/func_equal.result index f20b259191c..4f876b4f27b 100644 --- a/mysql-test/main/func_equal.result +++ b/mysql-test/main/func_equal.result @@ -43,3 +43,14 @@ a 4828532208463511553 drop table t1; #End of 4.1 tests +# Start of 10.5 tests +# +# MDEV-21029 Incorrect result for expression with the <=> operator and IS NULL +# +CREATE TABLE t0(c0 INT); +INSERT INTO t0 VALUES (1); +SELECT (c0 > (NULL <=> 0)) IS NULL AS c1 FROM t0; +c1 +0 +DROP TABLE t0; +# End of 10.5 tests diff --git a/mysql-test/main/func_equal.test b/mysql-test/main/func_equal.test index f17ebb5bd84..88cab9e95a0 100644 --- a/mysql-test/main/func_equal.test +++ b/mysql-test/main/func_equal.test @@ -44,3 +44,18 @@ select * from t1 where a in ('4828532208463511553'); drop table t1; --echo #End of 4.1 tests + + +--echo # Start of 10.5 tests + +--echo # +--echo # MDEV-21029 Incorrect result for expression with the <=> operator and IS NULL +--echo # + +CREATE TABLE t0(c0 INT); +INSERT INTO t0 VALUES (1); +SELECT (c0 > (NULL <=> 0)) IS NULL AS c1 FROM t0; +DROP TABLE t0; + + +--echo # End of 10.5 tests diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 1bc5f42ab2b..3d15a6f3dc1 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -782,6 +782,7 @@ public: enum Functype functype() const override { return EQUAL_FUNC; } enum Functype rev_functype() const override { return EQUAL_FUNC; } cond_result eq_cmp_result() const override { return COND_TRUE; } + bool is_null() override { return false; } const char *func_name() const override { return "<=>"; } Item *neg_transformer(THD *thd) override { return 0; } void add_key_fields(JOIN *join, KEY_FIELD **key_fields,