Skip to content

perf(storage): project requested columns before taking rows - #920

Open
egolearner wants to merge 2 commits into
mainfrom
codex/project-columns-before-take
Open

egolearner wants to merge 2 commits into
mainfrom
codex/project-columns-before-take

Conversation

@egolearner

@egolearner egolearner commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Why project before taking rows?

A ranked query that returns only primary keys and scores needs just the primary key from the forward store. Previously, MemForwardStore ran Arrow's Take on the full table and selected the output columns afterward. When hits span record batches, Take can concatenate chunks and copy large text values that the query will discard. This work runs while the query holds the collection read lock and can make a writer wait longer.

Select the requested columns first, then pass the original row indices to Take. This preserves hit order and duplicate hits. If the Arrow table has no unique match for a requested physical column, projection returns an Invalid status naming the column before taking any rows.

Measured allocations

The regression test fetches only primary keys for row indices [1, 0, 0]. Row 0 is in a stored batch and contains a 256 KiB text value. Row 1 is still pending. The test measures the change in Arrow's cumulative allocated-byte counter around a single fetch call on macOS arm64.

Version Arrow bytes allocated per fetch
Base (8d978b0) 1,051,776
This change 2,304

Regression results

  • The allocation regression test fails on the base commit and passes with this change. It checks the allocation budget, the returned column and the exact primary-key sequence.
  • A second regression test requests one valid column and one missing column. It checks that projection fails with an Invalid status containing the missing column's name.
  • All 52 memory forward-store tests, 23 selected Collection tests and both concurrent read/write tests passed (77 total).
  • A separate full-text search over 1,024 documents returned byte-for-byte identical primary keys and scores, in the same order, across 10 repeated top-100 queries on both versions.

Arrow can concatenate chunks while taking rows from a table. Select the requested columns first so primary-key fetches skip large text columns while the query holds the collection read lock.
Return an Invalid status with the column name when the Arrow table cannot resolve a requested field. Cover a projection that previously succeeded with only a subset of its requested columns.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant