Skip to content

perf(substrait): avoid quadratic field lookup when consuming ReadRel - #26190

Open
ole-baranov wants to merge 1 commit into
apache:mainfrom
tarantool:feature/substrait-schema-check-index
Open

ole-baranov wants to merge 1 commit into
apache:mainfrom
tarantool:feature/substrait-schema-check-index

Conversation

@ole-baranov

Copy link
Copy Markdown

ensure_schema_compatibility and apply_projection looked up every field of the Substrait base schema with a linear scan of the table schema, making consumption of a read over a wide table O(m*n). Build a name->index map of the table schema once instead. Missing or duplicated names fall back to the existing DFSchema lookups, so errors and disambiguation are unchanged.

Add a consume_wide_read benchmark. Consume time for SELECT c0 over a table with N columns:

columns   before     after
100       58 us      25.5 us
1000      2.33 ms    276 us
10000     211 ms     3.16 ms

`ensure_schema_compatibility` and `apply_projection` looked up every field
of the Substrait base schema with a linear scan of the table schema, making
consumption of a read over a wide table O(m*n). Build a name->index map of
the table schema once instead. Missing or duplicated names fall back to the
existing DFSchema lookups, so errors and disambiguation are unchanged.

Add a `consume_wide_read` benchmark. Consume time for `SELECT c0` over a
table with N columns:

    columns   before     after
    100       58 us      25.5 us
    1000      2.33 ms    276 us
    10000     211 ms     3.16 ms

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the substrait Changes to the substrait crate label Oct 10, 2026

@bvolpato bvolpato left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the improvement. The fast path preserves the existing lookup fallback for missing and duplicate names. Substrait checks, Clippy, and the wide-read benchmark smoke run pass locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

substrait Changes to the substrait crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants