fix(clickhouse): reuse installed SQL plans for moving time windows - #691
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Dashboard refreshes change SQL timestamp bounds, so fixed canonical identities miss an installed plan even when its summaries cover the refreshed window.
What
Reuse same-duration time windows for simple single-table aggregates (
Project? → Aggregate → Scan). Preserve thresholds, projection constants and other query semantics. Multiple concrete windows can coexist without losing their individual materializations or pane origins. Keep old fixed publications compatible and external SQL subqueries fixed.How
Normalize resolved integer source bounds into a half-open window template. Keep concrete SQL identities as primary catalog keys and add a separate optional
ClickHousePlanningContext.window_templatesindex referencing those entries. Validate template references at publication. Serving first checks concrete identities, then tries indexed entries with the request's actual range until one passes execution and coverage checks.Support
>=,>,<,<=and checked constant integer arithmetic. Missing template metadata defaults to an empty index, preserving old publications. New template-index publications require the updated backend.Before this PR
An installed
[0,1000)aggregate cannot match a refresh for[1000,2000)because the timestamp literals change its catalog key.After this PR
The refresh reuses the installed computation and reads the new panes. The execution regression seeds consecutive panes with sums 2, 3 and 5, retains two concrete query entries, and verifies that the original windows and a later refresh each read their own data (20, 30 and 50 after the fixture's projection). Both compilation paths accept multiple concrete windows sharing a template; automatic compilation retains different materialization bindings for different pane origins. Missing or partial coverage falls back; a changed duration does not reuse the template.
Verification
CLICKHOUSE_URLconfigured, including real ClickHouse backfill and mixed-execution differential tests.clickhouse_differential_e2e,--test-threads=1). The new test automatically publishes two concrete windows, installs/activates the plan in a backend process, backfills both materializations from ClickHouse, and compares HTTP query results with the native oracle. Original windows return 5 and 12, a new window returns 24, equivalent inclusive/arithmetic bounds return 24, all withwarmrouting. A window with raw data but no summary returns 36 throughexact_fallback.sha256:fa394da808cc53f76d0344429421d6c422a6ee85fe7450135c0e3cff4df9bcbb, 2 CPUs / 2 GiB, with authentication enabled. The test container was removed afterward.git diff --checkpassed.8c03d7c, because the local shared checkout lacks methods required by main. The shared dependency checkout was not changed.Limitations
Complex query shapes retain fixed matching. Refreshes still require complete, aligned summary panes; this change does not alter pane granularity, retention, or maintenance scheduling. This PR establishes query-plan reuse, not measured end-to-end performance benefits.