[SPARK-58100][SQL] Use IndexedSeq to fix quadratic complexity in partition resolution#57243
Open
flipp5b wants to merge 1 commit into
Open
[SPARK-58100][SQL] Use IndexedSeq to fix quadratic complexity in partition resolution#57243flipp5b wants to merge 1 commit into
flipp5b wants to merge 1 commit into
Conversation
Author
|
@pan3793, @LuciferYang, could you please take a look? |
pan3793
reviewed
Jul 14, 2026
LuciferYang
reviewed
Jul 14, 2026
LuciferYang
reviewed
Jul 14, 2026
pan3793
approved these changes
Jul 14, 2026
69bd23a to
c98ccf6
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.
This PR fixes the issue 57220.
What changes were proposed in this pull request?
The PR updates
resolveTypeConflictsto returnIndexedSeq[TypedPartValue](backed byVector) instead ofSeq.Vector.apply(index)is effectively O(1), reducing the overall complexity to O(nk).Why are the changes needed?
For now,
resolvedValuesis aSeq[Seq[TypedPartValue]], where each inner collection is a linked list. So theapplymethod called there is O(n). This is called for every partition and every column, making the total complexity O(n²k), where n = number of partitions and k = number of partition columns.With thousands of daily partitions, this becomes a real issue: a thread "indefinitely" spins at the following stack trace:
Does this PR introduce any user-facing change?
No
How was this patch tested?
The following benchmark confirms the issue and the fix:
Results before the fix:
Results after the fix:
Was this patch authored or co-authored using generative AI tooling?
No