mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-19 06:01:57 +00:00
Respect PK for aggregate projection.
This commit is contained in:
parent
f86cedefc3
commit
75597efeb6
@ -582,6 +582,9 @@ bool optimizeUseAggregateProjections(QueryPlan::Node & node, QueryPlan::Nodes &
|
||||
ContextPtr context = reading->getContext();
|
||||
MergeTreeDataSelectExecutor reader(reading->getMergeTreeData());
|
||||
|
||||
auto ordinary_reading_select_result = reading->selectRangesToRead(parts);
|
||||
size_t ordinary_reading_marks = ordinary_reading_select_result->marks();
|
||||
|
||||
/// Selecting best candidate.
|
||||
for (auto & candidate : candidates.real)
|
||||
{
|
||||
@ -597,12 +600,18 @@ bool optimizeUseAggregateProjections(QueryPlan::Node & node, QueryPlan::Nodes &
|
||||
if (!analyzed)
|
||||
continue;
|
||||
|
||||
if (candidate.sum_marks > ordinary_reading_marks)
|
||||
continue;
|
||||
|
||||
if (best_candidate == nullptr || best_candidate->sum_marks > candidate.sum_marks)
|
||||
best_candidate = &candidate;
|
||||
}
|
||||
|
||||
if (!best_candidate)
|
||||
{
|
||||
reading->setAnalyzedResult(std::move(ordinary_reading_select_result));
|
||||
return false;
|
||||
}
|
||||
|
||||
QueryPlanStepPtr projection_reading;
|
||||
bool has_ordinary_parts;
|
||||
|
@ -0,0 +1,2 @@
|
||||
ReadFromMergeTree (p1)
|
||||
Granules: 1/12
|
@ -0,0 +1,31 @@
|
||||
-- Tags: no-random-merge-tree-settings
|
||||
|
||||
DROP TABLE IF EXISTS t0;
|
||||
|
||||
CREATE TABLE t0
|
||||
(
|
||||
c1 Int64,
|
||||
c2 Int64,
|
||||
c3 Int64,
|
||||
PROJECTION p1
|
||||
(
|
||||
SELECT
|
||||
c1,
|
||||
c2,
|
||||
sum(c3)
|
||||
GROUP BY
|
||||
c2,
|
||||
c1
|
||||
)
|
||||
)
|
||||
ENGINE = MergeTree ORDER BY (c1, c2);
|
||||
|
||||
INSERT INTO t0 SELECT
|
||||
number,
|
||||
-number,
|
||||
number
|
||||
FROM numbers_mt(1e5);
|
||||
|
||||
select * from (EXPLAIN indexes = 1 SELECT c1, sum(c3) FROM t0 GROUP BY c1) where explain like '%ReadFromMergeTree%';
|
||||
select * from (EXPLAIN indexes = 1 SELECT c1, sum(c3) FROM t0 WHERE c1 = 100 GROUP BY c1) where explain like '%Granules%';
|
||||
|
Loading…
Reference in New Issue
Block a user