Repository navigation
Add per-part aggregation cache for incremental GROUP BY - #101073
sociopate-sss wants to merge 114 commits into
Conversation
|
Workflow [PR], commit [532b887] Summary: ❌
AI ReviewSummaryAdds an experimental cache of per-part Missing context / blind spots
Final VerdictStatus: ✅ Approve. No new inline findings. Existing CI checks remain responsible for build and lint failures. |
…intermediate actions, experimental gate, ON CLUSTER support
…eload and performance test
…_cache_for_partial_results Resolve the conflict with the move of the settings changes history into the setting declarations (ee6b44f): the history records this PR added to `SettingsChangesHistory.cpp` now live as trailing arguments of the `DECLARE` of each setting. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…cache` perf test `allow_experimental_analyzer = 0` is rejected on master since the setting became obsolete, so drop it and let the performance test exercise the analyzer plan. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/Interpreters/Context.cpp
…gs` in `MergeTreeSequentialSource` Master added a `reader_executor.enabled` check on the local `read_settings`, which this PR moved into the merge/mutation branch. Check it on the final `MergeTreeReaderSettings` instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…he key `table_id` + `part_name` is not a stable identity of the part contents: e.g. `SYSTEM RESTORE REPLICA` resets block number counters in ZooKeeper, so a part with an already used name but different data can appear while the table `UUID` stays the same. Hash the total checksum of the part files into the key, so stale states are never reused. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The optimization deliberately fails closed for parallel-replica reads, so the tests that check that the cache is populated and used cannot pass in the `ParallelReplicas` CI job. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… `joinGet` or `dictGet` `ActionsDAG::updateHash` does not hash the contents of an `IN` set (`ColumnSet` is a dummy column), so `k IN (1)` and `k IN (2)` produce the same cache key, and a set built from a subquery or a `Set`/`Join` table changes with the data of another table while the query text stays the same. `joinGet` and `dictGet` read external state in the same way. Skip the optimization (fail-closed) when any intermediate or source filter DAG, including lambda bodies, uses them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…, use `VectorWithMemoryTracking` Master is now `26.11`, so the `settings_changes_history` check requires the new settings to be recorded under it. `src/Processors/Sources` is linted for plain `std` containers, so `PartAggregationCacheSource` now uses `VectorWithMemoryTracking`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=101073&sha=d30e4584e346c48e6e9a0d3c3c911a6db8510338&name_0=PR&name_1=Style%20check ClickHouse#101073 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Pass of 2026-10-21: merged current |
The reference server does not know `allow_experimental_part_aggregation_cache`, so putting it in the `<settings>` section failed the performance comparison with `Unknown setting`. Pass the new settings per query, and add a setup query marked with `do_not_check_in_pr` that fails on the reference server, so the test runs on the new server only in this PR. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=101073&sha=e5c237c2a397f597f087471369859b5e2a5f19f9&name_0=PR&name_1=Performance%20Comparison%20%28arm_release%2C%20master_head%2C%205%2F6%29 ClickHouse#101073 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ambdas in the part aggregation cache - The populator tracks the row count separately from the block, so a filter that removes the last column (`SELECT count() FROM t PREWHERE f`) no longer caches an empty state for a non-empty part. - Aggregate functions with a non-trivial state destructor own memory outside the aggregation arenas (`uniqExact`, `quantile`), which the cache budget does not see, and functions that parallelize their merge (`uniqExact`) may convert the shared cached right-hand side state in place. Skip the optimization for them. - `ActionsDAG::updateHash` does not hash lambda bodies and the settings captured by functions inside them, so skip the optimization for expressions with lambdas. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve conflicts in `MergeTreeSequentialSource`: master renamed the `prefetch` argument to `allow_remote_fs_prefetch` (prefetching is now started separately); keep the PR's `read_context` argument and apply the remote-FS prefetch switch in both the query-context and merge/mutation read-settings branches.
…he key `ActionsDAG::updateHash` does not see settings captured by ordinary functions at build time (`formatDateTime`, `locate`, `session_timezone`, ...), so a state warmed under one setting value was reused under another. Mix `queryConditionCacheSettingsSalt` into the final cache key, which covers keys, aggregate arguments, `WHERE`, `PREWHERE` and source filters, and add a regression test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/Processors/QueryPlan/Optimizations/optimizeTree.cpp # src/Storages/MergeTree/MergeTreeSequentialSource.cpp
…ggregation cache population The replayed `ExpressionStep`, `FilterStep` and `PREWHERE` actions were built with default `ExpressionActionsSettings`, so the cache population ignored short-circuit evaluation and the `max_temporary_columns` / `max_temporary_non_const_columns` limits. A query that fails without the cache could then succeed from a cached state, and a query relying on short-circuit evaluation (e.g. `if(x = 0, 0, intDiv(42, x))`) failed to populate the cache on every execution. Build every replayed action with `ExpressionActionsSettings(context)`, and add a regression test for the temporary-column limit and short-circuit evaluation in the aggregate argument, `WHERE` and `PREWHERE`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cache intermediate per-part aggregation states in an LRU cache. On repeated GROUP BY queries, reuse cached states for unchanged MergeTree parts and only aggregate new ones. Uses the existing
AggregatingProjectionStepmechanism to merge cached and fresh results.Changelog category
Experimental Feature
Changelog entry
Add per-part aggregation cache for incremental GROUP BY over MergeTree tables. Gated behind
allow_experimental_part_aggregation_cache.Note
Medium Risk
Adds a new caching layer that rewrites
GROUP BYquery plans and stores intermediate aggregation states, which can affect correctness/performance and memory usage if hashing/invalidation/configuration is wrong. Gated behind experimental/settings but touches core query planning and system commands.Overview
Adds an experimental per-part aggregation cache for
GROUP BYoverMergeTreetables, caching intermediate (non-final) per-part aggregation states and reusing them across repeated queries to avoid re-aggregating unchanged parts.Wires the cache into server/local startup and config reload (
part_aggregation_cache.max_size_in_bytes), introduces session settings to gate/enable reads+writes, and addsSYSTEM DROP PART AGGREGATION CACHEplus asystem.part_aggregation_cachetable for introspection.Implements a new query-plan optimization (
optimizeUsePartAggregationCache) that splits aggregation into cached-part reads (PartAggregationCacheSource) + normal aggregation for uncached parts, with a populator that can precompute missing entries. Includes new stateless and performance tests, and minor repo maintenance updates (PR template doc checklist; remove disabled Cargo entries fromdependabot.yaml).Reviewed by Cursor Bugbot for commit 7f7ba63. Bugbot is set up for automated code reviews on this repo. Configure here.
Workflow [PR]
Sync PR [sync-upstream/pr/101073]