[opt](nereids) rewrite element_at(split_by_string(s,sep),n) to split_part - #66181
Open
Baymine wants to merge 1 commit into
Open
[opt](nereids) rewrite element_at(split_by_string(s,sep),n) to split_part#66181Baymine wants to merge 1 commit into
Baymine wants to merge 1 commit into
Conversation
### What problem does this PR solve? Issue Number: close apache#66179 Problem Summary: `element_at(split_by_string(s, d), n)` builds the whole split array (a PODArray allocation and a memcpy per part, per row) and then picks a single entry. This rewrites it to `split_part(s, d, n)`, which short-circuits as soon as it locates the n-th delimiter, eliminating the intermediate array and the trailing-parts work. The rewrite is semantics-preserving. The two forms differ only when the string yields no n-th part: `element_at` returns NULL while `split_part` can return ''. To neutralize this, the rule only rewrites the ROOT of a top-level filter conjunct (where NULL and false both drop the row) and is guarded to: - EqualTo / InPredicate with a NON-EMPTY string-literal RHS (or an IN-list of non-empty string literals), so a comparison against '' yields false, not true; - a NON-EMPTY string-literal separator (an empty/column separator diverges); - a NON-NEGATIVE int-literal index (negative back-counting uses rfind and can land on a different boundary for self-overlapping multi-char separators). It deliberately does NOT recurse into NOT / OR / CASE, where NULL and '' are no longer interchangeable. ### Release note None ### Check List (For Author) - Test <!-- At least one of them must be included. --> - [ ] Regression test - [x] Unit Test - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Explain why: - Behavior changed: - [x] No. - [ ] Yes. - Does this need documentation? - [x] No. - [ ] Yes.
Baymine
requested review from
924060929,
englefly,
morrySnow and
starocean999
as code owners
July 28, 2026 12:12
Contributor
Author
|
run buildall |
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
TPC-H: Total hot run time: 29631 ms |
Contributor
TPC-DS: Total hot run time: 177840 ms |
Contributor
ClickBench: Total hot run time: 24.91 s |
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.
What problem does this PR solve?
Issue Number: close #66179
Related PR: N/A
Problem Summary:
element_at(split_by_string(s, d), n)builds the whole split array (a PODArray allocation and a memcpy per part, per row) and then picks a single entry. This rewrites it tosplit_part(s, d, n), which short-circuits as soon as it locates the n-th delimiter, eliminating the intermediate array and the trailing-parts work.The rewrite is semantics-preserving. The two forms differ only when the string yields no n-th part:
element_atreturns NULL whilesplit_partcan return''. To neutralize this, the rule only rewrites the ROOT of a top-level filter conjunct (where NULL and false both drop the row) and is guarded to:''yields false, not true;It deliberately does NOT recurse into NOT / OR / CASE, where NULL and
''are no longer interchangeable.Release note
None
Check List (For Author)
Test
Behavior changed:
Does this need documentation?
Check List (For Reviewer who merge this PR)