Repository navigation
[core][datafusion] Prune and coalesce sparse ROW reads - #1555
Conversation
This reverts commit 221a3cb.
leaves12138
left a comment
There was a problem hiding this comment.
Reviewed base main at head f700edc. Full file list: crates/integrations/datafusion/src/table/mod.rs, crates/integrations/datafusion/tests/scan_pruning_stats.rs, crates/paimon/src/arrow/format/row.rs, crates/paimon/src/table/row_id_predicate.rs.
Core change notice: this touches generic core read paths, not just the SQL layer: the ROW format reader (block coalescing, read-ahead accounting, metadata tail prefetch) and the shared _ROW_ID predicate-to-range extraction (BETWEEN, IN compaction). All core/C/Python/DataFusion readers of ROW files and row-ID range planning are affected.
Analysis:
- Predicate extraction:
Betweenmaps to one inclusive range with the low bound clamped at 0 and inverted bounds yielding an empty range (no rows), which is correct since row IDs are non-negative;Innow goes throughmerge_row_ranges, which sorts and merges overlapping and adjacent singletons, preserving the exact value set.NotBetween/NotInare not convertible inleaf_to_ranges, so negated forms keep the residual filter and never over-prune. The AND-intersect / OR-union semantics of the extractor are unchanged. - DataFusion gating: the read-fields schema (with the synthesized
_ROW_ID) is only used for filter analysis when data evolution is enabled and every column reference in every filter is_ROW_ID; mixed predicates keep the physical-field path, andsupports_filters_pushdownuses the same read fields so classification and scan agree. - Block coalescing: only adjacent runs in
blocks_to_read(already ascending and gap-free by construction) are merged, capped at 1 MiB compressed per request and at runs no longer than the read-ahead window; a block larger than the cap still reads alone.read_row_rangevalidates the returned length, and the per-block split uses index compressed sizes, so decompression boundaries cannot drift. Per-block selection and order are computed exactly as before. - Read-ahead accounting:
FuturesOrderedpreserves block order; a merged request consumes one slot per block and slots are only refilled after its blocks are yielded, so an early-stopping consumer stays within the eight-block window. The no-selection and long-run cases read one block at a time, matching the old prefetch depth. The new regression asserts requested ranges are a prefix of the expected reads for four stop-early scenarios. - Metadata tail: the tail size scales with file size between 4 KiB and 64 KiB, the footer is sliced from the tail end, and the index is served from the tail when contained or fetched by its exact validated range otherwise. Index/footer cross-validation (
validate_for_file) is unchanged, and the cache-hit read-count tests were updated consistently (3 to 2 cold reads).
No findings. Behavior outside the new fast paths is preserved, and the test coverage is strong: SQL regression reproducing the extra-file scan on the base revision, range boundary cases including i64::MAX, request-limit splitting, adjacent/skipped block reads, early-stop request prefixes, and the large-index fallback.
CI note: most jobs are still pending on this head (1 pass, 14 pending); the author reports the core/DataFusion suites, SQL reads, and MERGE INTO integration passing locally with fmt and focused Clippy clean. Approving without waiting for CI to finish.
LGTM.
Purpose
Closes #1554.
Sparse Data Evolution SQL lookups can read every ROW file because the DataFusion predicate translator only sees the physical fields. A lookup that crosses a ROW block boundary also issues separate data reads for adjacent blocks.
Brief change log
_ROW_IDalone so the planner can prune by row ID. Extract inclusiveBETWEENranges and compact consecutiveINvalues into ranges.Tests
BETWEENandINchecks that the plan prunes an unselected file and returns the expected values. It reproduced the extra file on the base revision.MERGE INTOintegration suites passed locally. DataFusion used the CI test stack size. Formatting and focused Clippy checks passed.On a local OpenDAL counting fixture with 32 files, 200 Float32 fields, and sixteen 80-row lookups, both SQL forms returned the same 1,280 rows. The original SQL scan issued 800 data range reads. The updated reader issued 16, totaling 0.93 MB for block-aligned lookups. Moving each range one row forward crossed two blocks per file and took 16 data reads, totaling 1.86 MB. Placing eight of the disjoint ranges in each of two files also took 16 data reads. For small indexes, cold metadata took one range read per file.
On the same fixture,
LIMIT 1now requests 464,568 data bytes in eight single-block reads with a 58,030-byte first request. Before the read-ahead fixes, an unfiltered scan and a scan with one row deleted per file each requested 1,451,815 bytes. A scan with"_ROW_ID" BETWEEN 1 AND 1900requested 1,393,731 bytes. All three cases previously started with a 1,045,238-byte request.A synthetic ROW file of about 256 MiB with the same schema had 18.4 KiB of footer and index bytes. The 64 KiB tail covers both in one read. The roughly 1.4 MiB files from the range-lookup fixture still use 4 KiB.
API and Format
The changes use the existing SQL and table read APIs and accept existing Java-compatible ROW files.
Documentation
The existing Data Evolution SQL predicate syntax applies.