Skip to content

Cherry pick #118766 to 26.3: Do not rewrite end-anchored LIKE chains into multiMatchAny - #119910

Merged
robot-ch-test-poll merged 7 commits into
backport/26.3/118766from
cherrypick/26.3/118766
Sep 19, 2026
Merged

robot-ch-test-poll merged 7 commits into
backport/26.3/118766from
cherrypick/26.3/118766

Conversation

@robot-ch-test-poll4

Copy link
Copy Markdown
Contributor

Original pull-request #118766

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

@robot-ch-test-poll4 robot-ch-test-poll4 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Sep 14, 2026
@robot-ch-test-poll3

Copy link
Copy Markdown
Contributor

Dear @Ergus, @alexey-milovidov, this cherry-pick PR has not been updated for 3d0h6m53s. Please resolve the conflicts to backport #118766, or close this PR if the backport is no longer needed. This PR will be automatically closed after 7 days of inactivity.

@PedroTadim

Copy link
Copy Markdown
Member

This cherry-pick cannot be resolved as-is: it is a follow-up fix to a rework that this branch does not have.

Why it conflicts

The fix is written against the ConvertOrLikeChainPass rework from #94517, merged to master on 2026-07-13. That rework is on 26.7 and 26.8 but not on 26.3 or 26.6, and the split matches the cherry-pick outcomes exactly:

branch ConvertOrLikeChainPass.cpp PatternData / PatternInfo optimize_or_like_chain default cherry-pick
26.8 632 lines yes true merged clean
26.7 630 lines yes true merged clean
26.6 175 lines no false conflicts
26.3 175 lines no false conflicts

Every conflict is that gap, not a real divergence in the fix:

  • src/Analyzer/Passes/ConvertOrLikeChainPass.cpp — the fix adds may_have_end_anchor to PatternData and allRegexpsHaveNoEndAnchor to PatternInfo, and wires the latter into the multiMatchAny eligibility test. Neither struct exists here; the old pass has no eligibility checks at all and converts every like / ilike directly into multiMatchAny.
  • src/Analyzer/Passes/ConvertOrLikeChainPass.h and src/Core/Settings.cpp — both conflicts are documentation text describing master-only behaviour (indexHint preservation, the multiSearchAny path, optimize_or_like_chain_min_patterns and optimize_or_like_chain_min_substrings).
  • tests/performance/optimize_or_like_chain_hits.xml — modify/delete; the file does not exist on this branch.
  • tests/queries/0_stateless/05055_optimize_or_like_chain_end_anchor.sql merges without conflict but cannot run: its first statement is SET optimize_or_like_chain_min_patterns = 1, a setting Enable optimize_or_like_chain by default. #94517 introduced. Every query in it would fail with an unknown-setting exception.

Only src/Common/likePatternToRegexp.{h,cpp}, which add the has_end_anchor out-parameter, apply cleanly.

Impact on this branch

The underlying problem is real here too: likePatternToRegexp appends $, the result is handed to multiMatchAny, and Vectorscan's $ also matches before a final newline, so s LIKE 'tenant-a' additionally returns 'tenant-a\n'.

However, #94517 is also what flipped optimize_or_like_chain from false to true. On this branch it is still false, so the rewrite — and therefore the widened filter — only happens for users who enable the setting explicitly.

Suggested resolution

Close this PR. Landing the fix here means hand-writing a different change against the old 175-line pass, dropping the performance test, and rewriting the stateless test without the setting it depends on — a new backport rather than a cherry-pick, for a path that is off by default on this branch. Backporting #94517 itself is not a reasonable alternative: it is a 175→630-line rewrite of the pass plus three new settings and a default flip, on a stable release branch.

If the fix is wanted here regardless, it should be raised as a separate, branch-specific PR.

🤖 Generated with Claude Code

…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]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Conflicts resolved; the PR is MERGEABLE now.

@PedroTadim's analysis above is accurate: this is a follow-up to the ConvertOrLikeChainPass rework from #94517, which 26.3 does not have. I took the other branch of his conclusion and adapted the fix to the 175-line pass on 26.3 instead of closing, because the adaptation turned out to be small and the underlying wrong-results bug is real on this branch too.

How each conflict was resolved:

  • src/Common/likePatternToRegexp.{h,cpp} — merged cleanly, taken as is. likePatternToRegexp reports through the optional has_end_anchor out-parameter whether it emitted a trailing $. All other callers on this branch use the one-argument form and are unaffected by the defaulted parameter.
  • src/Analyzer/Passes/ConvertOrLikeChainPass.cpp — keeps the 26.3 pass and adds the end-anchor check to it directly. A {i}like branch whose regexp ends with $ is left as the original branch instead of being folded into multiMatchAny. Master rejects the whole group because PatternInfo collects the patterns first; the 26.3 pass decides per branch, so only the anchored branches are kept and the rest of the chain is still rewritten. Both are result-preserving and produce the same answers.
  • src/Analyzer/Passes/ConvertOrLikeChainPass.h, src/Core/Settings.cpp — keep the 26.3 text (including optimize_or_like_chain defaulting to false) plus one sentence stating that end-anchored patterns are never rewritten. None of the master-only prose about indexHint, multiSearchAny or the optimize_or_like_chain_min_* thresholds was pulled in.
  • tests/performance/optimize_or_like_chain_hits.xml — modify/delete, the deletion is kept; the file does not exist on 26.3.
  • tests/queries/0_stateless/05055_optimize_or_like_chain_end_anchor.sql — the SET optimize_or_like_chain_min_patterns = 1 line is dropped (Enable optimize_or_like_chain by default. #94517 introduced that setting), and the comment about whole-group rejection is reworded for the per-branch behaviour. The 26.3 pass has no minimum-branch threshold, so the two-branch chains in the test are rewritten without it, and the expected results are unchanged. There is no test number collision on this branch.

The net diff against backport/26.3/118766 is exactly those seven files, and ConvertOrLikeChainPass.cpp compiles.

One thing worth a separate decision, deliberately left out of this cherry-pick: 26.3 still carries the old-analyzer twin of this optimization in src/Interpreters/ConvertFunctionOrLikeVisitor.cpp, which feeds likePatternToRegexp output into multiMatchAny in the same way and therefore has the identical $-before-final-newline behaviour with enable_analyzer = 0. Master has no equivalent change to cherry-pick, so fixing it here would be a new, branch-specific change rather than a backport. As noted above, optimize_or_like_chain is false by default on 26.3, so both paths are opt-in.

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants