Skip to content

system-bench: read ASAPPlanner plan wire 16 (Counter readouts, ClickHouse time-range covers); plan-suite on 3ef265d - #294

Draft
zzylol wants to merge 5 commits into
mainfrom
feat/planner-wire-v16
Draft

zzylol wants to merge 5 commits into
mainfrom
feat/planner-wire-v16

Conversation

@zzylol

@zzylol zzylol commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Problem: ASAPPlanner main (fae63521 and later, here 3ef265d) writes plan wire version 16, and it rejects the capability files (unknown variant Rate). It also plans with one Counter state for rate and increase (#1439), and reads long ranges with multi-level window chains (#1440). The ClickHouse and VictoriaMetrics translators here read only wire 15, so no plan of the current planner runs on either engine.
  • Change: the plan decoder reads wire 16 (counter_readout, SummaryMergeWindows, TimeRangeCover). Both translators read a counter's readout. ClickHouse translates a time-range cover: one table and view per chain level, read over the windows the planner's cover_windows picks. Capability files use {"exact": "Counter"}, and the VictoriaMetrics files exclude covers. Fixtures are replanned at 3ef265d, and plan-suite.sh runs on the new planner.
  • Effect: max_over_time(latency[1h]) every 60 s with clickhouse.equivalent-only: before, the plan file was refused (plan file wire version Some(16); this reader supports 15). After, it runs as 60 s / 300 s / 900 s tables. A cover read at t = 3,660 s takes 3 windows of 900 s, 2 of 300 s and 5 of 60 s (10 rows per series) instead of 60. The answers equal the single-level read, checked at 8 evaluation times.

Review guide

  • Base: main (e4a9111). Not stacked.
  • Read first: system-bench/src/engines_external/clickhouse.rs: Translator::finalized, stored_read, stored_chain, cover_window_condition, counter_readout. Then plan_file.rs, and the counter path in victoriametrics.rs.
  • Needs careful review: cover_window_condition (the SQL form of cover_windows), and the counter cover, which joins segments across level tables.
  • Mechanical: the regenerated fixtures under system-bench/tests/fixtures/plans/ (written by scripts/regenerate-plan-fixtures.sh at 3ef265d), the regenerated VictoriaMetrics snapshot tests/golden/victoriametrics/public_plans.txt, and test node-index updates.
  • Commits: tests and fixtures first (they fail on their own: no wire-16 decoder yet), then the implementation, then plan-suite.sh, then two preflight-test commits.

Behavior: before → after

The user writes a suite workload, plans it with the current planner, and runs ClickHouse on the plans. This is the eval campaign's showcase-1h suite:

ASAP_PLANNER=<ASAPPlanner 3ef265d>/target/release/asap_planner \
  scripts/plan-suite.sh suites/showcase-1h /data/run-1h
approxbench benchmark-external run --run-directory /data/run-1h --engine clickhouse \
  --variant clickhouse.equivalent-only --variant clickhouse.with-substitutes ...
before (main e4a9111) after
plan-suite.sh asap_planner: unknown argument --executor-check for every variant, and with the flag removed, unknown variant Rate for every capability file all 48 (workload, variant) plans of showcase-1m and showcase-1h written. VictoriaMetrics equivalent-only plans no sum_rate and no joint: the file rules out every counter function, as before
ClickHouse max 1h refused: wire 16 three tables v1 (60 s), v2 (300 s), v3 (900 s), each with a view from the source, and one query over their cover windows
ClickHouse sum_rate 1h, with substitutes refused a Counter chain and a 300 s level, read as one segment-joined rate (the deltaSumTimestamp substitution as before)
VictoriaMetrics max 1h refused one 60 s stream output: the planner no longer offers a cover, because both VictoriaMetrics files exclude it

This serves the eval campaign, which runs every planner consumer on the latest planner.

Interfaces

system-bench/src/engines_external/plan_file.rs

 /// The `InstallablePlan` wire version this decoder reads.
-pub const SUPPORTED_PLAN_WIRE_VERSION: u32 = 15;
+pub const SUPPORTED_PLAN_WIRE_VERSION: u32 = 16;

 /// The planner operators the translators read (stays).
 pub enum PlanOperator {
     Scan { source: Source, predicates: Vec<Predicate> },
     TimeRange { child: NodeId, kind: RangeKind, range_ms: u64 },
+    /// The windows of `levels` (widest first) that tile `(t − offset_ms − range_ms, t − offset_ms]`
+    /// (the planner's `cover_windows`); wire `offset_ms` absent means 0.
+    TimeRangeCover { levels: Vec<NodeId>, range_ms: u64, offset_ms: u64 },
     SummaryTumblingWindowChain { child: NodeId, family: SummaryFamily, width_ms: u64, reduction: Reduction, input: Value, filter: Option<Value> },
+    /// One level of a multi-level chain: `child`'s windows merged into windows of `width_ms`.
+    SummaryMergeWindows { child: NodeId, width_ms: u64 },
     SummaryAgg { child: NodeId, family: SummaryFamily, reduction: Reduction, input: Value, filter: Option<Value> },
     SummaryMerge { children: Vec<NodeId>, group_by: Option<Vec<usize>> },
-    FinalizeExactAccumulator { child: NodeId },
+    /// `counter_readout`: for a `Counter` state, `rate` or `increase`; `None` for any other state.
+    FinalizeExactAccumulator { child: NodeId, counter_readout: Option<CounterReadout> },
     SummaryEstimate { summary_input: NodeId },
     Aggregate { child: NodeId, measures: Vec<Measure>, reduction: Reduction, measure_filters: Vec<Option<Value>>, having: Option<Value> },
     Project { child: NodeId, expressions: Vec<Value> },
     BinaryOp { lhs: NodeId, rhs: NodeId, operator: Value, return_bool: bool },
     Other { kind: String },
 }

+/// What a finalize reads from a `Counter` state (ASAPPlanner `CounterReadout`); an unknown name is a malformed plan.
+pub enum CounterReadout {
+    Rate,
+    Increase,
+}

Capability files (system-bench/capabilities/), read by ASAPPlanner 3ef265d:

 // clickhouse.equivalent-only.json, victoriametrics.with-substitutes.json
 "state_not_mergeable_across_windows": [
-  {"exact": "Rate"},
-  {"exact": "Increase"}
+  {"exact": "Counter"}
 ],
 // victoriametrics.equivalent-only.json, victoriametrics.with-substitutes.json
 "excluded_candidates": [
+  {"operator": "TimeRangeCover"}
 ]

Scripts (scripts/plan-suite.sh, scripts/regenerate-plan-fixtures.sh):

 # plan-suite.sh <suite-dir> <run-dir>; ASAP_PLANNER=<asap_planner>
-asap_planner ... --executor-check skip|compile
+asap_planner ...                      # 3ef265d compiles every plan itself
+ONLY_VARIANTS="<variant> ..."         # optional: plan only these variants
+# variants: + victoriametrics.equivalent-only, + victoriametrics.with-substitutes
+# each planner log ends with `planner_wall_s <s> peak_rss_kb <kB>`
+# ASAP_PLANNER=<asap_planner> scripts/regenerate-plan-fixtures.sh: replans every named and public fixture

Removed: --executor-check, because asap_planner no longer has the flag. The Rate / Increase names were removed because the planner refuses them.

Usage (checked at this head on a ClickHouse 26.8.39.19 server; the run is the reduced smoke under Verification):

# The suite: showcase-1h `max` (max_over_time(latency[1h]) every 60 s), `sum_rate`, `joint`.
ASAP_PLANNER=$P16 ONLY_VARIANTS="clickhouse.equivalent-only clickhouse.with-substitutes asap.exact" \
  scripts/plan-suite.sh $SUITE $RUN
#   max clickhouse.equivalent-only: plan         -> plans/clickhouse.equivalent-only/max.plan.json (wire 16)
# benchmark-external reads each plan with PlanFile::from_json, then clickhouse::translate:
#   chain 60 s (node 1) -> SummaryMergeWindows 300 s (node 2) -> 900 s (node 3) -> TimeRangeCover [3, 2, 1]
#   -> tables v1, v2, v3 with views, and one query whose step is 60 s
approxbench benchmark-external run --run-directory $RUN --engine clickhouse --variant clickhouse.equivalent-only ...
approxbench benchmark-external report --run-directory $RUN --truth clickhouse/clickhouse.equivalent-only
#   max      clickhouse.with-substitutes  ok  max_relative_error 0         points 176
#   sum_rate clickhouse.with-substitutes  ok  max_relative_error 3.5e-16   points 44   (counter cover vs query-time PromQL rate)

Algorithm changes

ClickHouse: reading a time-range cover

  • Problem: a 1 h range over 60 s windows now arrives as TimeRangeCover { levels: [900 s, 300 s, 60 s] }, and the old translator had no rule for it.
  • Before: one TimeRange over one chain: window_end_ms ∈ (t − R, t] of one table.
  • After (stored_read, cover_window_condition):
    1. Each level is a StoredChain: the base chain, or a SummaryMergeWindows level, which takes the base chain's state, labels and source with its own width and retention. Each level gets its own table v<node> and a view from the source over its width. Merging the narrower windows gives the same state.
    2. Level i takes the windows ending in (lo_i, hi_i], where lo_i = ⌈(t−R)/w_i⌉·w_i and hi_i = ⌊t/w_i⌋·w_i (positiveModulo), minus the wider level's (lo_{i−1}, hi_{i−1}]. The narrowest level's bounds are the range itself, and its throwIf checks that t is on its grid.
    3. The query reads the UNION ALL of the levels' rows: -Merge for Sum/Count/Min/Max, and the existing time-ordered segment join for a Counter.
  • Correctness: the spans nest (each width is a multiple of the next). A level with no whole window implies that every wider level has none too. So "this level's span minus the next wider span" is exactly what the planner's cover_into recursion selects, and the windows are disjoint and tile the range. Tests: cover_answers_as_its_narrowest_level compares the cover with the same plan read from its narrowest level only. It runs at 8 times (including t < R, t off the wider grids, and t after the data), on Sum, Max, Count and Counter rate with resets. Dropping the "minus wider span" clause makes it fail (13430400 vs 6715200). The golden test checks hand-computed answers at three times.
  • Complexity: stored rows read per series and evaluation drop from R/w_narrowest to between R/w_widest and R/w_widest + Σ 2·(w_i/w_{i+1} − 1): for 1 h over 900/300/60 s, between 4 and 16 rows instead of 60. Each level adds one table and one view written per insert. Translation is linear in the number of levels.
  • Assumptions and limits: a cover under a PromQL offset is refused. The levels must share the state, labels and source. VictoriaMetrics refuses covers: the window set depends on t, and one instant MetricsQL expression cannot express that.

Counter readout (both translators)

ExactKind::Counter replaces Rate and Increase. A FinalizeExactAccumulator's counter_readout picks the readout: ClickHouse divides by the range for rate, and VictoriaMetrics uses the rate(...) or increase(...) rollup. Two finalizes of one counter chain give two queries over one table (rate_and_increase_5m_stored). These are refused: a counter finalize without a readout, a readout on another state, and a counter state read without a finalize.

Decisions and open questions

Needs reviewer decision:

  • On ClickHouse, the showcase-1h asap.exact plans of sum_rate and joint keep a stored Counter chain, which carries the deltaSumTimestamp substitution. asap.exact allows no substitution, so the harness refuses these two cells: "variant asap.exact allows no substitutions, but the engine substituted". The other option is to run them as with-substitutes cells. This PR leaves the harness rule as it is.

Decided (2026-12-03):

  • ClickHouse translates covers faithfully, with one table per level. The rejected alternative was to read only the narrowest level, which would not run the planner's plan.
  • VictoriaMetrics excludes covers in its capability files, so the planner plans one level for it. The rejected alternative was a translator fallback, which would silently run a plan other than the planner's.
  • Some shapes are no longer planned for the engine files: query-time max_5m_label_filter, joint_5m, and the VictoriaMetrics query-time count. They are kept with test capability files (tests/fixtures/capabilities/: an engine file plus one exclusion), so the existing goldens still cover them.
  • The planeval feature stays pinned to ASAPPlanner b822553. 3ef265d needs asap_sketchlib 01f3333, and this workspace benchmarks a05b35c, so moving the pin also moves the measured sketch library. That belongs in its own PR.

Verification

Scope Result Notes
cargo test -p system-bench --tests all pass 0 newly failing; the ignored tests are below
cargo clippy -p system-bench --tests, cargo fmt --check clean
clickhouse_translate + clickhouse_run, --ignored (clickhouse local 26.8.39.19, githash ed6dc0f3) 12/12 pass includes public_translations_run: every public plan, covers included, runs
clickhouse_conformance --ignored against a ClickHouse 26.8.39.19 server 13/13 pass
victoriametrics_conformance --ignored against VictoriaMetrics v1.154.1 4/4 pass
VictoriaMetrics benchmark-external smoke (showcase-1m count, max, sum_rate, 16 series, 3 min) 5 cells ok, 1 no plan count (now a 10 s stream output) and max have error 0 against equivalent-only truth; sum_rate equivalent-only has no plan, as before
plan-suite.sh at 3ef265d, showcase-1m and showcase-1h, 6 variants 92 plans, 4 no-plan the no-plans are VictoriaMetrics equivalent-only sum_rate and joint (counter_resets_not_handled), as before
run_directory_plans_translate on those two run directories 1m: all translate. 1h: all translate 1h asap.exact sum_rate and joint carry a substitution (see Decisions)
ClickHouse benchmark-external smoke (showcase-1h max, sum_rate, joint, 16 series) 7 cells ok, 2 refused covers against PromQL-equivalent truth: max error 0 (max), 3.5e-16 (sum_rate, joint); the 2 refused are asap.exact with a substitution

New tests:

  • reads_a_multi_level_chain_and_its_cover, counter_readouts_decode: the wire-16 fields decode, and malformed ones are refused.
  • cover_worked_example (golden), a_counter_cover_reads_its_levels_as_segments, a_counter_finalize_reads_rate_or_increase, counter_readouts_must_fit_the_state, cover_refusals: ClickHouse cover and readout translation.
  • cover_answers_as_its_narrowest_level (ignored, clickhouse local): a cover's answers equal the single-level read, at 8 times and for 4 state kinds.
  • a_time_range_cover_is_refused: VictoriaMetrics refuses covers by name.
  • run_directory_plans_translate (ignored, AQPBM_RUN_DIR): a preflight that every plan in a run directory translates within its variant's substitutions_allowed.

Plan changes from 5400f93fd to 3ef265d in showcase-1m/1h: count 1m became a 10 s Count chain on all four files (it was a query-time count); the 1h ClickHouse plans of count, max, sum_over_time, joint and sum_rate (with substitutes) became covers. The VictoriaMetrics 1h shapes are unchanged. Planner wall time is at most 0.08 s per plan and peak RSS at most 36 MB.

Follow-ups

  • The full sweep of the 206 public workloads used to choose the public fixture cover was not rerun at 3ef265d. The same list was replanned, and the eight showcase-1h shapes were added.
  • planeval pin to 3ef265d together with an asap_sketchlib bump.
  • The ClickHouse cover is not written as a capability README row with a server conformance case. It is covered by clickhouse local tests and the benchmark smoke.

🤖 Generated with Claude Code

zzylol and others added 5 commits December 3, 2026 16:30
…overs) (fails)

Expectations and fixtures for reading the plans ASAPPlanner 3ef265d writes;
the translators still read only wire 15, so these fail until the next
commit.

- Fixtures replanned at 3ef265d by the new scripts/regenerate-plan-fixtures.sh
  (asap_planner --plan-file; the named list lives in the script). New:
  sum_over_time_1h_cover (a 60 s chain, a 300 s level, a time-range cover),
  sum_rate_1h_counter_cover, rate_and_increase_5m_stored (one Counter chain,
  two finalizes), and the eight showcase-1h shapes with all four capability
  files. Shapes the planner no longer picks are kept with test capability
  files (tests/fixtures/capabilities): one engine file plus one exclusion.
- Capability files: {"exact": "Counter"} for the old Rate and Increase
  (#1439); both VictoriaMetrics files exclude TimeRangeCover.
- plan_file: wire 16, counter_readout, SummaryMergeWindows, TimeRangeCover.
- ClickHouse: the cover golden and its hand-computed answers, cover answers
  equal to reading the narrowest level (Sum, Max, Count, Counter rate),
  rate and increase of one chain, readout and cover refusals.
- VictoriaMetrics: readout picks rate or increase; a cover is refused;
  snapshot of the public translations updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ClickHouse time-range covers

ASAPPlanner 3ef265d (main fae63521 and later) writes plan wire version 16
and plans with one Counter state for rate and increase (#1439) and with
multi-level window chains read by time-range covers (#1440).

- plan_file reads wire 16 only: FinalizeExactAccumulator.counter_readout,
  SummaryMergeWindows {child, width_ms}, TimeRangeCover {levels, range_ms,
  offset_ms}.
- Both translators: ExactKind::Counter replaces Rate and Increase; a
  finalize's readout picks rate or increase. A counter finalize without a
  readout, a readout on another state, and a counter state read without a
  finalize are refused.
- ClickHouse: each SummaryMergeWindows level is its own AggregatingMergeTree
  table and view over its wider windows, built from the source rows. A
  cover reads from each level the windows the planner's cover_windows
  takes: (ceil((t - R)/w)*w, floor(t/w)*w] less the wider level's span, as
  one UNION ALL; a counter cover joins the levels' rows as time-ordered
  segments like one chain. A cover under an offset is refused.
- VictoriaMetrics: a cover's windows depend on the evaluation time, which
  one instant MetricsQL expression cannot select, so it is refused (both
  capability files exclude it). A plan reading counters still gets the
  previous-arm gap (the Counter family).
- Capability README rows follow (Counter, the cover row, sketchlib names).

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

- --executor-check is gone from asap_planner (it compiles every plan on its
  executor itself), so the variant table drops its check column.
- The two VictoriaMetrics capability variants are planned too, and
  ONLY_VARIANTS picks a subset.
- Each planner log ends with the planner's wall time and peak RSS: planning
  is a one-time offline cost, reported apart from the data plane.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, AQPBM_RUN_DIR)

A preflight for a benchmark-external run planned with scripts/plan-suite.sh:
the ClickHouse and VictoriaMetrics capability variants translate with their
engine's translator and asap.exact with ClickHouse's; equivalent-only plans
carry no substitution; no-plan files are listed.

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

The harness refuses a cell whose engine substituted in a variant that allows
none (asap.exact as well as the equivalent-only files), so the preflight
reads variant.json instead of the variant name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zzylol zzylol added the enhancement New feature or request label Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant