Skip to content

chore(deps): bump asap_sketchlib to main a05b35c (+ #267, #270, #271 views); plan wire version 16 - #1539

Merged
zzylol merged 1 commit into
mainfrom
chore/bump-sketchlib-latest
Nov 27, 2026
Merged

zzylol merged 1 commit into
mainfrom
chore/bump-sketchlib-latest

Conversation

@zzylol

@zzylol zzylol commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Review guide

Base: main at a51c623 (after #1535, #1537 and #1536). This PR is not stacked.

Read these first:

  1. Cargo.toml: the pin and its comment. The pin commit is listed under Decisions.
  2. crates/cost/src/node/state_bytes/{mod.rs,tests.rs}: the DDSketch view header drops from 88 to 64 B. A new test pins the price to the library's view bytes, and the bands are recalibrated.
  3. crates/planner/src/installable/mod.rs: the wire version goes to 16.
  4. crates/executor/src/summary_kernels/dd_sketch.rs: q = 0 and q = 1 are no longer exact (see Behavior).

Mechanical, skim only:

  • Renames of SketchAlgorithm::* across crates and their docs.
  • JSON fixtures and stage0 goldens, where only the names change.
  • Regenerated sketch_plan_snapshots/*.json: names, definition_id (a hash that includes the name), and DDSketch bytes and costs.
  • dag-viewer test strings and the p90-kll.json labels.

Behavior: before → after

Workload: one PromQL quantile_over_time(0.99, data[5m]) evaluated every 10 s over 10,000 series, max error 5% (accepted as relative) (quantile-single-mvp in sketch_plan_snapshots, workload workloads/quantile-single.json). Run with asap_planner --run-until stage3 --format json --plan-file plan.json.

before (main) after (this PR)
selected plan DDSketch 10 s tumbling-window chain → 60 s merge → cover same DAG
plan file sketch type "summary_type": {"Sketch": "DDSketch"}; KLL plans: {"Sketch": "Kll"} DDSketch unchanged; KLL: {"Sketch": "KLL"} (Cms→CountMinSketch, Hll→HLL, Kmv→KMV, HydraCms→HydraCountMinSketch, …)
wire_version 15 16 (a file written by main is refused with UnsupportedWireVersion(Some(15)))
DDSketch tumbling-window build keeps 116,480,000 B 109,040,000 B
selected cost 8.00796836235e-7 /s 7.90576578141e-7 /s (−1.28%)
accepted line accepted rank (Kll) (KLL plans) accepted rank (KLL)

Executor answers change only at the DDSketch extremes. Sketchlib #252 removed the exact min/max, so quantile q = 0 and q = 1 now return the lowest or highest occupied bucket's representative (within α) instead of the exact min/max. Every other quantile is unchanged, and so is the relative-α guarantee the planner claims. No planner path answers min/max from a DDSketch: min_over_time/max_over_time are exact aggregates.

This keeps the planner on the same sketchlib main as the other repos (MVP correctness: one wire vocabulary).

Interfaces

Cargo.toml

-asap_sketchlib = { git = "https://github.com/ProjectASAP/asap_sketchlib", rev = "389530ce23b121520f0218a4471e376db2c35945" }
+asap_sketchlib = { git = "https://github.com/ProjectASAP/asap_sketchlib", rev = "01f3333cbdc7c55a36642e0938aa7f0040f2cfa8" }

crates/planner/src/installable/mod.rs

 /// The version of the plan-file format [`InstallablePlan`] serializes to:
-/// the DAG, its nodes' fields and the query texts.
-pub const INSTALLABLE_PLAN_WIRE_VERSION: u32 = 15;
+/// the DAG, its nodes' fields and the query texts. Bumped to 16 when a
+/// sketch family started being written by `asap_sketchlib`'s full
+/// `SketchAlgorithm` names (`{"Sketch": "KLL"}`, `"CountMinSketch"`, ...).
+pub const INSTALLABLE_PLAN_WIRE_VERSION: u32 = 16;

asap_types::summary_type::SketchAlgorithm is sketchlib's enum, re-exported, and serialized by variant name into plan files, --deployment-capabilities JSON (supported_summaries, exclusions) and the CLI document. Its variants as the planner sees them after this PR:

 /// A sketch family (asap_sketchlib::capability); stays.
 pub enum SketchAlgorithm {
-    Cms,
+    CountMinSketch,
     CountSketch,
     CountSketchWithL2Norm,
-    CmsWithHeap,
+    CountMinSketchWithHeap,
     CountSketchWithHeap,
-    CmsWithSpaceSaving,
+    CountMinSketchWithSpaceSaving,
     CountSketchWithSpaceSaving,
-    CmsFold,
+    CountMinSketchFold,
     CountSketchFold,
-    Hll,
-    HllHip,
-    Kmv,
-    Kll,
-    KllDynamic,
+    HLL,
+    HLLHip,
+    KMV,
+    KLL,
+    KLLDynamic,
     DDSketch,
     SpaceSaving,
-    Elastic,
-    Coco,
+    ElasticSketch,
+    CocoSketch,
     Bloom,
     SetAggregator,
     UnivMon,
     UnivMonTwoTier,
     UnivMonQ,
-    HydraCms,
+    HydraCountMinSketch,
     HydraCountSketch,
-    HydraKll,
-    HydraHll,
+    HydraKLL,
+    HydraHLL,
     HydraUnivMon,
 }

The planner's own enums keep their names: SketchParams::Kll { k }, θ text Kll(k=547), and the JSON "parameters": {"Kll": {"k": 547}}.

DDSketch's capability row gains StatisticKind::QuantileInterpolated. The deployment file that lists every family therefore lists it too (tools/dag-viewer/deployment-capabilities/every-summary-family.json).

Usage (from crates/planner-cli/tests/sketch_plan_snapshots.rs, quantile-single-mvp):

# workload: quantile_over_time(0.99, data[5m]) every 10 s over 10,000 series, max error 5%
asap_planner --workload crates/planner-cli/tests/sketch_plan_snapshots/workloads/quantile-single.json \
  --run-until stage3 --format json --plan-file plan.json
# Stage 1 picks the DDSketch family; Stage 3 prices each stored DDSketch window at
# state_bytes::ddsketch_state_bytes = 64 B header + 4 B column offset + its counts
# (88 B header before), and selects the same DAG at 7.906e-7 /s.
# plan.json: {"wire_version": 16, "dag": {... "summary_type": {"Sketch": "DDSketch"} ...}}

Algorithm changes

Cost model, DDSketch stored-state bytes (crates/cost/src/node/state_bytes/mod.rs, ddsketch_state_bytes)

  • Problem: the view layout lost sum, min and max (3 × 8 B), but the price still charged an 88-byte header. A one-value state was priced at 100 B but holds 76 B. The new test stored_ddsketch_header_is_the_librarys_view_header shows this and failed first: priced 100 B, view layout 76 B.
  • Before / after: HEADER_BYTES goes from 88 to 64. The rest of the formula is unchanged. The open (owned) state is priced through size_of::<DdSketch>(), which is already 24 B smaller.
  • Correctness: the new test compares the price with DdSketch::to_view_bytes().len() + 4 from the library. stored_ddsketch_prices_never_fall_below_what_the_executor_holds still passes. The value-shape bands were recalibrated: held bytes fell by 24 B, so narrow-value ratios rose. Gauge and per-series 21.2→26.0, counter 22.9→28.7, declared per-series 12.2→14.9. The doc table was updated to match.
  • Complexity: unchanged.
  • Assumptions and limits: a deployment's measured memory_bytes_per_state still replaces this estimate.

Decisions and open questions

Needs reviewer decision

None.

Decided

Verification

Run on the head commit, rebased onto main a51c623:

scope result notes
cargo fmt --all --check pass
cargo clippy --workspace --all-targets --all-features --locked -D warnings pass
cargo test --workspace --locked (CI's runner) 2153 passed, 0 failed, 17 ignored includes the stage0 goldens (14)
cargo test --release -p asap-planner-cli --test corpus_snapshots -- --ignored 3 passed corpus goldens unchanged; sketch plan snapshots regenerated (below)
node --test tools/dag-viewer/stages.test.mjs tools/dag-viewer/memo.test.mjs 36 passed
asap_sketchlib pin 01f3333, cargo test --all-features views 9, ddsketch lib 45, analytics 156 passed (full suite 1418 passed at the earlier pin e074547) tests/views.rs layout offsets updated for the 64-byte header

After #1536 (view state key and plan id). Two IDs hash the SketchAlgorithm names, so they change for the KLL views in three snapshots: a MaterializedView's definition_id and the plan_id built from it. These are chains-10m-5m-3m-10s-mvp, sql-rollup-quantile-same-window-raw-retained and sql-rollup-quantile-different-windows-raw-retained; all three were regenerated with UPDATE_SNAPSHOTS=1. The test view_state_key::the_view_state_key_of_a_planned_chain_is_pinned_and_round_trips_through_json pins the 5-minute KLL chain's definition_id, which goes from bfbffb8f01ab202d585c3e18c9f78080 to 2d963bc6757b98ad80934456821cc040. materialized_views::PINNED_PLAN_ID (a Sum plan) is unchanged.

New test: stored_ddsketch_header_is_the_librarys_view_header checks that a one-row DDSketch state is priced at exactly the library's view bytes plus its 4-byte column offset.

Changed tests:

  • dd_sketch::tests::quantile_interpolates_between_adjacent_order_statistics: q = 0 and q = 1 are now checked within α instead of exactly.
  • Name strings in assertions: "accepted rank (KLL)", ["KMV"], "CountMinSketch", Sketch(KLL).

Sketch plan snapshot diffs (selected DAGs identical in every file; the check compares structure after normalizing names, costs and definition_id):

snapshot selected cost/s before → after what changed
quantile-single-mvp 8.00796836235e-7 → 7.90576578141e-7 (−1.28%) DDSketch bytes
quantile-grouped-mvp 8.76149650182e-7 → 8.65929392088e-7 (−1.17%) DDSketch bytes
random-mixed-seed-862-long-w01-q3-mvp 2.01369403744e-5 → 2.00517569418e-5 (−0.42%) DDSketch bytes
nested-windows-15m-1h-mvp 5.73348028975e-6 → 5.71305047031e-6 (−0.36%) DDSketch bytes
shared-quantiles-1h-mvp 5.70215396377e-6 → 5.68172490806e-6 (−0.36%) DDSketch bytes
ratio-of-quantiles-1h-mvp 6.2464250683e-6 → 6.22599601259e-6 (−0.33%) DDSketch bytes
random-mixed-seed-862-w01-q3-q8-mvp 3.01080959229e-5 → 3.00795223309e-5 (−0.09%) DDSketch bytes
random-mixed-seed-862-w02-q2-q7-mvp 3.03721390498e-5 → 3.03435654579e-5 (−0.09%) DDSketch bytes
chains-10m-5m-3m-10s-mvp unchanged KLL name, definition_id, plan_id
sql-rollup-quantile-same-window-raw-retained unchanged KLL name, definition_id, plan_id
sql-rollup-quantile-different-windows-raw-retained unchanged KLL name, definition_id, plan_id
quantile-over-time-phase-0-raw-retained unchanged KLL name
mixed-quantiles-raw-retained unchanged KLL name
distinct-over-time-5pct-raw-retained unchanged KMV name
distinct-two-forms-raw-retained unchanged KMV name
entropy-and-distinct-raw-retained unchanged KMV name

Corpus goldens (corpus_snapshots/): no diff.

Follow-ups

…views)

Pins planner-pin/main-a05b35c-shrink-to-fit (01f3333): sketchlib main
a05b35c with the open KLL and DDSketch shrink_to_fit PRs (#267, #270) and
#271's zero-copy views ported to main's DDSketch (no sum/min/max).

- SketchAlgorithm variants take sketchlib's full names (KLL, HLL, KMV,
  CountMinSketch, HydraCountMinSketch, ...) across crates, fixtures,
  snapshots, docs and the DAG viewer; the planner's own SketchParams names
  (Kll { k }, ...) stay.
- The plan file writes those names, so INSTALLABLE_PLAN_WIRE_VERSION 15 -> 16.
- estimated_memory_bytes -> theoretical_memory_bytes.
- DDSketch's view header shrank 88 -> 64 B: the stored-state price follows
  (new test pins it to the library's view bytes), and the value-shape bands
  are recalibrated. Sketch plan snapshots: same plans, DDSketch plans cost
  0.09-1.28% less.
- DDSketch q = 0 / q = 1 read bucket representatives (within alpha), no
  longer the exact min / max; the executor test checks within alpha.
@zzylol
zzylol force-pushed the chore/bump-sketchlib-latest branch from 33b2b6d to 9b7bab4 Compare November 27, 2026 20:30
@zzylol
zzylol merged commit f17bd99 into main Nov 27, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cost-model Cost formulas, statistics, ranking, and selection refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant