summaryrefslogtreecommitdiff
path: root/sql/item_sum.cc
diff options
context:
space:
mode:
authorNeeraj Bisht <neeraj.x.bisht@oracle.com>2013-09-04 10:45:55 +0530
committerNeeraj Bisht <neeraj.x.bisht@oracle.com>2013-09-04 10:45:55 +0530
commit6a23a4449529ed2ed6174072f1741518cc9f643d (patch)
tree578dfd1ae471b02b645db9558b80f4226fa949f3 /sql/item_sum.cc
parent5b333350a8f439d1456ef485e06a74e14ceaa19b (diff)
downloadmariadb-git-6a23a4449529ed2ed6174072f1741518cc9f643d.tar.gz
Bug#17222452 - SELECT COUNT(DISTINCT A,B) INCORRECTLY COUNTS ROWS
CONTAINING NULL Problem:- In MySQL, We can obtain the number of distinct expression combinations that do not contain NULL by giving a list of expressions in COUNT(DISTINCT). However rows with NULL values are incorrectly included in the count when loose index scan is used. Analysis:- In case of loose index scan, we check whether the field is null or not and increase the count in Item_sum_count::add(). But there we are checking for the first field in COUNT(DISTINCT), not for every field. This is causing an incorrect result. Solution:- Check all field in Item_sum_count::add(), whether there values are null or not. Then only increment the count. ****** Bug#17222452 - SELECT COUNT(DISTINCT A,B) INCORRECTLY COUNTS ROWS CONTAINING NULL Problem:- In MySQL, We can obtain the number of distinct expression combinations that do not contain NULL by giving a list of expressions in COUNT(DISTINCT). However rows with NULL values are incorrectly included in the count when loose index scan is used. Analysis:- In case of loose index scan, we check whether the field is null or not and increase the count in Item_sum_count::add(). But there we are checking for the first field in COUNT(DISTINCT), not for every field. This is causing an incorrect result. Solution:- Check all field in Item_sum_count::add(), whether there values are null or not. Then only increment the count.
Diffstat (limited to 'sql/item_sum.cc')
-rw-r--r--sql/item_sum.cc8
1 files changed, 6 insertions, 2 deletions
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index e194907fa06..3fbbc1b811a 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -1496,8 +1496,12 @@ void Item_sum_count::clear()
bool Item_sum_count::add()
{
- if (!args[0]->maybe_null || !args[0]->is_null())
- count++;
+ for (uint i=0; i<arg_count; i++)
+ {
+ if (args[i]->maybe_null && args[i]->is_null())
+ return 0;
+ }
+ count++;
return 0;
}