mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-26013 distinct not work properly in some cases for spider tables
The bug is caused by the following reasons: * spider_group_by_handler::init_scan() generates a query for a data node. * The function adds DISTINCT if and only if spider_group_by_handler::query::distinct is TRUE. * spider_group_by_handler::query::distinct is set to the value of JOIN::select_distinct in JOIN::make_aggr_tables_info(). * In the test case, DISTINCT is not added because JOIN::select_distinct is FALSE at the call of JOIN::make_aggr_tables_info(). Why JOIN::select_distinct is set to FALSE? That is because the function JOIN::optimize_stage2() convert DISTINCT into GROUP BY and then optimizes away GROUP BY.
This commit is contained in:
@ -3274,9 +3274,17 @@ bool JOIN::make_aggr_tables_info()
|
||||
|
||||
if (ht && ht->create_group_by)
|
||||
{
|
||||
/* Check if the storage engine can intercept the query */
|
||||
Query query= {&all_fields, select_distinct, tables_list, conds,
|
||||
group_list, order ? order : group_list, having};
|
||||
/*
|
||||
Check if the storage engine can intercept the query.
|
||||
|
||||
JOIN::optimize_stage2() might convert DISTINCT into GROUP BY and then
|
||||
optimize away GROUP BY (group_list). In such a case, we need to notify
|
||||
a storage engine supporting a group by handler of the existence of the
|
||||
original DISTINCT. Thus, we set select_distinct || group_optimized_away
|
||||
to Query::distinct.
|
||||
*/
|
||||
Query query= {&all_fields, select_distinct || group_optimized_away, tables_list,
|
||||
conds, group_list, order ? order : group_list, having};
|
||||
group_by_handler *gbh= ht->create_group_by(thd, &query);
|
||||
|
||||
if (gbh)
|
||||
|
Reference in New Issue
Block a user