chore: Add substr() benchmarks, refactor#20803
Open
neilconway wants to merge 3 commits intoapache:mainfrom
Open
chore: Add substr() benchmarks, refactor#20803neilconway wants to merge 3 commits intoapache:mainfrom
substr() benchmarks, refactor#20803neilconway wants to merge 3 commits intoapache:mainfrom
Conversation
substr() benchmarks, refactor
Omega359
reviewed
Mar 9, 2026
| argument( | ||
| name = "start_pos", | ||
| description = "Character position to start the substring at. The first character in the string has a position of 1." | ||
| description = "Character position to start the substring at. The first character in the string has a position of 1. If the start position is less than 1, it is treated as if it is before the start of the string and the (absolute) number of characters before position 1 is subtracted from `length` (if given). For example, `substr('abc', -3, 6)` returns `'ab'`." |
Contributor
There was a problem hiding this comment.
Is this a new behaviour? As far as I know this doesn't match postgresql's behaviour (as described in the doc on get_true_start_end) where negative start is not allowed. I think for PG the recommended approach there is to use the right(..) function, for duckdb it's string slices.
Contributor
Author
There was a problem hiding this comment.
@Omega359 Thanks for the comment! This is not new behavior. The behavior for negative start values actually matches what PostgreSQL implements (and what the SQL spec dictates), even though personally that behavior doesn't seem particularly useful to me. get_true_start_end does allow negative start values; maybe you're thinking of negative count values, which are not allowed.
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.
Which issue does this PR close?
N/A
Rationale for this change
I'd like to optimize
substrfor scalarstart/countinputs, but the code would benefit from some refactoring and cleanup first. I also added benchmarks forsubstrwith scalar args.What changes are included in this PR?
string_view_substrandstring_substrto use a single loopget_true_start_endto validate its own inputs, cleanup UTF8 pathstartandcountargumentsAre these changes tested?
Yes.
Are there any user-facing changes?
No, other than an error message wording change.
AI usage
Multiple AI tools were used to iterate on this PR. I have reviewed and understand the resulting code.