Skip to content

fix: name SQL summary state columns independently of readout parameters - #516

Merged
zzylol merged 2 commits into
mainfrom
fix/sql-quantile-state-name
Oct 2, 2026
Merged

zzylol merged 2 commits into
mainfrom
fix/sql-quantile-state-name

Conversation

@zzylol

@zzylol zzylol commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Why

After #515, structurally identical summary producers are shared across queries. SQL p50 and p99 over the same table, filter and column were still not shared, and neither were PromQL cross-series quantile(0.5, x) / quantile(0.99, x). The KLL state column was named after the query's output column, and that name contains the quantile. For example, SQL produced approx_percentile_cont(lineitem.l_extendedprice,Float64(0.5)) and PromQL produced quantile_0_5. CSE compares schemas, so the two producers never matched, even though the quantile is only a readout parameter.

What

In construct_summary_agg (crates/asap-aware-mapping/src/replacement.rs), a Quantile state that reads a single column is now named after that input column. The column is resolved against the child schema, so SQL gets l_extendedprice and PromQL gets value. This follows the existing UnivMon rule that a state's identity does not depend on which statistic reads it. Output column names are unchanged, because the readout node still produces them.

Effects:

  • SQL p50 and p99 share one KLL.
  • PromQL cross-series p50 and p99 share one KLL.
  • median(x), approx_median(x) and approx_percentile_cont(x, 0.5) share one state.

TopK is unchanged, because k sizes the heap and so is a build parameter.

Tests

  • sql_p50_and_p99_share_one_producer: they share, output columns are unchanged, and a different WHERE or a different column is not shared.
  • cross_series_p50_and_p99_share_one_producer: fails without the fix.
  • Two existing assertions on the old PromQL cross-series state name now expect value. Their output-column assertions are unchanged.

Validation

On Rust 1.99, all of these pass: cargo fmt --check, clippy with -D warnings, the vendored MetricsQL baseline, and cargo test --workspace.

🤖 Generated with Claude Code

zzylol and others added 2 commits October 2, 2026 00:31
A quantile summary's state column was named after the query's output
column (e.g. `approx_percentile_cont(t.x,Float64(0.5))`, or PromQL's
cross-series `quantile_0_5`), so p50 and p99 over one input built
structurally different states and post-ASAP CSE could not share them.
Name the state after the column it summarizes; the readout keeps the
query's output name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zzylol
zzylol merged commit 107ab28 into main Oct 2, 2026
3 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