Repository navigation
[CALCITE-7953] RelBuilder.fields(Iterable<String>) searches the input once per name, so resolving many fields by name is quadratic - #5434
Merged
Conversation
RyanL1997
marked this pull request as ready for review
November 20, 2026 23:52
mihaibudiu
reviewed
Nov 22, 2026
Contributor
Author
|
Pushed a small follow-up: the check now compares field names rather than whole fields, so a join of inputs with distinct names also uses the row type (20,000 fields: 1.3 s -> 10 ms). The wide-input test now uses such a join. Comparing names costs a bit more, so skipping the check for 1 or 2 names now saves about 13 µs rather than 6.5 µs on a 1,000-field input. |
mihaibudiu
approved these changes
Nov 23, 2026
… once per name, so resolving many fields by name is quadratic
RyanL1997
force-pushed
the
CALCITE-7953
branch
from
November 23, 2026 19:28
d2b221d to
2a8e218
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Jira Link
CALCITE-7953
Changes Proposed
RelBuilder.fields(Iterable<String>)calledfield(String)once per name, and each call searches the input's fields, so resolving n names on an n-field input took O(n²) time.As discussed in the Jira case, when the input has its row type's field names,
fieldsnow looks the names up in the row type; aRelRecordTypewith many fields keeps a map from name to field. This is the case after a scan, filter, sort, project or aggregate, and after a join whose inputs have no field names in common. Otherwise, for example after a join with repeated names, and for 2 or fewer names, it callsfield(String)as before. Results and errors are unchanged.Tests in
RelBuilderTest:testFieldsByNameOnWideInputlooks up all fields of a join of two 50,000-field inputs and fails if that takes more than 2 seconds. It takes about 20 seconds before the fix and 50 ms after.testFieldsByNameAfterJoin,testFieldsByNameWithDynamicStarandtestFieldsByNameWithExtraFieldcheck thatfieldsreturns the same fields and errors asfield(String)when the input's names repeat, and whenRelDataType.getFieldreturns a field for a name the row type does not have.