From 74d7496eb1e7778ad6fcdc93bc9c831bd3b66657 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 6 Nov 2005 12:35:49 +0400 Subject: Fix for bug #13044: BIT_COUNT with NULL values. sql/item_func.cc: Fix for bug #13044: BIT_COUNT with NULL values. Always set null_value. --- mysql-test/r/func_op.result | 11 +++++++++++ mysql-test/t/func_op.test | 12 ++++++++++++ sql/item_func.cc | 5 +---- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/func_op.result b/mysql-test/r/func_op.result index d009a66353e..486c55870c2 100644 --- a/mysql-test/r/func_op.result +++ b/mysql-test/r/func_op.result @@ -25,3 +25,14 @@ select -1 >> 0, -1 << 0; select -1 >> 1, -1 << 1; -1 >> 1 -1 << 1 9223372036854775807 18446744073709551614 +drop table if exists t1,t2; +create table t1(a int); +create table t2(a int, b int); +insert into t1 values (1), (2), (3); +insert into t2 values (1, 7), (3, 7); +select t1.a, t2.a, t2.b, bit_count(t2.b) from t1 left join t2 on t1.a=t2.a; +a a b bit_count(t2.b) +1 1 7 3 +2 NULL NULL NULL +3 3 7 3 +drop table t1, t2; diff --git a/mysql-test/t/func_op.test b/mysql-test/t/func_op.test index a312d6ac8c0..ab96caaff82 100644 --- a/mysql-test/t/func_op.test +++ b/mysql-test/t/func_op.test @@ -14,3 +14,15 @@ select 1 | -1, 1 ^ -1, 1 & -1; select 0 | -1, 0 ^ -1, 0 & -1; select -1 >> 0, -1 << 0; select -1 >> 1, -1 << 1; + +# +# Bug 13044: wrong bit_count() results +# + +drop table if exists t1,t2; +create table t1(a int); +create table t2(a int, b int); +insert into t1 values (1), (2), (3); +insert into t2 values (1, 7), (3, 7); +select t1.a, t2.a, t2.b, bit_count(t2.b) from t1 left join t2 on t1.a=t2.a; +drop table t1, t2; diff --git a/sql/item_func.cc b/sql/item_func.cc index 855e86b2382..e83d1f35db8 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1138,11 +1138,8 @@ longlong Item_func_find_in_set::val_int() longlong Item_func_bit_count::val_int() { ulonglong value= (ulonglong) args[0]->val_int(); - if (args[0]->null_value) - { - null_value=1; /* purecov: inspected */ + if ((null_value= args[0]->null_value)) return 0; /* purecov: inspected */ - } return (longlong) my_count_bits(value); } -- cgit v1.2.1