Repository navigation
Do not rewrite end-anchored LIKE chains into multiMatchAny - #118766
Conversation
|
Workflow [PR], commit [bd844b3] Summary: ✅
AI ReviewSummaryThis PR fixes Final Verdict✅ No findings. LLVM Coverage ReportMeasured on commit bd844b3.
Changed lines: Changed C/C++ lines covered: 37/37 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units86 translation units recompiled, 369 s compile time in total, 86 of them have a recent master baseline. |
alexey-milovidov
left a comment
There was a problem hiding this comment.
Ok. However, I'd search for a regexp modifier that makes anchors not match line boundaries, only the whole content boundaries.
Backport #118766 to 26.8: Do not rewrite end-anchored LIKE chains into `multiMatchAny`
Backport #118766 to 26.7: Do not rewrite end-anchored LIKE chains into `multiMatchAny`
…chains into `multiMatchAny`
Cherry pick #118766 to 26.6: Do not rewrite end-anchored LIKE chains into `multiMatchAny`
Backport #118766 to 26.6: Do not rewrite end-anchored LIKE chains into `multiMatchAny`
…into `multiMatchAny`
Resolve the conflicts of the automated cherry-pick. The 26.3 branch carries the
original, much simpler `ConvertOrLikeChainPass` (no `multiSearchAny` path, no
`PatternData`, no per-chain thresholds, and `optimize_or_like_chain` defaults to
`false`), so the master version of the pass, of the `optimize_or_like_chain`
description and the `tests/performance/optimize_or_like_chain_hits.xml` change
do not apply. The fix is adapted to the 26.3 pass instead.
Conflict resolutions:
* `src/Common/likePatternToRegexp.{h,cpp}` merged cleanly and is taken as is:
`likePatternToRegexp` now reports through an optional `has_end_anchor`
out-parameter whether it emitted a trailing `$`.
* `src/Analyzer/Passes/ConvertOrLikeChainPass.cpp` keeps the 26.3 pass and adds
the end-anchor check to it: a `{i}like` branch whose regexp ends with `$` is
left as the original branch instead of being folded into `multiMatchAny`.
`multiMatchAny` runs the regexp through Vectorscan, where `$` also matches
before a final newline, while `like`/`ilike` use RE2, where `$` is the
absolute end - so the rewrite widened the filter and `LIKE 'a'` also matched
`'a\n'`. In the 26.3 pass the grouping is per branch rather than per chain, so
only the anchored branches are kept and the rest of the chain is still
rewritten; the results are the same either way.
* `src/Analyzer/Passes/ConvertOrLikeChainPass.h` and `src/Core/Settings.cpp`
keep their 26.3 text plus a note that end-anchored patterns are never
rewritten.
* `tests/performance/optimize_or_like_chain_hits.xml` does not exist on 26.3;
the deletion is kept.
* `tests/queries/0_stateless/05055_optimize_or_like_chain_end_anchor.sql` drops
the `optimize_or_like_chain_min_patterns` setting, which 26.3 does not have,
and the comment about whole-group rejection is adjusted to the per-branch
behaviour. The expected results are unchanged.
Original pull-request: #118766
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Cherry pick #118766 to 26.3: Do not rewrite end-anchored LIKE chains into `multiMatchAny`
Backport #118766 to 26.3: Do not rewrite end-anchored LIKE chains into `multiMatchAny`
optimize_or_like_chainrewrites anORchain ofLIKE/ILIKEpredicates intomultiMatchAny, which runs the generated regexps through Vectorscan. There$follows PCRE semantics and also matches immediately before a final newline, while the originallike/ilikeuses RE2, where$means the absolute end of the string.likePatternToRegexpanchors every pattern that does not end in an unescaped%, so the rewritten predicate matched more rows than the query as written:s LIKE 'tenant-a'also returned'tenant-a\n'. With the optimization enabled by default this silently widensLIKEfilters, including filters that implement row filtering inSQL SECURITY DEFINERviews, so a user holding onlySELECTon such a view could read rows the view was written to exclude.Such chains now keep their original branches, exactly as the existing embedded-NUL and non-UTF-8 guards do. Prefix and pure-substring patterns emit no anchor and are still rewritten. One query in
tests/performance/optimize_or_like_chain_hits.xmlended with an exact pattern and is adjusted so it keeps exercising themultiMatchAnypath.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
optimize_or_like_chainreturning extra rows forORchains ofLIKE/ILIKEpatterns that do not end in%: a value followed by a trailing newline wrongly matched the filter.Workflow [PR]
Sync PR [sync-upstream/pr/118766]
Version info
26.9.1.1312(included in26.9and later)26.8.4.11,26.7.8.16,26.6.9.10,26.3.33.116