Skip to content

Extend the regexp fast-path to anchored literals - #116554

Merged
ahmadov merged 9 commits into
masterfrom
ahmadov/optimized-regex-prefix-suffix
Aug 27, 2026
Merged

ahmadov merged 9 commits into
masterfrom
ahmadov/optimized-regex-prefix-suffix

Conversation

@ahmadov

@ahmadov ahmadov commented Aug 26, 2026 •

Copy link
Copy Markdown
Member

Previously, only substring pattern 'lit' was supported in the fast-path.

However, the fast-path can be extended for more simple patterns (starts with, ends with, equals): '^lit', 'lit$' and '^lit$'.

This avoids initialization and running the RE2 engine for such patterns.

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Extend the regexp fast path to simple anchored literals: prefix, suffix, and exact-literal matches.


Workflow [PR]
Sync PR [sync-upstream/pr/116554]

Previously, only substring pattern `'lit'` was supported in the fast-path.

However, the fast-path can be extended for more simple patterns (starts with,
ends with, equals): `'^lit'`, `'lit$'` and `'^lit$'`.

This avoids running the re2 engine for such patterns.
@clickhouse-gh

clickhouse-gh Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0f70d70]

Summary: ✅


AI Review

Summary

This PR extends OptimizedRegularExpression with anchored-literal fast paths for prefix, suffix, and exact matches, wires that behavior through the row-wise match/LIKE execution paths and the text-index cache key, and adds focused unit, stateless, and performance coverage. After reconciling the earlier review threads against the current code, I did not find an unresolved correctness, compatibility, or evidence issue in the diff.

Missing context / blind spots
  • ⚠️ Full PR CI was still in progress for SHA 0f70d700feae573d94b3adc823e625f2173d5e4f while I reviewed, so this verdict is based on the current code plus the already-passed Style check, Fast test, and Build (arm_tidy) jobs rather than the remaining sanitizer/debug builds.
Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Metric Baseline Current Δ
Lines 87.30% 87.30% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 79.40% 79.40% +0.00%

Changed lines: Changed C/C++ lines covered: 221/235 (94.04%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Aug 26, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 0f70d700f with master 594c5c07f (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 712.32 MiB 709.26 MiB -3.05 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

305 translation units recompiled, 3036 s compile time in total, 305 of them have a recent master baseline.

Median compile-time ratio to the baselines is ×1.10 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +268.3 s (+10%) in total before that adjustment.

Job report

Comment thread src/Functions/MatchImpl.h Resolved
@ahmadov

ahmadov commented Aug 27, 2026

Copy link
Copy Markdown
Member Author

Perf report:
image

@Avogar Avogar self-assigned this Aug 27, 2026

@Avogar Avogar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@clickhouse-gh

clickhouse-gh Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 40 queries analysed

This PR replaces re2 with a direct byte comparison for anchored-literal patterns (^lit, lit$, ^lit$) in match/LIKE/extract; the public and private diffs are identical, so both comments describe the same change. The only flagged query is clickbench Q31, a GROUP BY aggregation that never exercises the regexp path this PR touches. Its -15.7% median is wall-clock variance only — CPU time is flat (3532 vs 3513 ms) — so the deterministic within-envelope no-change is correct and consistent with the diff. No real regressions or improvements attributable to this change appear in the flagged set.

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 3995fdfc-870e-4fa3-a154-434abafbea6a
  • MIRAI run: 894d6219-c6d1-4749-8e5a-4c1673983e76
  • PR check IDs:
    • clickbench_6283_1787847324
    • clickbench_6338_1787847325
    • clickbench_6358_1787847325
    • tpch_adapted_1_official_6627_1787847335
    • tpch_adapted_1_official_6744_1787847348
    • tpch_adapted_1_official_6948_1787847389

@ahmadov
ahmadov added this pull request to the merge queue Aug 27, 2026
Merged via the queue into master with commit 798cd34 Aug 27, 2026
179 checks passed
@ahmadov
ahmadov deleted the ahmadov/optimized-regex-prefix-suffix branch August 27, 2026 17:17
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants