mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 09:32:06 +00:00
Merge pull request #67804 from ClickHouse/vdimir/fix_fliter_pushdown_no_keys
Fix filter pushdown for aggregation without keys
This commit is contained in:
commit
a180bf311c
@ -442,6 +442,15 @@ size_t tryPushDownFilter(QueryPlan::Node * parent_node, QueryPlan::Nodes & nodes
|
||||
|
||||
const auto & params = aggregating->getParams();
|
||||
const auto & keys = params.keys;
|
||||
/** The filter is applied either to aggregation keys or aggregation result
|
||||
* (columns under aggregation is not available in outer scope, so we can't have a filter for them).
|
||||
* The filter for the aggregation result is not pushed down, so the only valid case is filtering aggregation keys.
|
||||
* In case keys are empty, do not push down the filter.
|
||||
* Also with empty keys we can have an issue with `empty_result_for_aggregation_by_empty_set`,
|
||||
* since we can gen a result row when everything is filtered.
|
||||
*/
|
||||
if (keys.empty())
|
||||
return 0;
|
||||
|
||||
const bool filter_column_is_not_among_aggregation_keys
|
||||
= std::find(keys.begin(), keys.end(), filter->getFilterColumnName()) == keys.end();
|
||||
|
@ -0,0 +1,6 @@
|
||||
---
|
||||
1 1
|
||||
---
|
||||
3 3
|
||||
---
|
||||
---
|
26
tests/queries/0_stateless/03217_fliter_pushdown_no_keys.sql
Normal file
26
tests/queries/0_stateless/03217_fliter_pushdown_no_keys.sql
Normal file
@ -0,0 +1,26 @@
|
||||
|
||||
|
||||
|
||||
select * from ( select sum(last_seen) as dates_seen, materialize(1) as last_seen ) where last_seen > 2;
|
||||
select * from ( select sum(last_seen) as dates_seen, materialize(2) as last_seen ) where last_seen < 2;
|
||||
select * from ( select sum(last_seen) as dates_seen, materialize(2) as last_seen GROUP BY 'a' ) where last_seen < 2;
|
||||
|
||||
select '---';
|
||||
select * from ( select sum(last_seen) as dates_seen, 1 as last_seen UNION ALL select sum(last_seen) as dates_seen, 3 as last_seen ) where last_seen < 2;
|
||||
|
||||
select '---';
|
||||
select * from ( select sum(last_seen) as dates_seen, 1 as last_seen UNION ALL select sum(last_seen) as dates_seen, 3 as last_seen ) where last_seen > 2;
|
||||
|
||||
select '---';
|
||||
with activity as (
|
||||
select
|
||||
groupUniqArrayState(toDate('2025-01-01 01:00:00')) as dates_seen,
|
||||
toDateTime('2025-01-01 01:00:00') as last_seen
|
||||
union all
|
||||
select
|
||||
groupUniqArrayState(toDate('2023-11-11 11:11:11')) as dates_seen,
|
||||
toDateTime('2023-11-11 11:11:11') as last_seen
|
||||
)
|
||||
select last_seen from activity
|
||||
where last_seen < toDateTime('2020-01-01 00:00:00');
|
||||
select '---';
|
Loading…
Reference in New Issue
Block a user