Skip to content

feat: preserve filters over planned summaries - #366

Merged
zzylol merged 1 commit into
mainfrom
feat/clickhouse-sql-filter
Sep 10, 2026
Merged

feat: preserve filters over planned summaries#366
zzylol merged 1 commit into
mainfrom
feat/clickhouse-sql-filter

Conversation

@zzylol

@zzylol zzylol commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Before this PR

PR #365 preserves SQL Project nodes while recursively materializing their aggregate children. A filter above a derived aggregate still becomes one opaque KeepPreAsap subtree, however. For example:

SELECT t.service, t.p
FROM (
  SELECT service, approx_percentile_cont(latency, 0.9) AS p
  FROM metrics WHERE service = 'api' GROUP BY service
) t
WHERE t.p > 100
ORDER BY t.p DESC
LIMIT 5

The canonical DAG contains Limit -> Sort -> Project -> Filter -> Project -> Aggregate, but the Filter hides the summary-bound aggregate from the final executable DAG.

After this PR

Filter is an explicit read-time ValueOperation that preserves its canonical predicate and output schema. Global selection materializes the Filter child independently, so the example retains the complete Project/Filter/Sort/Limit chain over SummaryEstimate -> SummaryAgg.

The two selection scopes remain separate: service = 'api' stays in the raw Scan that populates the summary, while t.p > 100 executes only after summary readout. If a child is unsupported, only that child remains an opaque fallback leaf and the supported Filter stays explicit.

The operation uses the existing shared post-ASAP value-operation and execution-data-state contracts. No predicate is reordered across an aggregate.

Verification

  • Rebased onto main including feat: add MetricsQL canonical frontend #368
  • cargo test --workspace --locked
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
  • cargo test -p asap-integration-tests --test sql_to_post_asap (7 passed)
  • MetricsQL external-consumer and vendored-baseline verification scripts
  • cargo fmt --all -- --check
  • git diff --check

Limitations

  • Join, Dedup, SetOp, window functions, and other relational operators remain conservative KeepPreAsap fallbacks.
  • Runtime consumers must implement ValueOperation::Filter before executing the newly explicit node.

@zzylol
zzylol force-pushed the feat/clickhouse-sql-filter branch from e2abfbb to 3df6f87 Compare September 10, 2026 04:38
@zzylol
zzylol force-pushed the feat/clickhouse-sql-filter branch from 3df6f87 to 4bdb8b8 Compare September 10, 2026 06:20
@zzylol
zzylol merged commit 26e5807 into main Sep 10, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant