Skip to content

Commit 4422b0f

Browse files
author
Ramil Kalimullin
committed
Fix for bug#49517: Inconsistent behavior while using
NULLable BIGINT and INT columns in comparison Problem: a consequence of the fix for 43668. Some Arg_comparator inner initialization missed, that may lead to unpredictable (wrong) comparison results. Fix: always properly initialize Arg_comparator before its usage.
1 parent b4def7b commit 4422b0f

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

mysql-test/r/select.result

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4619,4 +4619,19 @@ c1
46194619
9.1234
46204620
DROP TABLE t1;
46214621
# End of test for bug#49489.
4622+
#
4623+
# Bug #49517: Inconsistent behavior while using
4624+
# NULLable BIGINT and INT columns in comparison
4625+
#
4626+
CREATE TABLE t1(a BIGINT UNSIGNED NOT NULL, b BIGINT NULL, c INT NULL);
4627+
INSERT INTO t1 VALUES(105, NULL, NULL);
4628+
SELECT * FROM t1 WHERE b < 102;
4629+
a b c
4630+
SELECT * FROM t1 WHERE c < 102;
4631+
a b c
4632+
SELECT * FROM t1 WHERE 102 < b;
4633+
a b c
4634+
SELECT * FROM t1 WHERE 102 < c;
4635+
a b c
4636+
DROP TABLE t1;
46224637
End of 5.1 tests

mysql-test/t/select.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3973,4 +3973,18 @@ SELECT * FROM t1 WHERE c1 < 9.12345;
39733973
DROP TABLE t1;
39743974
--echo # End of test for bug#49489.
39753975

3976+
3977+
--echo #
3978+
--echo # Bug #49517: Inconsistent behavior while using
3979+
--echo # NULLable BIGINT and INT columns in comparison
3980+
--echo #
3981+
CREATE TABLE t1(a BIGINT UNSIGNED NOT NULL, b BIGINT NULL, c INT NULL);
3982+
INSERT INTO t1 VALUES(105, NULL, NULL);
3983+
SELECT * FROM t1 WHERE b < 102;
3984+
SELECT * FROM t1 WHERE c < 102;
3985+
SELECT * FROM t1 WHERE 102 < b;
3986+
SELECT * FROM t1 WHERE 102 < c;
3987+
DROP TABLE t1;
3988+
3989+
39763990
--echo End of 5.1 tests

sql/item_cmpfunc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,9 +895,9 @@ int Arg_comparator::set_cmp_func(Item_result_field *owner_arg,
895895
ulonglong const_value= (ulonglong)-1;
896896
thd= current_thd;
897897
owner= owner_arg;
898+
set_null= set_null && owner_arg;
898899
a= a1;
899900
b= a2;
900-
owner= owner_arg;
901901
thd= current_thd;
902902

903903
if ((cmp_type= can_compare_as_dates(*a, *b, &const_value)))

sql/item_cmpfunc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ class Arg_comparator: public Sql_alloc
5454
/* Allow owner function to use string buffers. */
5555
String value1, value2;
5656

57-
Arg_comparator(): thd(0), a_cache(0), b_cache(0), set_null(0),
57+
Arg_comparator(): thd(0), a_cache(0), b_cache(0), set_null(TRUE),
5858
get_value_a_func(0), get_value_b_func(0) {};
5959
Arg_comparator(Item **a1, Item **a2): a(a1), b(a2), thd(0),
60-
a_cache(0), b_cache(0), set_null(0),
60+
a_cache(0), b_cache(0), set_null(TRUE),
6161
get_value_a_func(0), get_value_b_func(0) {};
6262

6363
int set_compare_func(Item_result_field *owner, Item_result type);

0 commit comments

Comments
 (0)