Skip to content

Epic: Plan (replacing LayoutReaders) #9062

Open
0 of 1 issue completed
Open

Description

@joseph-isaacs

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:

  1. A LayoutReader executes one split inside a stack frame, and splitting the expression across children happens during that execution.
  2. Expression optimizations are recomputed, behind a cache, on every split.
  3. 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 most n pieces, from metadata only. It is for hosts that read a fixed number of streams. DataFusion asks for one piece per output partition. Spark would choose n itself, from its target split size, and report the pieces as its input partitions. The host states what it needs on the ScanRequest, 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 DataSource and ScanRequest underneath. Partitions and the public ScanBuilder are 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

Execution

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:

Next:

  • The V2 engine behind split and open
  • DataFusion FileOpener reads each file through open
  • Python, Java/Spark and C bindings on DataSource and ScanRequest, 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 make ScanBuilder private, in one breaking release

Engines

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 Plan through the V2 engine by default, and the LayoutReader path is deleted.
  • Every host reads every source through the Scan API's split and open. Partitions are deleted, and no host calls ScanBuilder.

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

  1. added
    epic
    on Jul 29, 2026
  2. changed the title [-]Epic: `ScanPlan` (replacing `LayoutReader`s)[/-] [+]Epic: `Plan` (replacing `LayoutReader`s)[/+] on Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    epic

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions