datafusion icon indicating copy to clipboard operation
datafusion copied to clipboard

Exact reverse parquet scan counts shared buffers once per batch in its memory reservation

Open zhuqi-lucas opened this issue 3 weeks ago • 1 comments

With datafusion.execution.parquet.enable_exact_reverse_scan (#27079), the scan buffers one decoded row group and charges each batch's get_array_memory_size() to the memory pool. Batches of the same row group can share buffers, such as a page dictionary, so a shared buffer is counted once per batch. The scan cannot spill, so a query can fail with a resources error well below its real memory use.

Example from the #27079 review: 1M rows with 4000 distinct strings (about 25 MB). A 100 MB pool fails in the reverse scan, while the plan with the option off finishes at 30 MB by spilling in the sort.

The reservation should count each distinct buffer once across the batches it holds. This should be fixed before the option is enabled by default.

Related: #27079, #19048

zhuqi-lucas avatar Nov 09 '26 02:11 zhuqi-lucas

I'd like to take this. The reverse row group reservation currently charges each batch's get_array_memory_size, so buffers shared across batches are counted once per batch. I'll switch it to RecordBatchMemoryTracker, count each batch when it is retained and uncount it when it is dropped or popped, and add a shared-buffer regression test.

vinycalves avatar Nov 12 '26 13:11 vinycalves