Commit 56a34960 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-10236 Where expression with NOT function gives incorrect result

Item_cache::is_null() erroneously returned null_value in a
non-cached state. Now Item_cache::is_null() uses has_value(),
which caches the value if not cached yet, similar to what other value methods do
(e.g. val_int, val_real, etc).
parent 64c115b8
...@@ -1572,5 +1572,22 @@ SELECT * FROM t1 WHERE NULLIF(NULLIF(NULLIF(NULLIF(NULLIF(NULLIF(NULLIF(NULLIF(N ...@@ -1572,5 +1572,22 @@ SELECT * FROM t1 WHERE NULLIF(NULLIF(NULLIF(NULLIF(NULLIF(NULLIF(NULLIF(NULLIF(N
i i
DROP TABLE t1; DROP TABLE t1;
# #
# MDEV-10236 Where expression with NOT function gives incorrect result
#
CREATE TABLE t1 (c1 INT);
INSERT INTO t1 VALUES (1),(2),(3);
EXPLAIN EXTENDED
SELECT * FROM t1 WHERE ((c1 IS NOT NULL) >= (NOT TRUE)) IS NOT NULL;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`c1` AS `c1` from `test`.`t1` where (((`test`.`t1`.`c1` is not null) >= <cache>((not(1)))) is not null)
SELECT * FROM t1 WHERE ((c1 IS NOT NULL) >= (NOT TRUE)) IS NOT NULL;
c1
1
2
3
DROP TABLE t1;
#
# End of 10.1 tests # End of 10.1 tests
# #
...@@ -1007,6 +1007,17 @@ SELECT * FROM t1 WHERE NULLIF(NULLIF(NULLIF(NULLIF(NULLIF(NULLIF(NULLIF(NULLIF(N ...@@ -1007,6 +1007,17 @@ SELECT * FROM t1 WHERE NULLIF(NULLIF(NULLIF(NULLIF(NULLIF(NULLIF(NULLIF(NULLIF(N
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # MDEV-10236 Where expression with NOT function gives incorrect result
--echo #
CREATE TABLE t1 (c1 INT);
INSERT INTO t1 VALUES (1),(2),(3);
EXPLAIN EXTENDED
SELECT * FROM t1 WHERE ((c1 IS NOT NULL) >= (NOT TRUE)) IS NOT NULL;
SELECT * FROM t1 WHERE ((c1 IS NOT NULL) >= (NOT TRUE)) IS NOT NULL;
DROP TABLE t1;
--echo # --echo #
--echo # End of 10.1 tests --echo # End of 10.1 tests
--echo # --echo #
...@@ -5050,7 +5050,7 @@ class Item_cache: public Item_basic_constant ...@@ -5050,7 +5050,7 @@ class Item_cache: public Item_basic_constant
bool basic_const_item() const bool basic_const_item() const
{ return MY_TEST(example && example->basic_const_item()); } { return MY_TEST(example && example->basic_const_item()); }
virtual void clear() { null_value= TRUE; value_cached= FALSE; } virtual void clear() { null_value= TRUE; value_cached= FALSE; }
bool is_null() { return null_value; } bool is_null() { return !has_value(); }
virtual bool is_expensive() virtual bool is_expensive()
{ {
if (value_cached) if (value_cached)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment