A duql pipeline with an order-dependent stage asks for an ordered scan; others stay unordered
DecisionVerified 29 Sep 2026Holds project: dftracer-utils
Decision. The context, the choice, why, and the options that were turned down.
Context#
With 8 workers the duql scan streamed rows in finish order, so the determinism test (1, 2 and 8 workers, two checkpoint sizes) failed for pipelines with take or skip.
Decision#
- Workers still decode checkpoints in parallel, in any order. For an ordered scan, the stream cursor keeps early morsels in a small buffer and gives rows out in file, then checkpoint order.
- A claim window of 2 × workers checkpoints limits how far ahead workers claim. It bounds memory and prevents a deadlock with the memory budget.
- Only a plan with a later order-dependent step (
take,skip,distinct,sort) asks for order. Aggregations,countand export stay unordered, and so does a plainView.head(n).
Why#
Ordering after the work keeps decoding parallel; the only cost is a short wait at the head of the stream. Plans that do not depend on order pay nothing. The user approved it: "ok i like it".
Rejected options#
- A
skipthat avoids decoding: not done for now, because it needs per-checkpoint event counts in the index.
Evidence#
Commit 05a7f86b: the determinism test passes, take 1000 takes 12 ms against 270 ms for a full scan, and TSan found no races.
Also found by searching
- determinism test fails with 8 workers for pipelines with take or skip
- parallel duql scan returns rows in a different order on each run
- how do I keep row order for take skip distinct in a parallel scan without slowing everything
- ordered scan stream cursor buffer claim window 2x workers deadlock memory budget
- duql with take or skip gives different rows with 8 workers, determinism test fails for 1, 2 and 8 workers
- scan streams rows in finish order and head(n) results differ per run
- how does duql decide when the scan must be ordered?
- ordered scan claim window 2 x workers morsel buffer deadlock memory budget