From 1e45d46dee9b0cddfbb1937439b61989bbbe783c Mon Sep 17 00:00:00 2001 From: zzylol <50204836+zzylol@users.noreply.github.com> Date: Sun, 15 Nov 2026 08:55:24 +0000 Subject: [PATCH 1/4] fix(executor): build an unbound chain's windows for its readers, with sample times A plan run without its materialized views bound lost the rows of sum by (job)(rate(c[5m])) and sum by (job)(increase(c[5m])): - A tumbling-window chain placed at ingestion time and compiled for its readers (not a compile root, its view not bound) was built as in an ingestion run: only its newest window (T - 10s, T]. A counter has at most one sample there, so the finalize dropped every series. Such a chain now builds every window its readers read, as a query-time chain does, and its input is read through those windows. - A chain built for its readers replaced each sample's time with its window's end before the build, so a counter's rate and increase extrapolated from window ends instead of sample times (19.5 for 20). The range window now appends the window end as its own column and keeps the sample time. --- crates/executor/src/operators/mod.rs | 1 + crates/executor/src/operators/time_range.rs | 70 ++++++++++++------- crates/executor/src/physical_planner/mod.rs | 61 +++++++++------- .../src/physical_planner/time_window.rs | 27 +++++++ .../executor/tests/tumbling_window_chain.rs | 22 ++++-- 5 files changed, 124 insertions(+), 57 deletions(-) diff --git a/crates/executor/src/operators/mod.rs b/crates/executor/src/operators/mod.rs index f45e20ce6..557a2e6f2 100644 --- a/crates/executor/src/operators/mod.rs +++ b/crates/executor/src/operators/mod.rs @@ -38,6 +38,7 @@ pub use aggregate::Reduction; pub use series_window::SubquerySteps; pub use sort::SortKey; pub use summary::{RowWeight, SummaryEvaluation}; +pub use time_range::TUMBLING_WINDOW_END_COLUMN; #[derive(Clone, serde::Serialize, serde::Deserialize)] enum Kind { #[serde(skip)] diff --git a/crates/executor/src/operators/time_range.rs b/crates/executor/src/operators/time_range.rs index 929cec29e..9b7091541 100644 --- a/crates/executor/src/operators/time_range.rs +++ b/crates/executor/src/operators/time_range.rs @@ -54,13 +54,15 @@ impl Operator { }) } - /// This range window (not an instant window), each kept row's time - /// replaced by the end of the tumbling window of `width_ms` it lies in, - /// the windows counted back from the range's end `E`: `(E - (k+1) · - /// width_ms, E - k · width_ms]` ends at `E - k · width_ms`. A - /// tumbling-window chain built at query time groups its rows by that - /// end. Example: with `E` = 600,000 and windows of 60,000 ms, rows at - /// 540,001 and 600,000 end at 600,000, a row at 540,000 at 540,000. + /// This range window (not an instant window), each kept row followed + /// by the end of the tumbling window of `width_ms` its time lies in, in + /// a trailing [`TUMBLING_WINDOW_END_COLUMN`]; the row's own time is + /// kept, as a counter's samples need it. The windows count back from + /// the range's end `E`: `(E - (k+1) · width_ms, E - k · width_ms]` ends + /// at `E - k · width_ms`. A tumbling-window chain built for its readers + /// groups its rows by that end. Example: with `E` = 600,000 and windows + /// of 60,000 ms, rows at 540,001 and 600,000 end at 600,000, a row at + /// 540,000 at 540,000. pub fn with_tumbling_window_ends(mut self, width_ms: i64) -> Result { let Kind::TimeRange { latest_per_series: None, @@ -73,11 +75,30 @@ impl Operator { if width_ms <= 0 { return Err(invalid("a tumbling window has a positive width")); } + if self + .output + .fields + .iter() + .any(|field| field.name == TUMBLING_WINDOW_END_COLUMN) + { + return Err(invalid("a range window's input already has a window end")); + } *slot = Some(width_ms); + let mut output = (*self.output).clone(); + output.fields.push(result_field( + TUMBLING_WINDOW_END_COLUMN, + DataType::Timestamp, + false, + )); + self.output = Arc::new(output); Ok(self) } } +/// The column [`Operator::with_tumbling_window_ends`] appends: each row's +/// tumbling window end. +pub const TUMBLING_WINDOW_END_COLUMN: &str = "$tumbling_window_end"; + impl Operator { /// A `TimeShift { offset_ms, at }`: its rows are its input's, which a /// run evaluates once, at the anchor's time minus `offset_ms` @@ -228,7 +249,7 @@ pub(super) fn execute<'a>( batch.filter(&keep)? }; match tumbling_window_width_ms { - Some(width_ms) => window_ends(batch, time, end, width_ms), + Some(width_ms) => window_ends(batch, &operator.output, time, end, width_ms), None => Ok(batch), } }) @@ -274,10 +295,16 @@ pub(super) fn execute<'a>( .boxed_local()) } -/// `batch` (its rows in `(.., end]`) with each row's `time` replaced by the -/// end of its tumbling window of `width_ms` counted back from `end` -/// ([`Operator::with_tumbling_window_ends`]). -fn window_ends(batch: Batch, time: usize, end: i64, width_ms: i64) -> Result { +/// `batch` (its rows in `(.., end]`) as `output`: each row followed by the +/// end of its `time`'s tumbling window of `width_ms` counted back from +/// `end` ([`Operator::with_tumbling_window_ends`]). +fn window_ends( + batch: Batch, + output: &SchemaRef, + time: usize, + end: i64, + width_ms: i64, +) -> Result { let times = batch .column(time) .as_any() @@ -290,16 +317,11 @@ fn window_ends(batch: Batch, time: usize, end: i64, width_ms: i64) -> Result = (0..arrays.len()) + .map(|column| batch.state_column(column).cloned()) + .collect(); + arrays.push(std::sync::Arc::new(ends) as arrow::array::ArrayRef); + states.push(None); + Batch::from_parts(output.clone(), arrays, states, rows) } diff --git a/crates/executor/src/physical_planner/mod.rs b/crates/executor/src/physical_planner/mod.rs index ffd9d1b6a..9617977cf 100644 --- a/crates/executor/src/physical_planner/mod.rs +++ b/crates/executor/src/physical_planner/mod.rs @@ -513,14 +513,17 @@ fn compile_internal( } continue; } - // A chain builds, in an ingestion run, the window of its input - // ending at the run's end: one row per key, stamped with that - // `window_end`. Older windows are earlier runs', in the store. - // Built at query time, it builds at each evaluation `T` every - // window `(T - (k+1)c, T - kc]` its readers read, in one pass: - // each row is grouped with its key by the end of its window, - // and each state is stamped with that end, as the stored - // windows are, for the `TimeRange`s above it to select. + // A chain refreshed in an ingestion run builds the window of + // its input ending at the run's end: one row per key, stamped + // with that `window_end`. Older windows are earlier runs', in + // the store. Built for its readers instead (at query time, or + // read here without its view bound, + // [`CompileGraph::chain_builds_windows_readers_read`]), it + // builds at each evaluation `T` every window + // `(T - (k+1)c, T - kc]` its readers read, in one pass: each + // row is grouped with its key by the end of its window, and + // each state is stamped with that end, as the stored windows + // are, for the `TimeRange`s above it to select. if let Payload::ASAP(ASAPOp::SummaryTumblingWindowChain { summary_type, input: update, @@ -530,12 +533,13 @@ fn compile_internal( .. }) = &node.payload { - let query_time = node.output_state.timing - == planner_types::ir::properties::ExecutionTiming::QueryTime; - if !query_time { + if node.output_state.timing + == planner_types::ir::properties::ExecutionTiming::IngestionTime + { crate::capability::validate_ingestion_time_summary(filter.as_ref()) .map_err(Error::Invalid)?; } + let built_for_readers = graph.chain_builds_windows_readers_read(id); let [input] = schemas.as_slice() else { return Err(invalid("a tumbling-window chain reads one input")); }; @@ -559,12 +563,12 @@ fn compile_internal( })) => Some(named_column(input, &ColumnRef::SampleValue)?), _ => None, }; - let window = if query_time { + let window = if built_for_readers { // The windows its readers read, whole tumbling windows. let read = window_read_above(id, &graph).ok_or_else(|| { invalid(format!( - "node {id}: a query-time tumbling-window chain is read \ - outside the time ranges above it" + "node {id}: a tumbling-window chain built for its readers is \ + read outside the time ranges above it" )) })?; let millis = |ms: u64| { @@ -592,9 +596,12 @@ fn compile_internal( } else { Operator::time_range(input.clone(), time, 0, width_ms, sample_value, None)? }; - // At query time each key's rows group by their window end - // too. - let window_end = query_time.then_some(time); + // The rows the build reads: built for its readers, each + // followed by its tumbling window's end, which groups each + // key's rows by window too; the sample time stays the + // update's time (a counter's rate needs it). + let windowed = window.schema(); + let window_end = built_for_readers.then(|| windowed.fields.len() - 1); let build = match reduction { PlannerReduction::PerEntity => { let SummaryInputExpr::Column(value) = &update.weight else { @@ -602,14 +609,12 @@ fn compile_internal( "per-entity update requires a projected value column", )); }; - let value = named_column(input, value)?; - let groups = (0..input.fields.len()) - .filter(|&column| { - column != value && (column != time || window_end.is_some()) - }) + let value = named_column(&windowed, value)?; + let groups = (0..windowed.fields.len()) + .filter(|&column| column != value && column != time) .collect(); Operator::per_group_summary_build( - input.clone(), + windowed.clone(), summary_type.clone(), node.parameters.clone(), value, @@ -618,7 +623,7 @@ fn compile_internal( )? } _ => summary_agg_build( - input, + &windowed, summary_type, node.parameters.as_ref(), update, @@ -627,17 +632,19 @@ fn compile_internal( )?, }; let build = match filter { - Some(filter) => build.with_row_filter(expression(&filter.0, input)?)?, + Some(filter) => build.with_row_filter(expression(&filter.0, &windowed)?)?, None => build, }; let compact = build.schema(); // The window end's column among the build's output columns. let window_end = window_end - .map(|time| { + .map(|_| { compact .fields .iter() - .position(|field| field.name == input.fields[time].name) + .position(|field| { + field.name == crate::operators::TUMBLING_WINDOW_END_COLUMN + }) .ok_or_else(|| invalid("a chain's build drops its window end")) }) .transpose()?; diff --git a/crates/executor/src/physical_planner/time_window.rs b/crates/executor/src/physical_planner/time_window.rs index 9826d33be..ff884938f 100644 --- a/crates/executor/src/physical_planner/time_window.rs +++ b/crates/executor/src/physical_planner/time_window.rs @@ -50,6 +50,12 @@ impl TimeIndexedPlan for CompileGraph<'_> { reads: InputRows::AllRows, shifts_back_ms: 0, }, + InputRows::LastWindow { .. } if self.chain_builds_windows_readers_read(node) => { + InputTimeAccess { + reads: InputRows::WhatItsReadersRead, + ..access + } + } _ => access, } } @@ -63,6 +69,27 @@ impl TimeIndexedPlan for CompileGraph<'_> { } } +impl CompileGraph<'_> { + /// Whether the tumbling-window chain `node` is built in this compile + /// for the compiled nodes reading it, every window they read, rather + /// than refreshed as a compile root (its newest window, ending at an + /// ingestion run's end). A chain placed at query time always is; one + /// placed at ingestion time is when its materialized view is not bound + /// (a bound view is not compiled) and it is not a root. Example: the + /// plan of `sum by (job)(rate(c[5m]))` compiled with no view bound, a + /// 10 s chain at ingestion time under `TimeRange(5m)`: the query run + /// builds the chain's 30 windows `(T - 5m, T]`, not only `(T - 10s, T]`. + pub(super) fn chain_builds_windows_readers_read(&self, node: NodeId) -> bool { + let compiled = self.nodes[&node]; + matches!( + compiled.payload, + Payload::ASAP(ASAPOp::SummaryTumblingWindowChain { .. }) + ) && (compiled.output_state.timing + == planner_types::ir::properties::ExecutionTiming::QueryTime + || !self.roots.contains(&node)) + } +} + /// The native operator of `id` when it is a `TimeRange` or a `TimeShift` /// without an `@` anchor over a `Scan` of a SQL table or a time series, or /// over a tumbling-window chain (below any stacked `TimeShift`s); `None` diff --git a/crates/executor/tests/tumbling_window_chain.rs b/crates/executor/tests/tumbling_window_chain.rs index 9a9bee44d..3f1bb3909 100644 --- a/crates/executor/tests/tumbling_window_chain.rs +++ b/crates/executor/tests/tumbling_window_chain.rs @@ -363,7 +363,8 @@ fn a_chain_built_at_query_time_answers_queries_through_its_time_ranges() { // A range window with tumbling-window ends: at T = 10m, `(T - 3m, T]` in // windows of 1 minute keeps the rows at 7m (out), 7m + 1 ms, 8m, 9m 30 s and -// 10m, their times replaced by their windows' ends 8m, 8m, 10m and 10m. +// 10m, each keeping its time and followed by its window's end: 8m, 8m, 10m +// and 10m. #[test] fn a_range_window_stamps_each_row_with_its_tumbling_windows_end() { use asap_executor::operators::Operator as ExecutorOperator; @@ -407,15 +408,24 @@ fn a_range_window_stamps_each_row_with_its_tumbling_windows_end() { Limits::default(), ) .unwrap(); - let ends: Vec = run(&dag, &[1], context) + // Each kept row's own time and, appended, its window's end. + let times_and_ends: Vec<(i64, i64)> = run(&dag, &[1], context) .remove(0) .into_iter() - .map(|row| match row[1] { - Value::Timestamp(t) => t, - ref other => panic!("{other:?}"), + .map(|row| match (&row[1], &row[3]) { + (Value::Timestamp(time), Value::Timestamp(end)) => (*time, *end), + other => panic!("{other:?}"), }) .collect(); - assert_eq!(ends, [8, 8, 10, 10].map(|minutes| minutes * MINUTE_MS)); + assert_eq!( + times_and_ends, + [ + (7 * MINUTE_MS + 1, 8 * MINUTE_MS), + (8 * MINUTE_MS, 8 * MINUTE_MS), + (570_000, 10 * MINUTE_MS), + (10 * MINUTE_MS, 10 * MINUTE_MS), + ] + ); } // `sum_over_time(latency[5m] @ end())` in a range request over (1h, 3h]: From c082738273501903a3aba3a813c11d7039df360e Mon Sep 17 00:00:00 2001 From: zzylol <50204836+zzylol@users.noreply.github.com> Date: Sun, 15 Nov 2026 09:51:59 +0000 Subject: [PATCH 2/4] fix(executor): read an unbound ingestion-time node as at query time A node placed at ingestion time that is not a compile root is a view the compile does not bind, so it is computed for its readers. The window walk (CompileGraph::input_time_access) now reads it with query-time timing through InputTimeAccess::of, which replaces the chain-only chain_builds_windows_readers_read and also covers a stored TimeShift. The chain lowering is built for its readers when its read is not LastWindow. The window-end column is found by TUMBLING_WINDOW_END_COLUMN (now pub(crate)) in both places; the range-window test moves to a unit test that uses it. Tests: an unbound stored TimeShift(1h) over an unbound 1-minute chain answers the hand-worked a: 890, b: 1780; two counter rates sharing an installed query-time chain answer exactly (the base fails with "counter samples must have strictly increasing timestamps within each group"). --- crates/executor/src/operators/mod.rs | 2 +- crates/executor/src/operators/time_range.rs | 100 ++++++++++++++++- crates/executor/src/physical_planner/mod.rs | 39 ++++--- .../src/physical_planner/time_window.rs | 73 ++++++------- .../executor/tests/tumbling_window_chain.rs | 102 ++++++++---------- crates/planner/tests/runtime_install.rs | 73 +++++++++++-- 6 files changed, 267 insertions(+), 122 deletions(-) diff --git a/crates/executor/src/operators/mod.rs b/crates/executor/src/operators/mod.rs index 557a2e6f2..ded0132f9 100644 --- a/crates/executor/src/operators/mod.rs +++ b/crates/executor/src/operators/mod.rs @@ -38,7 +38,7 @@ pub use aggregate::Reduction; pub use series_window::SubquerySteps; pub use sort::SortKey; pub use summary::{RowWeight, SummaryEvaluation}; -pub use time_range::TUMBLING_WINDOW_END_COLUMN; +pub(crate) use time_range::TUMBLING_WINDOW_END_COLUMN; #[derive(Clone, serde::Serialize, serde::Deserialize)] enum Kind { #[serde(skip)] diff --git a/crates/executor/src/operators/time_range.rs b/crates/executor/src/operators/time_range.rs index 9b7091541..51b02d794 100644 --- a/crates/executor/src/operators/time_range.rs +++ b/crates/executor/src/operators/time_range.rs @@ -97,7 +97,7 @@ impl Operator { /// The column [`Operator::with_tumbling_window_ends`] appends: each row's /// tumbling window end. -pub const TUMBLING_WINDOW_END_COLUMN: &str = "$tumbling_window_end"; +pub(crate) const TUMBLING_WINDOW_END_COLUMN: &str = "$tumbling_window_end"; impl Operator { /// A `TimeShift { offset_ms, at }`: its rows are its input's, which a @@ -325,3 +325,101 @@ fn window_ends( states.push(None); Batch::from_parts(output.clone(), arrays, states, rows) } + +#[cfg(test)] +mod tests { + use super::*; + use crate::plan::PhysicalDAG; + use crate::runtime::{Limits, Scope}; + use futures::executor::block_on; + use planner_types::stages::Lifetime; + + const MINUTE_MS: i64 = 60_000; + + // A range window with tumbling-window ends: at T = 10m, `(T - 3m, T]` + // in windows of 1 minute keeps the rows at 7m (out), 7m + 1 ms, 8m, + // 9m 30 s and 10m, each keeping its time and followed, in + // `TUMBLING_WINDOW_END_COLUMN`, by its window's end: 8m, 8m, 10m and + // 10m. + #[test] + fn a_range_window_stamps_each_row_with_its_tumbling_windows_end() { + let schema = Arc::new(Schema::with_time_index( + vec![ + SummaryField::plain("job", DataType::Utf8, false), + SummaryField::plain("ts", DataType::Timestamp, false), + SummaryField::plain("value", DataType::Float64, false), + ], + 1, + vec![], + )); + let times = [ + 7 * MINUTE_MS, + 7 * MINUTE_MS + 1, + 8 * MINUTE_MS, + 570_000, + 10 * MINUTE_MS, + ]; + let rows = times + .iter() + .map(|&t| { + vec![ + Value::Utf8("a".into()), + Value::Timestamp(t), + Value::Float64(1.0), + ] + }) + .collect(); + let batch = Batch::try_new(schema.clone(), rows).unwrap(); + let mut dag = PhysicalDAG::default(); + dag.add( + 0, + vec![], + Operator::source(schema.clone(), vec![batch]).unwrap(), + Lifetime::None, + ) + .unwrap(); + let window = Operator::time_range(schema, 1, 0, 3 * MINUTE_MS, None, None) + .unwrap() + .with_tumbling_window_ends(MINUTE_MS) + .unwrap(); + let output = window.schema(); + let end = output + .fields + .iter() + .position(|field| field.name == TUMBLING_WINDOW_END_COLUMN) + .unwrap(); + dag.add(1, vec![0], window, Lifetime::None).unwrap(); + let context = RunContext::new( + Scope::Query { + evaluation_time_ms: 10 * MINUTE_MS, + }, + Limits::default(), + ) + .unwrap(); + let mut outputs = dag.execute(&[1], context).unwrap(); + let rows = block_on(async { + let mut rows = Vec::new(); + while let Some(batch) = outputs[0].next().await { + rows.extend(batch.unwrap().to_rows()); + } + rows + }); + // Each kept row's own time and, appended, its window's end. + let times_and_ends: Vec<(i64, i64)> = rows + .into_iter() + .map(|row| match (&row[1], &row[end]) { + (Value::Timestamp(time), Value::Timestamp(end)) => (*time, *end), + other => panic!("{other:?}"), + }) + .collect(); + assert_eq!( + times_and_ends, + [ + (7 * MINUTE_MS + 1, 8 * MINUTE_MS), + (8 * MINUTE_MS, 8 * MINUTE_MS), + (570_000, 10 * MINUTE_MS), + (10 * MINUTE_MS, 10 * MINUTE_MS), + ] + ); + } +} diff --git a/crates/executor/src/physical_planner/mod.rs b/crates/executor/src/physical_planner/mod.rs index 9617977cf..14f780ed9 100644 --- a/crates/executor/src/physical_planner/mod.rs +++ b/crates/executor/src/physical_planner/mod.rs @@ -20,6 +20,7 @@ use planner_types::plan::physical_asap_dag::{ PhysicalASAPDAG, PhysicalASAPDAGNode, PhysicalASAPNodeId, PhysicalASAPOperatorPayload as Payload, }; +use planner_types::plan::time_window::{InputRows, TimeIndexedPlan}; use planner_types::plan::TimeWindow; use planner_types::summary_type::{ SketchParams, SketchStatistic, SummaryInputExpr, SummaryTypeCapability, @@ -517,8 +518,8 @@ fn compile_internal( // its input ending at the run's end: one row per key, stamped // with that `window_end`. Older windows are earlier runs', in // the store. Built for its readers instead (at query time, or - // read here without its view bound, - // [`CompileGraph::chain_builds_windows_readers_read`]), it + // not a compile root, its view not bound: it then reads what + // its readers read, [`CompileGraph::input_time_access`]), it // builds at each evaluation `T` every window // `(T - (k+1)c, T - kc]` its readers read, in one pass: each // row is grouped with its key by the end of its window, and @@ -539,7 +540,10 @@ fn compile_internal( crate::capability::validate_ingestion_time_summary(filter.as_ref()) .map_err(Error::Invalid)?; } - let built_for_readers = graph.chain_builds_windows_readers_read(id); + let built_for_readers = !matches!( + graph.input_time_access(id).reads, + InputRows::LastWindow { .. } + ); let [input] = schemas.as_slice() else { return Err(invalid("a tumbling-window chain reads one input")); }; @@ -601,7 +605,22 @@ fn compile_internal( // key's rows by window too; the sample time stays the // update's time (a counter's rate needs it). let windowed = window.schema(); - let window_end = built_for_readers.then(|| windowed.fields.len() - 1); + // The window end's column in `schema`, when built for its + // readers. + let window_end_in = |schema: &SchemaRef| { + built_for_readers + .then(|| { + schema + .fields + .iter() + .position(|field| { + field.name == crate::operators::TUMBLING_WINDOW_END_COLUMN + }) + .ok_or_else(|| invalid("a chain's build drops its window end")) + }) + .transpose() + }; + let window_end = window_end_in(&windowed)?; let build = match reduction { PlannerReduction::PerEntity => { let SummaryInputExpr::Column(value) = &update.weight else { @@ -637,17 +656,7 @@ fn compile_internal( }; let compact = build.schema(); // The window end's column among the build's output columns. - let window_end = window_end - .map(|_| { - compact - .fields - .iter() - .position(|field| { - field.name == crate::operators::TUMBLING_WINDOW_END_COLUMN - }) - .ok_or_else(|| invalid("a chain's build drops its window end")) - }) - .transpose()?; + let window_end = window_end_in(&compact)?; physical_dag.add(auxiliary, inputs, window)?; physical_dag.add(helper_id(id, 1)?, vec![auxiliary], build)?; physical_dag.add( diff --git a/crates/executor/src/physical_planner/time_window.rs b/crates/executor/src/physical_planner/time_window.rs index ff884938f..af7990c6f 100644 --- a/crates/executor/src/physical_planner/time_window.rs +++ b/crates/executor/src/physical_planner/time_window.rs @@ -38,24 +38,32 @@ impl TimeIndexedPlan for CompileGraph<'_> { self.dependencies.get(&node).cloned().unwrap_or_default() } + /// A node placed at ingestion time that is not a compile root reads as + /// if placed at query time. The walks ask this only of compiled nodes + /// (every reader is one), and a compiled ingestion-time node that is + /// not a root is a view this compile does not bind: it is computed + /// here for the compiled nodes reading it. Example: the + /// plan of `sum by (job)(rate(c[5m]))` compiled with no view bound, a + /// 10 s chain at ingestion time under `TimeRange(5m)`: the chain reads + /// what its readers read, `(T - 5m, T]`, not only its newest window + /// `(T - 10s, T]`; a stored `TimeShift(1h)` reads its readers' windows + /// 1 h back, not only the current time. A planned per-edge read window + /// replaces this override: such a node then reads the union of its + /// outgoing edges' windows. fn input_time_access(&self, node: NodeId) -> InputTimeAccess { + use planner_types::ir::properties::ExecutionTiming; let compiled = self.nodes[&node]; - let access = InputTimeAccess::of( - &compiled.payload, - compiled.output_state.timing, - compiled.lifetime, - ); + let root = self.roots.contains(&node); + let timing = match compiled.output_state.timing { + ExecutionTiming::IngestionTime if !root => ExecutionTiming::QueryTime, + timing => timing, + }; + let access = InputTimeAccess::of(&compiled.payload, timing, compiled.lifetime); match access.reads { - InputRows::WhatItsReadersRead if self.roots.contains(&node) => InputTimeAccess { + InputRows::WhatItsReadersRead if root => InputTimeAccess { reads: InputRows::AllRows, shifts_back_ms: 0, }, - InputRows::LastWindow { .. } if self.chain_builds_windows_readers_read(node) => { - InputTimeAccess { - reads: InputRows::WhatItsReadersRead, - ..access - } - } _ => access, } } @@ -69,27 +77,6 @@ impl TimeIndexedPlan for CompileGraph<'_> { } } -impl CompileGraph<'_> { - /// Whether the tumbling-window chain `node` is built in this compile - /// for the compiled nodes reading it, every window they read, rather - /// than refreshed as a compile root (its newest window, ending at an - /// ingestion run's end). A chain placed at query time always is; one - /// placed at ingestion time is when its materialized view is not bound - /// (a bound view is not compiled) and it is not a root. Example: the - /// plan of `sum by (job)(rate(c[5m]))` compiled with no view bound, a - /// 10 s chain at ingestion time under `TimeRange(5m)`: the query run - /// builds the chain's 30 windows `(T - 5m, T]`, not only `(T - 10s, T]`. - pub(super) fn chain_builds_windows_readers_read(&self, node: NodeId) -> bool { - let compiled = self.nodes[&node]; - matches!( - compiled.payload, - Payload::ASAP(ASAPOp::SummaryTumblingWindowChain { .. }) - ) && (compiled.output_state.timing - == planner_types::ir::properties::ExecutionTiming::QueryTime - || !self.roots.contains(&node)) - } -} - /// The native operator of `id` when it is a `TimeRange` or a `TimeShift` /// without an `@` anchor over a `Scan` of a SQL table or a time series, or /// over a tumbling-window chain (below any stacked `TimeShift`s); `None` @@ -223,17 +210,19 @@ pub(super) fn time_range_window(id: NodeId, graph: &CompileGraph<'_>) -> Option< /// The window back from the evaluation time that the compiled consumers of /// `id` read ([`windows_readers_need`]): through the /// `TimeShift`s (without an `@` anchor) above it, a `TimeRange(w)` or a -/// chain of width `w` built at ingestion time (its window ending at the -/// evaluation time) over shifts summing to `s` reads `{s, w}`; several read -/// the smallest window holding all of theirs. A chain built at query time -/// builds the windows its own readers read, so the walk passes up through -/// it. `None` when `id` or a shift above it is a compile root, another +/// chain of width `w` refreshed as a compile root (its window ending at +/// the evaluation time) over shifts summing to `s` reads `{s, w}`; several +/// read the smallest window holding all of theirs. A chain built for its +/// readers (at query time, or not a root, +/// [`CompileGraph::input_time_access`]) builds the windows they read, so +/// the walk passes up through it. `None` when `id` or a shift above it is a compile root, another /// consumer reads it outside a window, or nothing reads it. /// -/// A `TimeShift` materialized at ingestion time reads its input at its -/// evaluation time, which this walk reads unbounded (every consumer -/// outside a window is): its refresh over a chain slot is refused ("read -/// unbounded"), and over a raw `Scan` it compiles and reads every row. +/// A `TimeShift` materialized at ingestion time and refreshed as a compile +/// root reads its input at its evaluation time, which this walk reads +/// unbounded (every consumer outside a window is): its refresh over a +/// chain slot is refused ("read unbounded"), and over a raw `Scan` it +/// compiles and reads every row. /// /// Example: a `Scan` read by a query-time chain of 1-minute windows, which /// `TimeRange(5m)` and `TimeShift(1m) -> TimeRange(5m)` read, is read for diff --git a/crates/executor/tests/tumbling_window_chain.rs b/crates/executor/tests/tumbling_window_chain.rs index 3f1bb3909..75245ddbc 100644 --- a/crates/executor/tests/tumbling_window_chain.rs +++ b/crates/executor/tests/tumbling_window_chain.rs @@ -14,7 +14,6 @@ use planner_types::ir::scalar::ColumnRef; use planner_types::ir::schema::{DataType, Field, FieldDataType, Schema}; use planner_types::ir::{ASAPOp, NonASAPOp, Operator, OperatorNode, QueryRoot, TimeRangeKind}; use planner_types::plan::physical_asap_dag::{PhysicalASAPDAG, PhysicalASAPNodeId}; -use planner_types::stages::Lifetime; use planner_types::summary_type::{ExactKind, ExactParams, SummaryUpdate}; use std::collections::BTreeMap; use std::rc::Rc; @@ -361,70 +360,61 @@ fn a_chain_built_at_query_time_answers_queries_through_its_time_ranges() { ); } -// A range window with tumbling-window ends: at T = 10m, `(T - 3m, T]` in -// windows of 1 minute keeps the rows at 7m (out), 7m + 1 ms, 8m, 9m 30 s and -// 10m, each keeping its time and followed by its window's end: 8m, 8m, 10m -// and 10m. +// `sum_over_time(latency[5m] offset 1h)` over a stored chain of 1-minute +// windows and a stored `TimeShift(1h)` above it, both views at ingestion +// time, run in one query run with no view bound: both are computed here +// for their readers. At T = 4h the shift reads `(T - 1h - 5m, T - 1h]` = +// `(175m, 180m]`, so the chain builds those five windows from the raw +// samples: `a` = 176 + 177 + 178 + 179 + 180 = 890, `b` twice that. #[test] -fn a_range_window_stamps_each_row_with_its_tumbling_windows_end() { - use asap_executor::operators::Operator as ExecutorOperator; - use asap_executor::plan::PhysicalDAG; - let schema = Arc::new(samples_schema()); - let times = [ - 7 * MINUTE_MS, - 7 * MINUTE_MS + 1, - 8 * MINUTE_MS, - 570_000, - 10 * MINUTE_MS, - ]; - let rows = times - .iter() - .map(|&t| { - vec![ - Value::Utf8("a".into()), - Value::Timestamp(t), - Value::Float64(1.0), - ] - }) - .collect(); - let batch = Batch::try_new(schema.clone(), rows).unwrap(); - let mut dag = PhysicalDAG::default(); - dag.add( - 0, - vec![], - ExecutorOperator::source(schema.clone(), vec![batch]).unwrap(), - Lifetime::None, - ) - .unwrap(); - let window = ExecutorOperator::time_range(schema, 1, 0, 3 * MINUTE_MS, None, None) - .unwrap() - .with_tumbling_window_ends(MINUTE_MS) +fn an_unbound_stored_time_shift_over_an_unbound_chain_reads_its_readers_windows() { + let chain = node(Operator::ASAP(ASAPOp::SummaryTumblingWindowChain { + child: scan(), + summary_type: sum(), + input: SummaryUpdate::column(ColumnRef::SampleValue), + reduction: Reduction::by(vec![0]), + filter: None, + tumbling_window_width_ms: MINUTE_MS as u64, + })); + let shifted_windows = shift(HOUR_MS, None, chain.clone()); + let shifted = finalized_sum(node(Operator::ASAP(ASAPOp::SummaryMerge { + children: vec![range(5 * MINUTE_MS, shifted_windows.clone())], + group_by: None, + }))); + let (mut dag, nodes) = + planner_types::test_support::forwarders::physical_asap_dag_at_query_time_with_node_ids(&[ + QueryRoot::Operator(shifted.clone()), + ]) .unwrap(); - dag.add(1, vec![0], window, Lifetime::None).unwrap(); + let stored = [id_of(&nodes, &chain), id_of(&nodes, &shifted_windows)]; + views_at(&mut dag, &stored.map(|id| id as u64)).unwrap(); + for id in stored { + assert_eq!( + dag.nodes + .iter() + .find(|node| node.id == id) + .unwrap() + .output_state + .timing, + planner_types::ir::properties::ExecutionTiming::IngestionTime + ); + } + let root = id_of(&nodes, &shifted) as u64; + let query = compile(&dag, &[], &[root]).unwrap(); let context = RunContext::new( Scope::Query { - evaluation_time_ms: 10 * MINUTE_MS, + evaluation_time_ms: 4 * HOUR_MS, }, Limits::default(), ) .unwrap(); - // Each kept row's own time and, appended, its window's end. - let times_and_ends: Vec<(i64, i64)> = run(&dag, &[1], context) - .remove(0) - .into_iter() - .map(|row| match (&row[1], &row[3]) { - (Value::Timestamp(time), Value::Timestamp(end)) => (*time, *end), - other => panic!("{other:?}"), - }) - .collect(); + let answers = { + let query = query.instantiate(Arc::new(store_with_samples())).unwrap(); + run(&query, &[root], context) + }; assert_eq!( - times_and_ends, - [ - (7 * MINUTE_MS + 1, 8 * MINUTE_MS), - (8 * MINUTE_MS, 8 * MINUTE_MS), - (570_000, 10 * MINUTE_MS), - (10 * MINUTE_MS, 10 * MINUTE_MS), - ] + sums_of(answers[0].clone()), + BTreeMap::from([("a".to_string(), 890.0), ("b".to_string(), 1780.0)]) ); } diff --git a/crates/planner/tests/runtime_install.rs b/crates/planner/tests/runtime_install.rs index a43ce2a01..212f4a702 100644 --- a/crates/planner/tests/runtime_install.rs +++ b/crates/planner/tests/runtime_install.rs @@ -554,15 +554,35 @@ async fn grouped_and_per_series_counts_over_a_shared_query_time_chain_install_an /// counter series sampled every second, planned with the built-in models /// on a deployment that keeps raw data or not. async fn plan_counter_query(query: &str, raw_data_retained: bool) -> InstallablePlan { + plan_counter_queries(&[query], 10_000, raw_data_retained).await +} + +/// `queries`, each every `interval_ms` within relative error 0.01, over +/// 1,000 `requests_total` counter series sampled every second, planned +/// together with the built-in models on a deployment that keeps raw data +/// or not. +async fn plan_counter_queries( + queries: &[&str], + interval_ms: u64, + raw_data_retained: bool, +) -> InstallablePlan { + let entries: Vec = queries + .iter() + .map(|query| { + format!( + r#"{{"query": {query:?}, + "demand": {{"fixed_interval_at": {{"interval": {interval_ms}, "evaluation_phase": 0}}}}, + "requirements": {{"accuracy": {{"max_error": 0.01}}}}, + "predictability": {{"predictable": {{"known_at": null}}}}}}"# + ) + }) + .collect(); let workload: PlanningWorkload = serde_json::from_str(&format!( - r#"{{"query_workload": {{"language": "promql", "repeating_queries": [{{ - "query": {query:?}, - "demand": {{"fixed_interval_at": {{"interval": 10000, "evaluation_phase": 0}}}}, - "requirements": {{"accuracy": {{"max_error": 0.01}}}}, - "predictability": {{"predictable": {{"known_at": null}}}}}}]}}, + r#"{{"query_workload": {{"language": "promql", "repeating_queries": [{}]}}, "data_workload": {{"arrival": {{"ingesting": {{"rows_per_second": 1000.0}}}}, "sources": {{"requests_total": {{"series_count": 1000, - "metric_type": "counter", "sample_interval": 1000}}}}}}}}"# + "metric_type": "counter", "sample_interval": 1000}}}}}}}}"#, + entries.join(",") )) .unwrap(); let capabilities = DeploymentCapabilities { @@ -572,7 +592,7 @@ async fn plan_counter_query(query: &str, raw_data_retained: bool) -> Installable let models = PlanningModels::builtin().with_deployment_capabilities(&capabilities); plan_installable(UserInput::new(&workload, FrontendInput::Promql, models)) .await - .unwrap_or_else(|e| panic!("{query} (raw data retained: {raw_data_retained}): {e}")) + .unwrap_or_else(|e| panic!("{queries:?} (raw data retained: {raw_data_retained}): {e}")) .0 } @@ -736,3 +756,42 @@ async fn counter_rates_and_increases_answer_at_query_time_from_raw_samples() { let mismatches = counter_query_mismatches(query_answers).await; assert!(mismatches.is_empty(), "{mismatches:#?}"); } + +/// `rate(requests_total[5m] offset 1m)` and `rate(requests_total[5m])`, +/// each every minute, share a tumbling-window chain of 1-minute windows +/// that the plan builds at query time. Installed, the query run builds it +/// from the raw samples, each update at its sample's own time: over +/// [`counter_samples`] (four samples per window) both queries answer the +/// hand-worked rates `(i + 1) * 20 / 300` per series. `(T - 6m, T - 1m]` +/// holds steps 9..=28, 20 samples as `(T - 5m, T]` does. +#[tokio::test] +async fn counter_rates_over_a_shared_query_time_chain_answer_as_installed() { + let plan = plan_counter_queries( + &[ + "rate(requests_total[5m] offset 1m)", + "rate(requests_total[5m])", + ], + 60_000, + true, + ) + .await; + assert!( + plan.dag.nodes.iter().any(|node| matches!( + node.payload, + asap_types::ir::Operator::ASAP( + asap_types::ir::ASAPOp::SummaryTumblingWindowChain { .. } + ) + ) && node.output_state.timing + == asap_types::ir::properties::ExecutionTiming::QueryTime), + "the plan builds a chain at query time: {:#?}", + plan.dag.nodes + ); + let rates: Vec = (1..=4).map(|i| i as f64 * 20.0 / 300.0).collect(); + for answered in installed_answers(&plan, &counter_samples()) { + let values: Vec = answered.iter().map(|(_, value)| *value).collect(); + assert_eq!(values.len(), rates.len(), "{answered:?}"); + for (value, rate) in values.iter().zip(&rates) { + assert!((value - rate).abs() <= 1e-9 * rate, "{answered:?}"); + } + } +} From 5237ecf3cd8d3c1ea73932aca92519674fddefe5 Mon Sep 17 00:00:00 2001 From: zzylol <50204836+zzylol@users.noreply.github.com> Date: Sun, 15 Nov 2026 10:45:53 +0000 Subject: [PATCH 3/4] fix(executor): read only an unbound view as at query time; review fixes Narrow the timing override in CompileGraph::input_time_access to an unbound view (a non-root AcrossEvaluations ingestion-time node). The chain lowering matches on its input time access: LastWindow gives the refresh form over that window, any other read builds for its readers. Neutral missing-window-end error; inline the one-line plan_counter_query wrapper; import ExecutionTiming at the top level. --- crates/executor/src/physical_planner/mod.rs | 87 +++++++++++-------- .../src/physical_planner/time_window.rs | 28 +++--- crates/planner/tests/runtime_install.rs | 9 +- 3 files changed, 68 insertions(+), 56 deletions(-) diff --git a/crates/executor/src/physical_planner/mod.rs b/crates/executor/src/physical_planner/mod.rs index 14f780ed9..f15c12e96 100644 --- a/crates/executor/src/physical_planner/mod.rs +++ b/crates/executor/src/physical_planner/mod.rs @@ -518,8 +518,8 @@ fn compile_internal( // its input ending at the run's end: one row per key, stamped // with that `window_end`. Older windows are earlier runs', in // the store. Built for its readers instead (at query time, or - // not a compile root, its view not bound: it then reads what - // its readers read, [`CompileGraph::input_time_access`]), it + // an unbound view: it then reads what its readers read, + // [`CompileGraph::input_time_access`]), it // builds at each evaluation `T` every window // `(T - (k+1)c, T - kc]` its readers read, in one pass: each // row is grouped with its key by the end of its window, and @@ -540,10 +540,6 @@ fn compile_internal( crate::capability::validate_ingestion_time_summary(filter.as_ref()) .map_err(Error::Invalid)?; } - let built_for_readers = !matches!( - graph.input_time_access(id).reads, - InputRows::LastWindow { .. } - ); let [input] = schemas.as_slice() else { return Err(invalid("a tumbling-window chain reads one input")); }; @@ -567,38 +563,53 @@ fn compile_internal( })) => Some(named_column(input, &ColumnRef::SampleValue)?), _ => None, }; - let window = if built_for_readers { + let millis = |ms: u64| { + i64::try_from(ms).map_err(|_| invalid("a chain's read overflows Int64")) + }; + let (window, built_for_readers) = match graph.input_time_access(id).reads { + // Refreshed: its newest window, `(T - length_ms, T]`. + InputRows::LastWindow { length_ms } => ( + Operator::time_range( + input.clone(), + time, + 0, + millis(length_ms)?, + sample_value, + None, + )?, + false, + ), // The windows its readers read, whole tumbling windows. - let read = window_read_above(id, &graph).ok_or_else(|| { - invalid(format!( - "node {id}: a tumbling-window chain built for its readers is \ + _ => { + let read = window_read_above(id, &graph).ok_or_else(|| { + invalid(format!( + "node {id}: a tumbling-window chain built for its readers is \ read outside the time ranges above it" - )) - })?; - let millis = |ms: u64| { - i64::try_from(ms).map_err(|_| invalid("a chain's read overflows Int64")) - }; - let (end_offset_ms, read_width_ms) = ( - millis(read.ends_before_evaluation_ms)?, - millis(read.length_ms)?, - ); - if end_offset_ms % width_ms != 0 || read_width_ms % width_ms != 0 { - return Err(invalid(format!( - "node {id}: a window ({end_offset_ms} ms back, {read_width_ms} ms \ - wide) is not whole tumbling windows of {width_ms} ms" - ))); + )) + })?; + let (end_offset_ms, read_width_ms) = ( + millis(read.ends_before_evaluation_ms)?, + millis(read.length_ms)?, + ); + if end_offset_ms % width_ms != 0 || read_width_ms % width_ms != 0 { + return Err(invalid(format!( + "node {id}: a window ({end_offset_ms} ms back, {read_width_ms} ms \ + wide) is not whole tumbling windows of {width_ms} ms" + ))); + } + ( + Operator::time_range( + input.clone(), + time, + end_offset_ms, + read_width_ms, + sample_value, + None, + )? + .with_tumbling_window_ends(width_ms)?, + true, + ) } - Operator::time_range( - input.clone(), - time, - end_offset_ms, - read_width_ms, - sample_value, - None, - )? - .with_tumbling_window_ends(width_ms)? - } else { - Operator::time_range(input.clone(), time, 0, width_ms, sample_value, None)? }; // The rows the build reads: built for its readers, each // followed by its tumbling window's end, which groups each @@ -616,7 +627,11 @@ fn compile_internal( .position(|field| { field.name == crate::operators::TUMBLING_WINDOW_END_COLUMN }) - .ok_or_else(|| invalid("a chain's build drops its window end")) + .ok_or_else(|| { + invalid( + "a chain built for its readers has no window-end column", + ) + }) }) .transpose() }; diff --git a/crates/executor/src/physical_planner/time_window.rs b/crates/executor/src/physical_planner/time_window.rs index af7990c6f..37e4b11cd 100644 --- a/crates/executor/src/physical_planner/time_window.rs +++ b/crates/executor/src/physical_planner/time_window.rs @@ -6,10 +6,12 @@ //! ([`CompileGraph`]). use super::*; +use planner_types::ir::properties::ExecutionTiming; use planner_types::plan::time_window::{ shift_back_ms_below, windows_computed_from, windows_readers_need, InputRows, InputTimeAccess, TimeIndexedPlan, }; +use planner_types::stages::Lifetime; /// The nodes one compile reads, as the time walks see them: each node's /// inputs (`dependencies`), the compiled nodes reading it (`consumers`; @@ -38,11 +40,11 @@ impl TimeIndexedPlan for CompileGraph<'_> { self.dependencies.get(&node).cloned().unwrap_or_default() } - /// A node placed at ingestion time that is not a compile root reads as - /// if placed at query time. The walks ask this only of compiled nodes - /// (every reader is one), and a compiled ingestion-time node that is - /// not a root is a view this compile does not bind: it is computed - /// here for the compiled nodes reading it. Example: the + /// An unbound view (a non-root `AcrossEvaluations` ingestion-time node) + /// reads as if placed at query time. The walks ask this only of + /// compiled nodes (every reader is one), and such a node is a view this + /// compile does not bind: it is computed here for the compiled nodes + /// reading it. Example: the /// plan of `sum by (job)(rate(c[5m]))` compiled with no view bound, a /// 10 s chain at ingestion time under `TimeRange(5m)`: the chain reads /// what its readers read, `(T - 5m, T]`, not only its newest window @@ -51,12 +53,13 @@ impl TimeIndexedPlan for CompileGraph<'_> { /// replaces this override: such a node then reads the union of its /// outgoing edges' windows. fn input_time_access(&self, node: NodeId) -> InputTimeAccess { - use planner_types::ir::properties::ExecutionTiming; let compiled = self.nodes[&node]; let root = self.roots.contains(&node); - let timing = match compiled.output_state.timing { - ExecutionTiming::IngestionTime if !root => ExecutionTiming::QueryTime, - timing => timing, + let timing = match (compiled.output_state.timing, compiled.lifetime) { + (ExecutionTiming::IngestionTime, Lifetime::AcrossEvaluations(_)) if !root => { + ExecutionTiming::QueryTime + } + (timing, _) => timing, }; let access = InputTimeAccess::of(&compiled.payload, timing, compiled.lifetime); match access.reads { @@ -213,10 +216,11 @@ pub(super) fn time_range_window(id: NodeId, graph: &CompileGraph<'_>) -> Option< /// chain of width `w` refreshed as a compile root (its window ending at /// the evaluation time) over shifts summing to `s` reads `{s, w}`; several /// read the smallest window holding all of theirs. A chain built for its -/// readers (at query time, or not a root, +/// readers (at query time, or an unbound view, /// [`CompileGraph::input_time_access`]) builds the windows they read, so -/// the walk passes up through it. `None` when `id` or a shift above it is a compile root, another -/// consumer reads it outside a window, or nothing reads it. +/// the walk passes up through it. `None` when `id` or a shift above it is +/// a compile root, another consumer reads it outside a window, or nothing +/// reads it. /// /// A `TimeShift` materialized at ingestion time and refreshed as a compile /// root reads its input at its evaluation time, which this walk reads diff --git a/crates/planner/tests/runtime_install.rs b/crates/planner/tests/runtime_install.rs index 212f4a702..32804d4be 100644 --- a/crates/planner/tests/runtime_install.rs +++ b/crates/planner/tests/runtime_install.rs @@ -550,13 +550,6 @@ async fn grouped_and_per_series_counts_over_a_shared_query_time_chain_install_an // ── Counter rate and increase, per series and per group ───────────────────── -/// `query` every 10 s within relative error 0.01 over 1,000 `requests_total` -/// counter series sampled every second, planned with the built-in models -/// on a deployment that keeps raw data or not. -async fn plan_counter_query(query: &str, raw_data_retained: bool) -> InstallablePlan { - plan_counter_queries(&[query], 10_000, raw_data_retained).await -} - /// `queries`, each every `interval_ms` within relative error 0.01, over /// 1,000 `requests_total` counter series sampled every second, planned /// together with the built-in models on a deployment that keeps raw data @@ -719,7 +712,7 @@ async fn counter_query_mismatches( let mut mismatches = Vec::new(); for raw_data_retained in [true, false] { for (query, expected) in counter_queries() { - let plan = plan_counter_query(query, raw_data_retained).await; + let plan = plan_counter_queries(&[query], 10_000, raw_data_retained).await; let answered = answer(&plan, &samples).remove(0); let matches = answered.len() == expected.len() && answered.iter().zip(&expected).all(|(answer, expected)| { From 3ae606ccd4161d931ca3dc6ab2d2c33c2d3f25e4 Mon Sep 17 00:00:00 2001 From: zzylol <50204836+zzylol@users.noreply.github.com> Date: Mon, 16 Nov 2026 04:20:52 +0000 Subject: [PATCH 4/4] docs(executor): a held AcrossEvaluations node may be an unbound view computed for its readers A compile with a view slot not bound computes that view for its readers in the query run, so a computed AcrossEvaluations node with several consumers is no longer only a hand-built DAG's. --- crates/executor/README.md | 8 ++++---- crates/executor/src/runtime/mod.rs | 10 ++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/executor/README.md b/crates/executor/README.md index b9e8075e3..f7cc8220f 100644 --- a/crates/executor/README.md +++ b/crates/executor/README.md @@ -28,10 +28,10 @@ consumer), as its `Lifetime` and the run's scope say: one consumer: the node runs once, to the end, before any consumer reads it, and every consumer reads its finished output independently, as the planner charges one run whose output is held. Likewise a computed - `AcrossEvaluations` node with more than one consumer, which only a - hand-built DAG has at query time (a compiled plan reads it through its - view slot). For example, a `OneEvaluation` scan read by three queries - is one store read. The output is charged to the run's byte budget until + `AcrossEvaluations` node with more than one consumer: an unbound view + (a compile with its view slot not bound computes it for its readers in + the query run), or a node of a hand-built DAG. For example, a + `OneEvaluation` scan read by three queries is one store read. The output is charged to the run's byte budget until every consumer has read it; over the budget the run fails with `MemoryLimit` (nothing spills). With one consumer the node streams to it, since no sibling can wait on that consumer. diff --git a/crates/executor/src/runtime/mod.rs b/crates/executor/src/runtime/mod.rs index 163c89a37..3e5462f66 100644 --- a/crates/executor/src/runtime/mod.rs +++ b/crates/executor/src/runtime/mod.rs @@ -103,10 +103,12 @@ enum NodeRun { /// than one consumer: run to the end once before any consumer reads it, /// then read by each consumer, as the planner charges one run whose /// output is held. Likewise a computed `AcrossEvaluations` node with - /// more than one consumer, which only a hand-built DAG has at query time - /// (a compiled plan reads it through its view slot). Example: a - /// `OneEvaluation` scan read by three queries is one store read whose - /// batches every query reads. + /// more than one consumer: an unbound view, which a compile with its + /// view slot not bound computes for its readers in the query run, or a + /// node of a hand-built DAG. Example: a `OneEvaluation` scan read by + /// three queries is one store read whose batches every query reads; a + /// stored chain no view slot binds, read by two queries, is built once + /// and read by both. Held, /// Every other node: one run whose batches reach each consumer as they /// come. At query time it has one consumer (a computed `None` node with