neilconway opened a new pull request, #24153:
URL: https://github.com/apache/datafusion/pull/24153
## Which issue does this PR close?
- N/A
## Rationale for this change
`regexp_count` takes an optional argument, `start`, that specifies a
character-based index. The current implementation handles `start` by calling
`v.chars().count` for every input row, which scans the entire string. This is
unnecessarily expensive for the common case that `start` identifies a character
position near the start of the string: once we've converted `start` into a byte
offset, we can stop scanning the string.
Fix this by doing a lazy walk of the string and stopping early. This was
first done for `regexp_instr` in #24054; this PR refactors that code into a
shared helper. Happily, this also fixes a 32-bit portability bug with the
previous code in `regexp_count` as well.
regexp_count benchmark, with_start cases:
size=1024 str_len=32: -5.7%
size=1024 str_len=128: -11.5%
size=4096 str_len=32: -4.1%
size=4096 str_len=128: -6.6%
## What changes are included in this PR?
* Refactor `start_to_byte_offset` into a shared helper
* Use `start_to_byte_offset` in both `regexp_instr` (no functional change)
and `regexp_count`
* Add SLT cases verifying that `regexp_count` handles zero-width patterns
the same way that PostgreSQL does (this was the primary motivation for #24054)
## Are these changes tested?
Yes; optimized code path is covered by existing tests. SLT additions are
orthogonal.
## Are there any user-facing changes?
No.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]