You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MDEV-8740 Wrong result for SELECT..WHERE year_field=10 AND NULLIF(year_field,2011.1)='2011'
MDEV-8754 Wrong result for SELECT..WHERE year_field=2020 AND NULLIF(year_field,2010)='2020' Problems: 1. Item_func_nullif stored a copy of args[0] in a private member m_args0_copy, which was invisible for the inherited Item_func menthods, like update_used_tables(). As a result, after equal field propagation things like Item_func_nullif::const_item() could return wrong result and a non-constant NULLIF() was erroneously treated as a constant at optimize_cond() time. Solution: removing m_args0_copy and storing the return value item in args[2] instead. 2. Equal field propagation did not work well for Item_fun_nullif. Solution: using ANY_SUBST for args[0] and args[1], as they are in comparison, and IDENTITY_SUBST for args[2], as it's not in comparison.
Copy file name to clipboardExpand all lines: mysql-test/r/null.result
+56Lines changed: 56 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1409,5 +1409,61 @@ Warnings:
1409
1409
Note 1003 select isnull((case when convert(`test`.`t1`.`a` using utf8) = (_utf8'a' collate utf8_bin) then NULL else `test`.`t1`.`a` end)) AS `expr` from `test`.`t1`
1410
1410
DROP TABLE t1;
1411
1411
#
1412
+
# MDEV-8740 Wrong result for SELECT..WHERE year_field=10 AND NULLIF(year_field,2011.1)='2011'
1413
+
#
1414
+
CREATE TABLE t1 (a YEAR);
1415
+
INSERT INTO t1 VALUES (2010),(2011);
1416
+
SELECT a=10 AND NULLIF(a,2011.1)='2011' AS cond FROM t1;
1417
+
cond
1418
+
0
1419
+
0
1420
+
SELECT * FROM t1 WHERE a=10;
1421
+
a
1422
+
2010
1423
+
SELECT * FROM t1 WHERE NULLIF(a,2011.1)='2011';
1424
+
a
1425
+
SELECT * FROM t1 WHERE a=10 AND NULLIF(a,2011.1)='2011';
1426
+
a
1427
+
EXPLAIN EXTENDED
1428
+
SELECT * FROM t1 WHERE a=10 AND NULLIF(a,2011.1)='2011';
1429
+
id select_type table type possible_keys key key_len ref rows filtered Extra
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where 0
1433
+
EXPLAIN EXTENDED
1434
+
SELECT * FROM t1 WHERE a=10 AND NULLIF(a,2011.1)=CONCAT('2011',RAND());
1435
+
id select_type table type possible_keys key key_len ref rows filtered Extra
1436
+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
1437
+
Warnings:
1438
+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 2010) and (<cache>((case when 2010 = 2011 then NULL else '2010' end)) = concat('2011',rand())))
1439
+
DROP TABLE t1;
1440
+
#
1441
+
# MDEV-8754 Wrong result for SELECT..WHERE year_field=2020 AND NULLIF(year_field,2010)='2020'
1442
+
#
1443
+
CREATE TABLE t1 (a YEAR);
1444
+
INSERT INTO t1 VALUES (2010),(2020);
1445
+
SELECT * FROM t1 WHERE a=2020;
1446
+
a
1447
+
2020
1448
+
SELECT * FROM t1 WHERE NULLIF(a,2010)='2020';
1449
+
a
1450
+
2020
1451
+
SELECT * FROM t1 WHERE a=2020 AND NULLIF(a,2010)='2020';
1452
+
a
1453
+
2020
1454
+
EXPLAIN EXTENDED
1455
+
SELECT * FROM t1 WHERE a=2020 AND NULLIF(a,2010)='2020';
1456
+
id select_type table type possible_keys key key_len ref rows filtered Extra
1457
+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
1458
+
Warnings:
1459
+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 2020)
1460
+
EXPLAIN EXTENDED
1461
+
SELECT * FROM t1 WHERE a=2020 AND NULLIF(a,2010)=CONCAT('2020',RAND());
1462
+
id select_type table type possible_keys key key_len ref rows filtered Extra
1463
+
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
1464
+
Warnings:
1465
+
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 2020) and (<cache>((case when 2020 = 2010 then NULL else '2020' end)) = concat('2020',rand())))
0 commit comments