Commit e203951c authored by Neeraj Bisht's avatar Neeraj Bisht

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.
parent a7526397
...@@ -1496,7 +1496,11 @@ void Item_sum_count::clear() ...@@ -1496,7 +1496,11 @@ void Item_sum_count::clear()
bool Item_sum_count::add() bool Item_sum_count::add()
{ {
if (!args[0]->maybe_null || !args[0]->is_null()) for (uint i=0; i<arg_count; i++)
{
if (args[i]->maybe_null && args[i]->is_null())
return 0;
}
count++; count++;
return 0; return 0;
} }
......
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