Repository navigation
Description
This epic tracks moving scans from LayoutReader to Plan, the V2 scan engine that executes plans, and the Scan API through which host engines drive it. A Plan is a physical plan: like ArrayRef, optimizations rewrite one plan into another, and execution is separate.
Why
LayoutReader merges planning with execution:
- A
LayoutReaderexecutes one split inside a stack frame, and splitting the expression across children happens during that execution. - Expression optimizations are recomputed, behind a cache, on every split.
- Changing what is read, such as gating a file on a pruning layout, means modifying the layout tree instead of the plan.
Plans fix these, and a separate executor gives us control over pushdown (expressions, aggregates) and over resource use.
The Scan API makes the engine reusable. Every host (DuckDB, DataFusion, Spark, Python, C/C++/Java) integrates once against the Scan API, and every format is a source that compiles to Scan Plan nodes, so n×m engine/format integrations become n+m. Vortex files are the first source. vortex-parquet already reads Parquet through Vortex layouts and expressions, at 0.7x the geomean query time of DataFusion's Parquet reader, and an Iceberg reader would be a plan that nests Parquet and Vortex scans. I/O stays pluggable underneath: new I/O subsystems, caching layers, and storage that isn't a file.
Example
For StructLayout(a: FlatLayout, b: FlatLayout) and the expression $.a + 1, a LayoutReader splits the expression as it executes, passing $ + 1 to the reader of a. With plans we build
ExprPlan(expr: $.a + 1, child: StructPlan(a: FlatLayout, b: FlatLayout))
and the optimizer rewrites it, before any execution, to
ExprPlan(expr: $ + 1, child: FlatLayout) // field a
Scan API
A scan was a stream of partitions, and a partition did two jobs: the unit a host ships or declares, and the unit one thread runs. Each host worked around that differently: DuckDB keeps private work queues for V1 and V2, DataFusion's output partitions share one partition stream under a lock, and row-range partitions re-plan and read their boundary chunks twice.
A scan now offers two operations. A host uses the one that matches its own execution model, and that model never changes to suit a source:
split(n)cuts the scan into at mostnpieces, from metadata only. It is for hosts that read a fixed number of streams. DataFusion asks for one piece per output partition. Spark would choosenitself, from its target split size, and report the pieces as its input partitions. The host states what it needs on theScanRequest, and the source decides what the pieces are. For an unordered request the pieces share one work queue inside the source, so a piece that runs dry takes work from the others. For an ordered request the pieces are fixed and contiguous, and their concatenation is in scan order.open()returns the scan as one stream of arrays that can be cloned. Each clone is another worker over the same remaining work. It is for hosts whose threads join a scan as they become free: DuckDB.
The source decides the units (layout splits in V1, the chunk grid in V2). The host decides parallelism, meaning how many pieces or clones it reads. The engine decides concurrency, which will become a memory limit per worker. A scan runs its work as tasks on the session's runtime, which the host owns, and never starts threads.
How hosts move over
- One default path per host. The PR that moves a host onto the Scan API replaces that host's read path, and is measured against develop on the benchmark target that already covers the host. No toggle outlives its PR, and no benchmark target is added.
- Public language APIs stay as they are while hosts move. The Python, Java and C APIs keep their surface and are re-implemented on
DataSourceandScanRequestunderneath. Partitions and the publicScanBuilderare removed once, in one breaking release, after every in-repo caller has moved. - V1 or V2 is the only lasting axis, and it becomes a choice of source instead of a code path in every host.
Status
V2 scans run on plans end to end. They are opt-in on DataFusion (vortex.scan_v2) and DuckDB (VORTEX_SCAN_V2=1), and the default in vortex compress and the TPC-DS and ClickBench benchmarks.
Plan model
-
Plantrait and layout scan physical plan model (Add layout scan physical plan model #9142) - Optimizer rules and expression pushdown (Add plan optimizer rules and push expressions #9196)
- Zoned pruning, shares and dictionary value reuse (feat(layout): zoned pruning, shares, and dictionary value reuse in physical plans #10462)
-
Eval(Eval())andEval(pack())reduce rules (Add Eval(Eval()) and Eval(pack()) reduce rules #10732) - Plan children in fixed-position slots (Store plan children in fixed-position slots #11178)
- Replace layout lowering with
VTable::new_plan(Replace layout lowering with a VTable::new_plan method #11200) -
ExpressionPlan(Tracking Issue: ExpressionPlan #9115): partly covered byEvalpushdown; pluggable per-plan pushdown kernels remain - Custom pushdown for expression × scan plans (Struct, Dict, …), @myrrc:
PartitionSessionregisters rules per expression × plan (PartitionSession: register partition rules dynamically #10812) and is threaded into planning and the optimizer (Pass VortexSession to plan scan and optimizer #10794) - Plan registry, foreign-operator placeholder and serialization envelope
Execution
- Push-based pipelines and the scan that runs them (feat(layout): add push-based pipelines and the scan that runs them #10391, feat(layout): compile segment scans, filters, concatenations, and packs to pipelines #10392, feat(layout): compile evals, row indices, and takes to pipelines #10393)
- Scan protocol traits: planners, morsels and the
Rundriver (Scan protocol traits #10047) - Filter / split / project planners (Add Filter/Split/Project planner and add Datafusion usage of this #10706), composed from one
PreparedScan(Plan a V2 scan as a chain of planners from one prepared scan #10707) - Random access from known row selections (Plan V2 random access from known row selections #10625)
- Cache scan state across scans of one file (feat(scan): cache V2 scan state across scans of one file #10631)
- Bound the splits a scan decodes at once (feat(scan): let a scan request bound the splits it decodes at once #11127)
- List layouts (Read list layouts in the V2 scan #11656, Read list layouts in the V2 scan #11275), with element samples (Record list element samples in the list layout #11652) and sliced-list export (Export only the list elements a sliced list references #11659)
- Row liveness, so in-memory scan state is dropped on time (feat(scan): track row liveness in the planner driver to time dropping in-memory scan state #11201, perf(scan): share decoded segments while live work covers their rows #11248, perf(scan): keep dictionary values only while live work claims their rows #11355)
- Reads named by source and segment, so storage without byte offsets can serve a scan (Name scan reads by source and segment #11623)
- Compile plans at run time inside pipeline sources (Let pipeline sources compile plans at run time #11655)
- Index pruning: skipping indexes (Epic: Skipping Indexes #8900) and the index layout (Epic: A First-Class Index Layout (
vortex.indexed) #8948) in V2 pruning - Admit work by memory budget rather than split count
- Recheck a tightened dynamic filter per chunk before its reads (Recheck tightened dynamic filters before a V2 chunk reads #11679)
Scan API
First merge target, one stack. It adds the contract and proves it with one partitioned host and one morsel-driven host, at parity with develop:
-
splitandopenon every scan (Make split and open the methods every scan implements #11662) - V1 layout scans behind
splitandopen(Read V1 layout scans through split and open #11663) - DataFusion
VortexTablereads throughsplit(Read DataFusion VortexTable scans through split and open #11666) - DuckDB
MultiFileReaderreads throughopen(Read DuckDB's V1 scans through open #11664)
Next:
- The V2 engine behind
splitandopen - DataFusion
FileOpenerreads each file throughopen - Python, Java/Spark and C bindings on
DataSourceandScanRequest, with their public APIs unchanged - A request property for fixed pieces, and serializable pieces, for hosts that ship them (Spark, distributed)
- One composite source over child sources, so an Iceberg table is one
DataSource - DuckDB table function over any
DataSource - A memory limit per worker, replacing
ScanRequest::split_concurrency - Remove partitions (
Partition,partition_range,partition_selection) and makeScanBuilderprivate, in one breaking release
Engines
-
vortex compressuses the V2 scan (feat: switch vortex compress to use v2 scan api #10540) - DataFusion: compose and drive a V2 scan (Compose and drive a V2 scan in DataFusion #10708), Arrow conversion on driver tasks (fix: Convert V2 scan batches to Arrow on the driver's tasks #10861), dynamic filters (Push DataFusion dynamic filters into V2 scans #11215)
- DuckDB: planner-driven V2 scan path (Drive V2 scans in the DuckDB extension with a custom driver #10809)
- Default the TPC-DS and ClickBench benchmarks to V2 (Speed up V2 scans and default datafusion-bench to V2 for TPC-DS and ClickBench #10799, Default duckdb-bench to the V2 scan for TPC-DS and ClickBench #11047)
- Results parity with V1 and Parquet on TPC-H, TPC-DS and ClickBench, checked in CI
- Per-scan metrics that explain pruning, I/O and decode time
- Default DuckDB to V2 (Default DuckDB to Scan V2 and optimize sparse and wide scans #10964)
- Default DataFusion to V2
- Remove the
LayoutReaderscan path
Ideas, not yet tracked
- Nested row domains. A list's elements are their own row domain, mapped to the parent by offsets. Scans should plan and split in whichever domain they iterate, translating row ranges and masks across the edge, so one large list can be several splits, and parent fields can broadcast over a scan of the elements.
- Sub-segment reads. Operators request byte ranges within a segment, and sources can register segment locations they discover while scanning, such as page offsets from an index. Segment lengths become
u64. - Evidence-based filtering. Replace separate prune and filter phases with one loop over evidence: plan nodes contribute providers (zone maps, page indexes, bloom filters, exact evaluation) that mark each row in, out or unknown, run in order of expected benefit per cost, and known-in rows skip that conjunct's reads. A first step is two-sided zone maps.
- Sparse reads. A selection of a few rows touches only the chunks that hold them, so point lookups cost in proportion to the rows they need.
- Cross-scan caches. Footers, plans and decoded dictionaries shared across scans in a session, behind the same pluggable interface as I/O.
Goal
- Scans run on
Planthrough the V2 engine by default, and theLayoutReaderpath is deleted. - Every host reads every source through the Scan API's
splitandopen. Partitions are deleted, and no host callsScanBuilder.
Unresolved questions
- How does a plan whose nodes expand at run time (an Iceberg manifest list) produce fixed pieces? Proposed: the scan expands such nodes before it splits, and an unexpanded node counts as one unit.
- Is an async stream the right shape for a worker on V2, or does V2 need a non-blocking step the host drives?
- What does a per-worker memory limit bound exactly (decoded output, in-flight segments, or both), and how does V1 approximate it?
Activity
[-]Epic: `ScanPlan` (replacing `LayoutReader`s)[/-][+]Epic: `Plan` (replacing `LayoutReader`s)[/+]Add layout scan physical plan model (#9142)
Use the shared scan driver in the DataFusion file opener (#11611)
Read files through the Scan API in vortex-tui and vortex-bench (#11794)