Repository navigation
fix(cost): a query-time scan selects series only by its predicates on the declared series key - #1570
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Scanis 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_v2SB_q3(count(DISTINCT user) … WHERE src IN $SB_A, over 1 h oflogin_fail). The deployment keyslogin_fail's series byuser. The plan prices the scan at 31 ms per step (IN-list selectivity onsrc). Measured on the data plane, it takes 8–12 s per round at x4 and x10.CostInputsgainsseries_key_columns, an optional per-table set of the columns that identify a series in the deployment's store.Scanselects series (and their rows) only by its predicates on those columns.intent_fullreplanned equals the build-4 plan. With the input from the intents layouts (login_failkeyed byuser),SB_q3keeps state. It uses a 10 s KMV chain by(src, target)with merged windows, the boundsrc INfilter below the time merge, then the merge totarget. 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
eval/2026-12-planner709f1ef (eval build 4).crates/cost/src/node/usage/mod.rs, at theScanarm that computesselected_by_predicate, then the rows-read block (readvsselected_rows), thenseries_visitedand the measuredunits. 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.rsadds the field only.Behavior: before → after
host IN (10 of 10,000), no input (today)authkeyed byuserauthkeyed byhostuser IN (10 of 100,000) AND host IN (10), keyed byuser(10 min of
auth: 100,000 series, 6,000,000 rows; unit tests K1–K4.)Interfaces
crates/cost/src/model.rspub 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 withasap_planner --cost-inputs(ornet_plan --cost-inputs). Stage 3 prices each candidate node withnode_usage_and_cost_terms. A query-timeScanoflogin_failundersrc IN $SB_Areads every row of its window (no key predicate) and keeps|$SB_A|/Nof them. The rawSB_q3plan 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 samelayouts.jsonit passes to the data plane (--table-layouts), so the two cannot diverge.Tests
asap-costlib: 175 passed (K1–K5 new; K1 and K3 failed before the fix, commit 1d46316).net_planbuilt on this branch,--cost-inputs cost-c6320.json. Without keys, suite_v2.c10r10h2intent_fullis identical to the build-4 plan. With keys, the plans are described above.Open question
login_faillayout keyed bysrc, whichSB_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