Skip to main content

vortex_scan/execution/pipeline/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4//! Push-based execution of physical plans as pipelines.
5//!
6//! A [`Scan`] runs a [`PlanRef`](crate::plan::PlanRef) over a list of splits, row ranges
7//! of the plan's domain. Each split is compiled into pipelines: a pipeline is one
8//! [`Source`](super::operator::Source), zero or more [`Operator`](super::operator::Operator)s,
9//! and the ports its last stage writes. The driver asks the source for a batch and pushes it
10//! through the stages into the ports. Every port runs from one pipeline's sink,
11//! the end that pushes into its outlets, to another's source, which reads it as an inlet, and
12//! the plan joining them declares how many batches each inlet may hold.
13//!
14//! A source checks its readiness before computing, waiting for a segment read or an inlet.
15//! The driver also blocks a pipeline when an outlet is full. The scheduler re-runs a blocked
16//! pipeline when that one condition clears.
17//!
18//! The owner of a scan answers reads: [`Scan::step`] returns each read as a [`Turn::Read`], and
19//! [`Scan::deliver`] hands its bytes back. Nothing in a scan awaits.
20//!
21//! # Masks
22//!
23//! Every mask a scan applies is known when the pipelines that apply it are compiled: the split's
24//! selection, and the rows the earlier conjuncts kept. The
25//! compiler places the mask in the stage that reads the rows, so chunks a mask selects nothing
26//! of are never built and never read.
27//!
28//! # Sharing
29//!
30//! A segment several readers decode is decoded once. Before the scan starts, one pass over the
31//! plans every split's stages run records the rows each segment is read for, so the splits that
32//! will read it are found by binary search over the splits. The first reader of a segment read
33//! more than once builds one pipeline that decodes it and fans the decoded array out into one
34//! single-use port per reader, tagged with the reader's split: a reader in the same stage, a
35//! later stage of a query, or a later split claims its own port. A split's ports it never
36//! claims, because its rows were pruned or a stage never ran, leave the sharing pipeline's
37//! outlets and are freed when it finishes, so nothing is ever pushed into a port nobody will
38//! read, and a claimed port is dropped once its source has drained it, so a decoded segment
39//! lives only as long as a split that may still read it.
40
41mod compile;
42pub(crate) mod port;
43mod scan;
44pub mod synthetic;
45mod values;
46
47pub use self::compile::Chain;
48pub use self::compile::Compiler;
49pub(crate) use self::compile::overlapping;
50pub(crate) use self::port::Arena;
51pub use self::port::Inlet;
52pub(super) use self::port::PortId;
53pub use self::scan::ReadId;
54pub use self::scan::ReadRequest;
55pub use self::scan::Scan;
56pub use self::scan::Split;
57pub use self::scan::Turn;
58pub use self::values::ValueCache;
59
60/// Batches an inlet holds before its sink is blocked, unless the plan joining it says
61/// otherwise; see [`Compiler::join_with`].
62pub const DEFAULT_CAPACITY: usize = 8;
63
64#[cfg(test)]
65mod scheduling_tests;
66
67#[cfg(test)]
68mod tests;