Skip to content

fix(cost): a query-time scan selects series only by its predicates on the declared series key - #1570

Merged
zzylol merged 2 commits into
eval/2026-12-plannerfrom
perf/x10-rounds
Dec 4, 2026
Merged

zzylol merged 2 commits into
eval/2026-12-plannerfrom
perf/x10-rounds

Conversation

@zzylol

@zzylol zzylol commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Problem. A query-time Scan is priced as if every predicate selected series. When the deployment keys a table's series by other columns, the scan cannot select by the predicate, so it reads every row of its window and then filters. Example: suite_v2 SB_q3 (count(DISTINCT user) … WHERE src IN $SB_A, over 1 h of login_fail). The deployment keys login_fail's series by user. The plan prices the scan at 31 ms per step (IN-list selectivity on src). Measured on the data plane, it takes 8–12 s per round at x4 and x10.
  • Change. CostInputs gains series_key_columns, an optional per-table set of the columns that identify a series in the deployment's store.
    • For a listed table, a query-time Scan selects series (and their rows) only by its predicates on those columns.
    • It evaluates the other predicates on every row it reads (filter terms per row read).
    • It passes on the rows that all predicates keep. The series visited follow the key predicates.
    • Absent input, or a table the input does not list, keeps today's rule.
  • Effect. Without the input, plans are byte-identical: suite_v2 c10 intent_full replanned equals the build-4 plan. With the input from the intents layouts (login_fail keyed by user), SB_q3 keeps state. It uses a 10 s KMV chain by (src, target) with merged windows, the bound src IN filter below the time merge, then the merge to target. The predicted cost goes up: SB x4 481 → 8,277 /s, suite_v2 x10 10,723 → 30,214 /s, average memory 17.5 → 121 GB (the KMV chain and its merged windows). The old price was wrong, so the higher cost is the correct one. Whether to deploy the keyed plan is an eval decision (see Open question).

Review guide

  • Base: eval/2026-12-planner 709f1ef (eval build 4).
  • Read first: crates/cost/src/node/usage/mod.rs, at the Scan arm that computes selected_by_predicate, then the rows-read block (read vs selected_rows), then series_visited and the measured units. Each conjunct is classified as key or not, and an ingestion-time scan is unchanged (its measured units still count the rows it passes on).
  • crates/cost/src/model.rs adds the field only.

Behavior: before → after

case rows read series visited rows out
host IN (10 of 10,000), no input (today) 6,000 100 6,000
same, auth keyed by user 6,000,000 100,000 6,000
same, auth keyed by host 6,000 100 6,000
user IN (10 of 100,000) AND host IN (10), keyed by user 600 10 1

(10 min of auth: 100,000 series, 6,000,000 rows; unit tests K1–K4.)

Interfaces

crates/cost/src/model.rs

 pub struct CostInputs {
     pub cost_model: CostModel,
     pub resource_speed: ResourceSpeed,
     pub non_repeating_query_horizon_seconds: f64,
     pub measured_operation_costs: MeasuredOperationCosts,
     pub frozen_calibration_factor: Option<f64>,
     pub data_plane_execution: DataPlaneExecution,
     pub latency_calibration: LatencyCalibration,
     pub latency_selection: LatencySelection,
     pub latency_selection_checks: LatencySelectionChecks,
+    /// Per table, the columns that identify a series in the deployment's
+    /// store (its series key): a query-time scan selects series only by
+    /// predicates on these columns, and evaluates any other predicate on
+    /// every row of the window it reads. A table not listed, and every
+    /// table when `None` (default), selects series by any label column.
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub series_key_columns: Option<BTreeMap<String, BTreeSet<String>>>,
 }

Usage (end to end): a cost inputs file {"measured_operation_costs": …, "series_key_columns": {"login_fail": ["user"]}} is passed with asap_planner --cost-inputs (or net_plan --cost-inputs). Stage 3 prices each candidate node with node_usage_and_cost_terms. A query-time Scan of login_fail under src IN $SB_A reads every row of its window (no key predicate) and keeps |$SB_A|/N of them. The raw SB_q3 plan therefore costs a full 1 h scan per evaluation, and the selection picks the kept KMV chain. The eval tooling writes the file from the same layouts.json it passes to the data plane (--table-layouts), so the two cannot diverge.

Tests

  • asap-cost lib: 175 passed (K1–K5 new; K1 and K3 failed before the fix, commit 1d46316).
  • Replans with net_plan built on this branch, --cost-inputs cost-c6320.json. Without keys, suite_v2.c10r10h2 intent_full is identical to the build-4 plan. With keys, the plans are described above.

Open question

  • The keyed plan holds ~108 GB of KMV state at x10 (predicted). The alternatives are to keep the raw plan with a login_fail layout keyed by src, which SB_q2 (user IN $SB_U) would then lose, or to accept the state. This needs an eval decision before the keyed plans are used.

🤖 Generated with Claude Code

zzylol and others added 2 commits December 4, 2026 17:39
CostInputs gains series_key_columns (per table, the columns that identify a
series in the deployment's store; None keeps today's rule). Tests K1-K5: a
predicate off the series key reads every row of the window and every
series (K1), on the key it selects series (K2), only the key conjuncts
select (K3), an unlisted table keeps today's rule (K4), and the input loads
from a cost inputs file (K5). K1 and K3 fail: the scan is priced as if
every predicate selected series.

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

With CostInputs::series_key_columns declaring a source's series key, a
query-time Scan reads the rows of the series its predicates on key columns
select, evaluates the other predicates on each of them (filter terms per
row read), and passes on the rows all predicates keep; series visited
follow the key predicates. Without the input, or for a table it does not
list, nothing changes (every label column selects series).

Why: SB_q3 (count distinct user by target where src IN $SB_A, 1 h) was
priced at 31 ms per step as if src selected series, but the deployment
keys login_fail's series by user, so the scan reads every row of the hour
(8-12 s per round at x4/x10).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zzylol zzylol added enhancement New feature or request cost-model Cost formulas, statistics, ranking, and selection labels Dec 4, 2026
@zzylol
zzylol merged commit fa22fa2 into eval/2026-12-planner Dec 4, 2026
2 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 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant