mirror of
https://github.com/MariaDB/server.git
synced 2025-12-24 11:21:21 +03:00
LP BUG#823169 fix.
For ANY subqueries NULLs should be ignored (if there is other values) when finding max min. For ALL subqueries NULLs should be saved if they found. Optimisation for ALL suqbueries if NULL is possible in the SELECT list with max/min aggregate function switched off. Some test changed where NULL is not used but optimization with max/min aggregate function important so NOT NULL added. mysql-test/r/explain.result: Forced old optimization. mysql-test/r/subselect.result: Forced old optimization. New test suite. mysql-test/t/explain.test: Forced old optimization. mysql-test/t/subselect.test: Forced old optimization. New test suite. sql/item_subselect.cc: Store converted subquery type. Switch off aggregate function optimisation for ALL and nulls. sql/sql_class.cc: Fixed NULL comparison. sql/sql_class.h: Store converted subquery type.
This commit is contained in:
@@ -2580,26 +2580,32 @@ bool select_max_min_finder_subselect::cmp_real()
|
||||
{
|
||||
Item *maxmin= ((Item_singlerow_subselect *)item)->element_index(0);
|
||||
double val1= cache->val_real(), val2= maxmin->val_real();
|
||||
|
||||
/* Ignore NULLs for ANY and keep them for ALL subqueries */
|
||||
if (cache->null_value)
|
||||
return (is_all && !maxmin->null_value) || (!is_all && maxmin->null_value);
|
||||
if (maxmin->null_value)
|
||||
return !is_all;
|
||||
|
||||
if (fmax)
|
||||
return (cache->null_value && !maxmin->null_value) ||
|
||||
(!cache->null_value && !maxmin->null_value &&
|
||||
val1 > val2);
|
||||
return (maxmin->null_value && !cache->null_value) ||
|
||||
(!cache->null_value && !maxmin->null_value &&
|
||||
val1 < val2);
|
||||
return(val1 > val2);
|
||||
return (val1 < val2);
|
||||
}
|
||||
|
||||
bool select_max_min_finder_subselect::cmp_int()
|
||||
{
|
||||
Item *maxmin= ((Item_singlerow_subselect *)item)->element_index(0);
|
||||
longlong val1= cache->val_int(), val2= maxmin->val_int();
|
||||
|
||||
/* Ignore NULLs for ANY and keep them for ALL subqueries */
|
||||
if (cache->null_value)
|
||||
return (is_all && !maxmin->null_value) || (!is_all && maxmin->null_value);
|
||||
if (maxmin->null_value)
|
||||
return !is_all;
|
||||
|
||||
if (fmax)
|
||||
return (cache->null_value && !maxmin->null_value) ||
|
||||
(!cache->null_value && !maxmin->null_value &&
|
||||
val1 > val2);
|
||||
return (maxmin->null_value && !cache->null_value) ||
|
||||
(!cache->null_value && !maxmin->null_value &&
|
||||
val1 < val2);
|
||||
return(val1 > val2);
|
||||
return (val1 < val2);
|
||||
}
|
||||
|
||||
bool select_max_min_finder_subselect::cmp_decimal()
|
||||
@@ -2607,13 +2613,16 @@ bool select_max_min_finder_subselect::cmp_decimal()
|
||||
Item *maxmin= ((Item_singlerow_subselect *)item)->element_index(0);
|
||||
my_decimal cval, *cvalue= cache->val_decimal(&cval);
|
||||
my_decimal mval, *mvalue= maxmin->val_decimal(&mval);
|
||||
|
||||
/* Ignore NULLs for ANY and keep them for ALL subqueries */
|
||||
if (cache->null_value)
|
||||
return (is_all && !maxmin->null_value) || (!is_all && maxmin->null_value);
|
||||
if (maxmin->null_value)
|
||||
return !is_all;
|
||||
|
||||
if (fmax)
|
||||
return (cache->null_value && !maxmin->null_value) ||
|
||||
(!cache->null_value && !maxmin->null_value &&
|
||||
my_decimal_cmp(cvalue, mvalue) > 0) ;
|
||||
return (maxmin->null_value && !cache->null_value) ||
|
||||
(!cache->null_value && !maxmin->null_value &&
|
||||
my_decimal_cmp(cvalue,mvalue) < 0);
|
||||
return (my_decimal_cmp(cvalue, mvalue) > 0) ;
|
||||
return (my_decimal_cmp(cvalue,mvalue) < 0);
|
||||
}
|
||||
|
||||
bool select_max_min_finder_subselect::cmp_str()
|
||||
@@ -2626,13 +2635,16 @@ bool select_max_min_finder_subselect::cmp_str()
|
||||
*/
|
||||
val1= cache->val_str(&buf1);
|
||||
val2= maxmin->val_str(&buf1);
|
||||
|
||||
/* Ignore NULLs for ANY and keep them for ALL subqueries */
|
||||
if (cache->null_value)
|
||||
return (is_all && !maxmin->null_value) || (!is_all && maxmin->null_value);
|
||||
if (maxmin->null_value)
|
||||
return !is_all;
|
||||
|
||||
if (fmax)
|
||||
return (cache->null_value && !maxmin->null_value) ||
|
||||
(!cache->null_value && !maxmin->null_value &&
|
||||
sortcmp(val1, val2, cache->collation.collation) > 0) ;
|
||||
return (maxmin->null_value && !cache->null_value) ||
|
||||
(!cache->null_value && !maxmin->null_value &&
|
||||
sortcmp(val1, val2, cache->collation.collation) < 0);
|
||||
return (sortcmp(val1, val2, cache->collation.collation) > 0) ;
|
||||
return (sortcmp(val1, val2, cache->collation.collation) < 0);
|
||||
}
|
||||
|
||||
int select_exists_subselect::send_data(List<Item> &items)
|
||||
|
||||
Reference in New Issue
Block a user