Skip to content

Delta graph sources: an unordered scan pages nondeterministically #2319

Open

Description

@aaj3f

Problem

A query over a Delta graph source with LIMIT/OFFSET and no ORDER BY can return
different rows for the same page across executions. DeltaSnapshot::scan
(fluree-db-delta/src/table.rs) reads a version's data files on N blocking
workers that all send decoded batches into one shared channel, so the consumer
sees rows interleaved at batch granularity in I/O-completion order. Pages of one
query therefore do not partition its answer: rows are skipped or repeated.

The same defect on Iceberg graph sources is fixed in #2315, which introduced
ScanOrder (a sliced query's Iceberg scan emits files smallest first, ties in
plan order; an unsliced one streams in completion order). The Delta provider
does not override R2rmlTableProvider::scan_table_ordered, so it ignores the
order and keeps today's behaviour.

Reproduce: a 24-file Delta table, SELECT ?s ?n WHERE { ?s ex:name ?n } LIMIT 25
run six times in one process gives 3-6 distinct row orders (measured on a quiet
dedicated 16-vCPU cloud machine).

Why it was not fixed with Iceberg

An ordered dispatcher was built and measured: files are handed to workers in
plan order, each file streams into a channel of its own, and the consumer drains
those channels in plan order through a channel bounded at the worker count.
Base vs that design, 24 files (even: 24 x 125k rows; uneven: (500k, 20k, 20k,
20k) x 6), warm medians, ratio vs base:

shape per-file buffer 2 per-file buffer 1024 buffer 1024, smallest first
drain, even / uneven 1.00 / 1.03 0.94 / 1.01 1.03 / 1.02
COUNT, even / uneven 3.55 / 3.99 1.16 / 1.65 1.16 / 1.59
LIMIT 25, even / uneven 1.72 / 1.86 3.15 / 3.00 3.35 / 1.30
LIMIT 25 OFFSET 100000, even / uneven 1.16 / 1.15 1.29 / 1.54 1.38 / 1.41

RSS at buffer 1024 is about 2x base on COUNT and LIMIT. A small per-file buffer
serializes decode (workers on later files stall after two batches); a large one
lets every worker decode ahead and holds whole files, which costs memory and,
after a LIMIT is met, wasted decode. No variant is speed-neutral.

Expected

  • A Delta scan honours ScanOrder: Any keeps today's shared-channel scan
    (no regression for unsliced queries); Deterministic emits a fixed order.
  • The deterministic lane is speed-neutral against today on the shapes above
    (LIMIT, LIMIT/OFFSET, filtered), or the trade-off is measured and agreed.
  • Candidate designs: order at batch granularity with a byte budget across files
    rather than a per-file batch count; smallest file first (as Iceberg does) so
    the head of the window is the cheapest read; cancel in-flight decodes once the
    consumer drops the stream.
  • Tests: a test-only slow-read hook (as Iceberg's) forcing completion order to
    differ from the fixed order; pages partition the answer on SPARQL and JSON-LD.

Notes

  • Out of scope here, as for Iceberg: an append or compaction between two page
    requests changes the version, and with it the order.

Follow-up from #2315.

Activity

  1. added
    bug
    P2
    area:query
    on Nov 11, 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

    P2area:querybug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions