You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The limit info lost in the AggregateExec when ser/deser the physical plan #10630
select
LO_SUPPKEY
from
SSB_1G.LINEORDER
GROUP BY
LO_SUPPKEY
limit 20 offset 10
The stand-alone physical plan is:
The agg exec add the limit value in the plan after the rule of LimitedDistinctAggregation, but it does not take effect when we send the physical plan to remote side.
But other issue i found in the AggregateExec, when we push the limit to the agg exec and will select the
if let Some(limit) = self.limit {
warn!("agg exec: {}", self.is_unordered_unfiltered_group_by_distinct());
if !self.is_unordered_unfiltered_group_by_distinct() {
warn!("agg exec: create GroupedPriorityQueue");
return Ok(StreamType::GroupedPriorityQueue(
GroupedTopKAggregateStream::new(self, context, partition, limit)?,
));
}
}
GroupedTopKAggregateStream.
The implementation of GroupedTopKAggregateStream get the right result for the SQL, but the efficiency is not good, because we don't care about the order and don't need to consume all of downstream data
But other issue i found in the AggregateExec, when we push the limit to the agg exec and will select the
if let Some(limit) = self.limit {
warn!("agg exec: {}", self.is_unordered_unfiltered_group_by_distinct());
if !self.is_unordered_unfiltered_group_by_distinct() {
warn!("agg exec: create GroupedPriorityQueue");
return Ok(StreamType::GroupedPriorityQueue(
GroupedTopKAggregateStream::new(self, context, partition, limit)?,
));
}
}
GroupedTopKAggregateStream.
The implementation of GroupedTopKAggregateStream get the right result for the SQL, but the efficiency is not good, because we don't care about the order and don't need to consume all of downstream data
In our sql:
select
LO_SUPPKEY
from
SSB_1G.LINEORDER
GROUP BY
LO_SUPPKEY
limit 20 offset 10
There is no sort/order and agg expression cause, we don't need to use the GroupedTopKAggregateStream struct to get the result. The GroupedTopKAggregateStream is not efficient for the SQL.
The GroupedTopKAggregateStream will consume all of the data and use the PriorityQueue to store and sort all data
I agree it is strange to be using that operator given a SQL without an aggregate. I thought it only kicked in if there was a MIN or MAX aggregate 🤔
I'm surprised this is being invoked, because:
// ensure the sort direction matches aggregate function
let (field, desc) = aggr.get_minmax_desc()?;
if desc != order.options.descending {
return None;
}
and
/// Finds the DataType and SortDirection for this Aggregate, if there is one
pub fn get_minmax_desc(&self) -> Option<(Field, bool)> {
let agg_expr = self.aggr_expr.as_slice().first()?;
if let Some(max) = agg_expr.as_any().downcast_ref::<Max>() {
Some((max.field().ok()?, true))
} else if let Some(min) = agg_expr.as_any().downcast_ref::<Min>() {
Some((min.field().ok()?, false))
} else {
None
}
}
I think pr #7192 introduced the top_k agg with the priority queue in the AggregateExec , and it is used to optimize the case like bellow pattern:
select column, min(xx) from table group by column order by min(xx)
But in the pr #8038 introduced the new rule of push limit for distinct column which use the is_unordered_unfiltered_group_by_distinct to check the condition without the sort condition in the plan. This rule is used to optimize the case like:
select distinct column from table
select column from table group by column
Activity
liukun4515 commentedon May 23, 2024
cc @alamb
I will fix this
liukun4515 commentedon May 23, 2024
my sql is like:
The stand-alone physical plan is:
The agg exec add the limit value in the plan after the rule of
LimitedDistinctAggregation, but it does not take effect when we send the physical plan to remote side.liukun4515 commentedon May 23, 2024
But other issue i found in the
AggregateExec, when we push the limit to the agg exec and will select theGroupedTopKAggregateStream.The implementation of
GroupedTopKAggregateStreamget the right result for the SQL, but the efficiency is not good, because we don't care about the order and don't need to consume all of downstream dataliukun4515 commentedon May 23, 2024
In our sql:
There is no sort/order and agg expression cause, we don't need to use the
GroupedTopKAggregateStreamstruct to get the result. TheGroupedTopKAggregateStreamis not efficient for the SQL.The
GroupedTopKAggregateStreamwill consume all of the data and use thePriorityQueueto store and sort all dataalamb commentedon May 23, 2024
I believe @avantgardnerio / @thinkharderdev worked on this code, as part of #7192
I agree it is strange to be using that operator given a SQL without an aggregate. I thought it only kicked in if there was a
MINorMAXaggregate 🤔avantgardnerio commentedon May 23, 2024
I'm surprised this is being invoked, because:
and
liukun4515 commentedon May 27, 2024
it's normal, if just want to get the distinct value for one or several column, and using the bellow sql:
The usages is from our cases, customer want to get the distinct value
liukun4515 commentedon May 27, 2024
I think pr #7192 introduced the top_k agg with the
priority queuein theAggregateExec, and it is used to optimize the case like bellow pattern:But in the pr #8038 introduced the new rule of
push limit for distinct columnwhich use theis_unordered_unfiltered_group_by_distinctto check the condition without thesortcondition in the plan. This rule is used to optimize the case like:liukun4515 commentedon May 27, 2024
I will file a pr to resolve the ser/deser issue.