Skip to content

Share one UnivMon across distinct, L2 and entropy; document why those readouts stay uncertified - #596

Draft
zzylol wants to merge 1 commit into
stack/509-w7a-pass2-sizingfrom
stack/509-w7a-univmon-accuracy
Draft

zzylol wants to merge 1 commit into
stack/509-w7a-pass2-sizingfrom
stack/509-w7a-univmon-accuracy

Conversation

@zzylol

@zzylol zzylol commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Rebased on main d4869a7 (DF 54).

Wave 1 chain: #594 → #593 → #592 → #591 → #595 → #596 → #597 → #598 → #599 (on #589)

Part of #509 (Example 2), #580 item E (accuracy part).

Why

#509 Example 2 has one UnivMon serving a distinct count, an entropy and an L2 norm, sized for the strictest requirement. Two things blocked it: the summary-capability rule (#595) knew only quantiles, and UnivMon certified only its total, so Stage 3 rejected every other UnivMon estimate.

What

  • Capability rule: a new FrequencyMoments key. Cardinality over at most one column, FrequencyL2 and FrequencyEntropy over the same input, window, grouping and column share one UnivMon. All members of the key are re-sized for the strictest requirement (W5). UnivMon's shape does not depend on ε, so the three UnivMon alternatives are one state. The other summaries (for example the distinct count's HLL) are re-sized for the strictest ε.
  • Accuracy model: no new certification. I found no sound bound for the shipped kernel's distinct, L2 or entropy readouts, so they stay uncertified (as the task allowed), and accuracy/estimators/univmon.rs documents why:
    • Published bound. Liu et al. (SIGCOMM 2016) build on Braverman and Ostrovsky's recursive sketch. With O(log n) layers, each returning a (g, ε)-cover of its substream, the recursive G-sum is (1 ± ε) with probability 1 − δ. The layer size is only stated asymptotically (O(ε⁻² log 1/δ) per CountSketch, times polylog factors). No constants exist to invert into (heap_size, rows, cols, layers).
    • Kernel. asap_sketchlib::UnivMon::calc_g_sum_heuristic keeps a fixed top-heap_size heap per layer, read through that layer's CountSketch. For distinct counts it also drops items below L2/√heap_size. Nothing bounds the probability that a heap is a cover, so the theorem's premise does not hold. Even with complete heaps, a CountSketch estimate can be ≤ 0 for a present item, so the distinct count is not certified there either.
    • CountSketch levels. A layer's CountSketch gives a sound F₂ (AMS) bound, but calc_l2 reads the recursive sum, not that estimate.
    • Path to a sound bound. Either an L2 readout from layer 0's CountSketch, or a per-layer cover guarantee. Both are executor/sketchlib changes, outside this PR.
  • Sizing: estimators::size_params is unchanged, since it has no bound to invert (UnivMon keeps its fixed candidate shape). This is documented on univmon::size_params.

Before / After

distinct_over_time(src[1m]) at ε = 0.02, entropy_over_time(src[1m]) at ε = 0.05 and l2_over_time(src[1m]) at ε = 0.01, through e2e_plan (frequency_moments_share_one_univmon_in_the_stage_pipeline):

accuracy model on #595 this PR
synthetic evidence certifying UnivMon one shared UnivMon, through the identical-expression merge after composition, because UnivMon's shape is fixed one shared UnivMon; the capability variant also lists it, with the other summaries re-sized for ε = 0.01
built-in no UnivMon selected no UnivMon selected: Stage 3 has no sound guarantee, unchanged

So for PromQL the new key changes no selection today. I checked this: the new pipeline test also passes on #595's rule. The key matters when pre-ASAP CSE merges nothing (SQL's unkeyed scans, for example COUNT(DISTINCT) next to a future SQL entropy/L2), or once UnivMon is sized per ε. The test pins the shared outcome either way.

Tests

  • univmon::tests::only_the_total_is_certified pins that the total is certified and the three readouts are not.
  • summary_capability::tests::frequency_moments_share_one_univmon.
  • summary_sharing::frequency_moments_share_one_univmon_in_the_stage_pipeline is the 3-consumer case through plan_stages via the facade.

Gate

fmt and clippy (-D warnings) are clean. cargo test --workspace: 1,531 passed and 7 ignored, against 1,528 and 7 on #595 and 1,517 and 10 on #589. That is +3 new tests. The Example 1 fixture regenerates byte-identically.

Gaps

  • Distinct, L2 and entropy from UnivMon still need a kernel readout with a provable bound before the built-in model can select them.
  • Example 2's "pairs share, third independent" candidates are not listed, by W5.

🤖 Generated with Claude Code

…umers

The summary-capability rule gains a frequency-moments key: a distinct count
(one column), an L2 norm and an entropy over the same input and window
share one UnivMon (#509 Example 2). UnivMon's shape does not depend on the
requirement, so the three alternatives are the same state.

The UnivMon accuracy model still certifies only the exact total. The
published UnivMon bounds (Liu et al., SIGCOMM 2016, via Braverman and
Ostrovsky) are asymptotic. The shipped kernel's heuristic recurrence, a
fixed top-heap per layer with an L2/sqrt(heap) cut, does not meet their
per-layer cover premise. Distinct count, L2 and entropy therefore stay
uncertified. The reasoning is documented, and a test pins it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zzylol
zzylol force-pushed the stack/509-w7a-univmon-accuracy branch from e5a24f4 to 2a98e68 Compare October 11, 2026 17:11
@zzylol
zzylol force-pushed the stack/509-w7a-pass2-sizing branch from 5a99a8b to 13aee91 Compare October 11, 2026 17:11
zzylol added a commit that referenced this pull request Oct 13, 2026
The specs and tests from #590 run the current stages through the shared
planner_layering_common pipeline (Pass 1 and composition,
optimize_physical_asap, select_plan); tests are named after the stages.
Materialization is read from the physical DAG (#667); window forms and
retention stay pending adapters. Behavior that works passes (29 tests);
every expectation that needs a feature not in this stack is ignored with
the PR that delivers it (29 tests): Pass 2 sharing (#588, #595, #596),
window composition (#601, #628, #634), materialization enumeration and
MatAtQuery (#604, #625), UnivMon sizing and accuracy (#621), SQL
recognition and COUNT(*) composition (#598, #603) and plan selection row
estimates (#632). Each spec's "Today" column states the current output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW
zzylol added a commit that referenced this pull request Oct 13, 2026
The specs and tests from #590 run the current stages through the shared
planner_layering_common pipeline (Pass 1 and composition,
optimize_physical_asap, select_plan); tests are named after the stages.
Materialization is read from the physical DAG (#667); window forms and
retention stay pending adapters. Behavior that works passes (29 tests);
every expectation that needs a feature not in this stack is ignored with
the PR that delivers it (29 tests): Pass 2 sharing (#588, #595, #596),
window composition (#601, #628, #634), materialization enumeration and
MatAtQuery (#604, #625), UnivMon sizing and accuracy (#621), SQL
recognition and COUNT(*) composition (#598, #603) and plan selection row
estimates (#632). Each spec's "Today" column states the current output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW
zzylol added a commit that referenced this pull request Oct 13, 2026
…stages (#577)

* test: acceptance spec and pending tests for planner-layering Example 1

Define MVP acceptance for #509 Example 1 before the Phase C stage APIs
exist: 1 -> 6 -> 6 -> 1 candidates (Pass 1 x identical-expression
sharing; physical operator implementation only, no materialization).

- Spec with per-stage candidate tables, invariants and doc ambiguities.
- Integration tests against todo!() stage stubs, ignored until the
  stages land; workload and Stage 0 frontend-shape tests run now.
- Expected-only asap-stage-pipeline/v1 fixture for the DAG viewer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: run the Example 1 acceptance tests against the real stages

Replace the todo!() stubs with adapters over Stage 0-3, un-ignore the 11
tests that pass, and give each still-ignored test the precise difference
between the implementation and the spec. Add runtime capability checks:
the selected plan compiles in the physical planner; compiling every
candidate stays ignored with the two runtime gaps it finds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: read Example 1 logical stages as flat DAGs after the export removal

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test: Example 1 acceptance on the composed stages (1 -> 3 -> 3 -> 1)

The tests run Pass 1 and composition, optimize_physical_asap and
select_plan through a shared tests/planner_layering_common pipeline, and
follow the decided behavior: three Pass 1 candidates (Q2 exact, CMS+heap,
CountSketch+heap), every sub-DAG NotMaterialized, P1 selected, CMS+heap
invalid (weights not proven non-negative) and CountSketch+heap invalid (a
Top-K output has no guarantee and no deployment evidence). Hydra (#605),
Pass 2 sharing (#588) and the two runtime gaps (#593, #579) stay ignored
with the PR that delivers them. Tests are named after the stages; the
compile check no longer uses the PromQL fallback. The spec lists where the
doc and the planner differ. The expected-only viewer fixture is removed:
the generated four-stage fixture replaces it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test: port #590's Example 2-4 acceptance specs and tests

The specs and tests from #590 run the current stages through the shared
planner_layering_common pipeline (Pass 1 and composition,
optimize_physical_asap, select_plan); tests are named after the stages.
Materialization is read from the physical DAG (#667); window forms and
retention stay pending adapters. Behavior that works passes (29 tests);
every expectation that needs a feature not in this stack is ignored with
the PR that delivers it (29 tests): Pass 2 sharing (#588, #595, #596),
window composition (#601, #628, #634), materialization enumeration and
MatAtQuery (#604, #625), UnivMon sizing and accuracy (#621), SQL
recognition and COUNT(*) composition (#598, #603) and plan selection row
estimates (#632). Each spec's "Today" column states the current output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* feat(devtools): stage_pipeline examples for #509 Example 3

Ported from #590: --example planner-layering-3a (Pattern A, ad hoc batch of
five p99 reports) and planner-layering-3b (Pattern B, repeating 5-min p99),
the Example 3 acceptance tests' workloads. Example 1's output is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test: follow #576's per-consumer charging and exact top-k columns

Plan selection charges a NotMaterialized node once per consuming query,
so the charging helper checks NodeCost.multiplier and the Example 4 A3
ambiguity is recorded as decided. Example 1 checks that exact Q2 sorts by
the ranked value and returns [job, topk_10]. The stage viewer guide's
tab 1 row now describes the actual all-exact result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* refactor(devtools): one planning pipeline for stage_pipeline and the acceptance tests

run_planning_stages and the #509 example workloads move into the
asap-devtools library; stage_pipeline serializes the run and the
planner-layering tests adapt it. The shared data workload drops
ingestion_rate for data at rest, which validate() requires.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* fix(devtools): select over every candidate; --max-displayed limits only the document

stage_pipeline capped enumeration at 64, so Example 3a (243 candidates)
selected P41 instead of the cheapest P122 (KLL for all five queries).
The pipeline now enumerates, optimizes and prices every candidate; the
document shows the first --max-displayed (default 64) plus the selected
one, with `combinations` and `capped`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* docs: Example 2's SQL candidates compose; the SQL test waits only on #598

Running the ignored SQL test composes every candidate and fails only on
Q2's options (per-source counts until #598), so #603 is not a blocker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test: name stages by number and name; say query-language frontends

The frontends' Run field, id and locals become stage0_query_language_frontends,
and test names carry stage0..stage3 with the stage name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test: charging helper follows plan selection's per-consumer rule

With a materialized node the helper accepted any multiplier >= 1. It now
computes each node's computations as plan selection does (walks from
query roots and materialized nodes' inputs, stopping at materialized
nodes), checked on a hand-built candidate with a materialized node.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test: Example 1 picks Q2 candidates by (option, no shared input)

physical_with and the invalid-candidate check no longer assume one
candidate per Q2 option, so #588's shared-input variants need no change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* docs: Example 3 Pattern B charges each node once per consuming query

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* docs(stage-viewer): rows 2, 3a and 3b describe the planner's current output

Read from uncapped runs: Example 2's sketch plans are rejected for having
no (ε, δ) guarantee, 3a selects P122 (first of 108 tied cheapest plans,
nothing shared yet) and 3b selects query-time KLL; panes and the latency
check come with the window-summary PRs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* docs(stage-viewer): row 2 from the SQL run; 3a ties 32 plans, not 108

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test: Example 1 counts only unshared candidates; stage3_ charging-helper names

The 3-logical and 3-physical counts now hold when #588 adds shared-input
variants.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* refactor(devtools): PlanningStagesRun fields carry stage number and name

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test(devtools): unique temp file per stage_pipeline run

cargo test runs the tests as threads of one process, so two runs of the same
example shared a file name and one deleted the other's output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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