Skip to content

feat(data_plane): raw reads return only the series a Scan's label predicates select - #902

Draft
zzylol wants to merge 3 commits into
feat/intent-trigger-ratefrom
feat/raw-read-label-pushdown
Draft

zzylol wants to merge 3 commits into
feat/intent-trigger-ratefrom
feat/raw-read-label-pushdown

Conversation

@zzylol

@zzylol zzylol commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: a raw read used only the time range and ignored the Scan's predicates. In E6 drill_cnt x1, q2 (... FROM auth WHERE host IN $Y ... GROUP BY user) converted all 6.0 M rows of auth every round, only for the executor to keep the 10 bound hosts' rows: 1.69 s and 1.69 core-s per round.
  • Change: the store recognizes label predicates among the Scan's predicates (label = 'v', label IN (...), and an OR of = on one label) and returns only the rows of the series they select. The executor still applies every predicate, so answers do not change.
  • Effect (same seeded feed, 18 rounds, pushdown off vs on): q2's p50 latency drops from 1688.7 ms to 287.4 ms, and query CPU from 30.4 to 5.2 core-s. The read returns 1.76 M of 6.0 M rows (3.4x fewer). All 36 (round, query) answers are identical.

Review guide

Behavior: before → after

The user writes (E6 drill_cnt.x1, auth = 10,000 rows/s over 10,000 Zipf-1.0 hosts × 10 users, stored as series {__name__=auth, host, user}):

INTENT drill_cnt EVERY 10s;
q1: ($Y, _) := SELECT host, count(*) AS c FROM flows WHERE ts > $now - INTERVAL '1 hour'
               GROUP BY host ORDER BY c DESC LIMIT 10 REQUIRE ERROR rel <= 0.05 DELTA 0.05, LATENCY <= 1000ms;
q2: SELECT user, count(*) AS c FROM auth WHERE host IN $Y AND ts > $now - INTERVAL '10 minutes'
    GROUP BY user REQUIRE ERROR rel <= 0.05 DELTA 0.05, LATENCY <= 1000ms;
GROUP (q1, q2) LATENCY <= 2000ms;

Planned query at a time (cost 177.9/s), q2 scans auth at query time with the bound predicate host IN ('h17', ..) in its Scan.

per round, q2 before (--no-label-pushdown) after (default)
raw rows read in the time range 6.0 M 6.0 M (row codes walked; nothing else touched)
raw rows converted and returned to the executor 6.0 M 1.76 M (the 10 bound hosts' rows, ~29% under Zipf)
latency p50 / max 1688.7 / 1731.2 ms 287.4 / 329.4 ms
query CPU 1.69 core-s 0.29 core-s
answer 100 users the same 100 users and counts

This serves the design intent in ASAPPlanner docs/design_docs/physical-planning-and-deployment.md: filter pushdown is a hint the store may use, and the executor always re-filters. It also serves the E6/E7 latency goal: q2's LATENCY <= 1000ms is now met (it was missed before).

Interfaces

data_plane/src/label_selection.rs (new)

+/// The values each restricted label may take; a series is selected when
+/// every restricted label holds one of its values.
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct LabelSelection {
+    values_by_label: BTreeMap<String, BTreeSet<String>>,
+}
+impl LabelSelection {
+    /// The selection `predicates` (over `schema`) imply; `None` when no
+    /// conjunct is recognized (every series is read).
+    pub fn from_predicates(schema: &Schema, predicates: &[ScalarExpr<()>]) -> Option<Self>;
+    /// Whether `series` holds one of the values of every restricted label.
+    pub fn holds(&self, series: &Series) -> bool;
+}

data_plane/src/store.rs

+/// Rows of the raw reads of some runs (the query runs: `/metrics`):
+/// how many were in the reads' time ranges, and how many the reads
+/// returned after label predicate pushdown.
+#[derive(Debug, Default)]
+pub struct RawReadCounts {
+    pub reads: AtomicU64,
+    pub rows_in_time_range: AtomicU64,
+    pub rows_returned: AtomicU64,
+}
 impl RunStore {
+    /// The run reads every series, whatever the `Scan`'s label predicates
+    /// (for comparison).
+    pub fn without_label_pushdown(mut self) -> Self;
+    /// The run counts its raw reads' rows in `counts`.
+    pub fn with_raw_read_counts(mut self, counts: Arc<RawReadCounts>) -> Self;
 }
 impl RawData {
-    pub(crate) fn read(&self, metric: &str, request: &RawDataRequest, reads: Option<&RawReads>, partition: Option<&PartitionReads>) -> Result<Vec<Batch>, Error>;
+    pub(crate) fn read(&self, metric: &str, request: &RawDataRequest, reads: Option<&RawReads>, partition: Option<&PartitionReads>) -> Result<RawRead, Error>;
 }
+/// One raw read's batches, and the rows of the read's series in its time
+/// range before the `Scan`'s label predicates selected some.
+pub(crate) struct RawRead {
+    pub batches: Vec<Batch>,
+    pub rows_in_time_range: u64,
+}

data_plane/src/query.rs, data_plane/src/engine.rs, data_plane/src/metrics.rs, data_plane/src/main.rs

 impl QueryEngine {
+    /// Raw reads select series by the `Scan`'s label predicates when
+    /// `label_pushdown`, and count their rows in `counts`.
+    pub fn with_raw_reads(mut self, label_pushdown: bool, counts: Arc<RawReadCounts>) -> Self;
 }
 pub struct EngineOptions {
+    /// Raw reads return only the series a `Scan`'s label predicates select;
+    /// `false` reads every series in the time range (for comparison). Default true.
+    pub label_pushdown: bool,
 }
 pub struct Metrics {
+    /// Rows of the query runs' raw reads: in their time ranges, and returned.
+    pub query_raw_reads: Arc<RawReadCounts>,
 }
+    /// The same counts for the ingestion runs' raw reads.
+    pub ingestion_raw_reads: Arc<RawReadCounts>,
+// ingestion.rs
+impl Precompute {
+    /// The ingestion runs' raw reads select series by label predicates when
+    /// `label_pushdown`, and count their rows in `counts`.
+    pub fn with_raw_reads(mut self, label_pushdown: bool, counts: Arc<RawReadCounts>) -> Self;
+}
+// CLI: --no-label-pushdown   (EngineOptions::label_pushdown = false; query AND ingestion runs)
+// /metrics: asap_query_raw_reads_total, asap_query_raw_read_rows_in_time_range_total,
+//           asap_query_raw_read_rows_returned_total, and the same three with asap_ingestion_ (counters)

Usage (end to end, as the E6 A/B ran it; tests/intent_sil_modes.rs::label_pushdown_reads_the_bound_series_only_and_answers_the_same checks the same flow in-process):

# The planned intent (query at a time) for drill_cnt x1: q2's Scan of `auth` carries host IN ('__sil_Y_0', ..).
e6_plan --sil intent.sil --tables tables.json --data data.json --mode query_at_a_time --out intent_plan.json
# Each round, the intent loop binds $Y to q1's 10 hosts (placeholders::bind) and runs q2's bound plan.
# Its Scan calls RunStore::read_raw_data with predicates [host IN ('h17', ..)]:
#   LabelSelection::from_predicates -> {host: {h17, ..}}; per chunk, Chunk::select keeps those series' rows.
data_plane --plan plan.json --intent intent_plan.json --intent-name drill_cnt --no-forward ...   # pushdown on (default)
data_plane ... --no-label-pushdown                                                            # comparison arm
curl -s localhost:19802/metrics | grep asap_query_raw_read
# asap_query_raw_read_rows_in_time_range_total 108000000   (18 rounds x 6.0 M)
# asap_query_raw_read_rows_returned_total 31673197         (18 rounds x 1.76 M; off: 108000000)

Algorithm changes

Raw read series selection (RawData::read, Chunk::select, SeriesVerdicts, RawReads::get_or_select)

  • Problem: q2 above: 6.0 M rows converted per round, of which 1.76 M are kept.
  • Before:
    1. For each chunk of the panes overlapping the range: cut it to the time range.
    2. Cut it to the run's series partition, if any.
    3. Convert it, through the shared cache when it is whole.
  • After:
    1. LabelSelection::from_predicates:
      • Flatten the predicates' BoolAnds.
      • For each conjunct on a label column with Utf8 literals (=, IN, or an OR of these on one label), collect label → values. Conjuncts on the same label intersect.
      • Ignore everything else.
    2. Per chunk, as before through step 2. Then Chunk::select:
      • Ask SeriesVerdicts::keeps once per distinct series of the chunk. It holds one byte per dense series id, so each series is judged once per read.
      • If no series is kept: skip the chunk without touching rows.
      • If all are kept: use the chunk and its whole conversion.
      • Otherwise: one pass over the row codes copies the kept rows.
    3. A whole stored chunk's selected cut is cached in RawReads under (chunk, schema, selection), separate from whole conversions, so a range request's steps cut and convert it once. A chunk with no kept series is cached as None.
    • Without a recognized predicate, or with --no-label-pushdown, the path is the old one.
  • Correctness: the store returns a superset of the rows the executor keeps, because the executor re-applies every predicate and the store drops only rows of series failing a conjunct of the predicates. A conjunct allowing '' is ignored, because a series lacking the label reads as ''. Tests:
    • label_selection::tests (6): recognition and negative forms.
    • store::tests (5): selected rows equal the row-wise read filtered; skipping; cache separation; composition with the series partition; unrecognized predicates.
    • E2E: answers identical with and without pushdown in all three planning modes. Off: rows returned = rows in range. On: rows in range = 4 × rows returned (one host of four).
    • Measured: 36/36 identical answers on E6.
  • Complexity:
    • Before: O(rows in range) conversion, plus executor filtering of all of them.
    • After: O(series per chunk) verdict lookups, plus O(rows in range) u32 code walk for chunks partly selected, plus O(selected rows) conversion and filtering.
    • Memory: one byte per series id per read; selected conversions in the per-request cache.
    • Measured: q2 1.69 → 0.29 core-s/round.
  • Assumptions and limits:
    • Only equality, IN, and OR-of-equality on labels.
    • !=, regex and ranges are left to the executor.
    • Rows stay in arrival order, so the code walk over a partly selected chunk remains. A series-sorted chunk layout is a follow-up.
    • Push-mode morsels (push.rs) read without predicates.

Decisions and open questions

Needs reviewer decision: None.

Decided (2026-12-03, user):

  • Per-chunk check instead of a global label → series-id index. Rows are in arrival order, so a selected read walks each chunk's series and codes whichever way the series are found. An index costs memory per series × label, kept forever.
  • Cache selected cuts per (chunk, schema, selection).
  • Ignore conjuncts allowing ''.
  • Count rows in totals over query runs.
  • Keep the --no-label-pushdown switch.
  • Rejected for today: sorting sealed chunks by series id, as VictoriaMetrics and ClickHouse sort parts by key. It would make selected rows contiguous and remove the code walk, at O(n log n) per pane at seal.

Verification

Run on clnode009 (c8220, 40 threads).

Scope Result Newly failing vs base Notes
cargo test -p data_plane --lib 109 passed 0 +11 tests (6 label_selection, 5 store)
cargo test -p data_plane (all integration tests) 150 passed, 1 failed 0 the failure: planner_executor_parity::push_precompute_answers_what_the_planner_executor_answers, "Too many open files" at the host's soft ulimit -n 1024
planner_executor_parity rerun with ulimit -n 65536 6 passed (1343 s) 0 environment, not code
tests/label_pushdown_ingestion.rs (review I1) 1 passed 0 a view built at ingestion from data{job="a"} (1 job of 4): pushdown on returns 1/4 of the ingestion rows in range, off returns all; answers identical
Full cargo test -p data_plane after rebase onto #901 fb773b8 (ee2ac16, ulimit -n 65536) 225 passed, 0 failed 0
tests/intent_sil_modes.rs 3 passed 0 new: label_pushdown_reads_the_bound_series_only_and_answers_the_same
cargo clippy -p data_plane --lib --tests --bins -- -D warnings, cargo fmt --check clean

E2E evidence: E6 drill_cnt x1, query-at-a-time plan.

  • Two data planes ran at once on disjoint cores (3 cores + siblings each), fed by the same seeded e6_feed (c8220-v1 scenario).
  • 660 s warm-up, then 18 rounds every 10 s.
pushdown off pushdown on
q2 latency p50 / mean / max (ms) 1688.7 / 1690.4 / 1731.2 287.4 / 289.8 / 329.4
q2 query CPU over 18 rounds (core-s) 30.42 5.21
q1 latency p50 (ms) 17.7 17.0
raw rows in time range / returned 108.0 M / 108.0 M 108.0 M / 31.7 M
peak RSS 418 MB 383 MB
identical answers (round, query) 36 / 36

Follow-ups

  • A series-sorted chunk layout at seal, with per-series row ranges: removes the 6 M-code walk for partly selected chunks.
  • Push-mode reads with predicates.
  • != and regex matchers via a verdict per series: same mechanism, with a different holds.
  • (Done after review I1, 12-04: ingestion runs follow --no-label-pushdown and are counted as asap_ingestion_raw_read_*.)

🤖 Generated with Claude Code

@zzylol zzylol added enhancement New feature or request area: data plane Runtime ingestion, storage, and query-serving data paths feature: workload optimization Cross-query sharing, costing, placement, and physical configuration selection labels Dec 3, 2026
zzylol and others added 2 commits December 3, 2026 19:30
Tests for selecting series by a Scan's label predicates (label = 'v',
IN, OR of = on one label) in raw reads: recognition and its negative
cases, the label index, per-chunk selection and skipping, shared
conversions kept apart by selection, series partition composition, and
an end-to-end intent round answering the same with and without pushdown
while reading only the bound host's rows. Stubs keep today's behaviour;
RawData::read returns RawRead with rows in the time range.

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

A raw read recognizes, among its Scan's predicates, label = 'v', label IN
(...) and an OR of = on one label, on label columns (a SQL table's text
columns, a metric's labels), and returns only the rows of the series
they select; everything else is still applied by the executor, so the
answers do not change. Per read, each series is judged once (a verdict
by dense series id); per chunk, its distinct series are checked, a chunk
with none selected is skipped without touching its rows, and the
selected rows are copied in one pass (Chunk::select, which
Chunk::in_partition now uses). A selected cut of a stored chunk is
converted once per range request and selection, apart from the whole
chunk's conversion.

/metrics counts the query runs' raw reads, their rows in the time range
and the rows returned (asap_query_raw_read_*_total). --no-label-pushdown
(EngineOptions::label_pushdown) reads every series, for comparison.
No global label index: the per-chunk check walks each chunk's series
list either way (rows are in arrival order).

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

The pushdown switch (EngineOptions::label_pushdown) covered query runs
only: ingestion runs built RunStore::for_partition, which always pushed
down, so a 'pushdown off' arm still pushed down at ingestion. Precompute
now carries the switch and passes it to each ingestion run's store, and
counts their raw reads apart (asap_ingestion_raw_read_*_total beside
asap_query_raw_read_*_total).

Test: label_pushdown_ingestion builds a view at ingestion from
data{job="a"} (one job of four): with pushdown the ingestion runs return
a quarter of the rows in their time ranges, without it every row, and
the answers are the same.

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

area: data plane Runtime ingestion, storage, and query-serving data paths enhancement New feature or request feature: workload optimization Cross-query sharing, costing, placement, and physical configuration selection

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant