Skip to content

Extend the regexp anchored-literal fast-path to escaped non-alphanumerics - #117331

Merged
ahmadov merged 2 commits into
masterfrom
ahmadov/optimized-regex-2
Sep 3, 2026
Merged

ahmadov merged 2 commits into
masterfrom
ahmadov/optimized-regex-2

Conversation

@ahmadov

@ahmadov ahmadov commented Aug 31, 2026 •

Copy link
Copy Markdown
Member

RE2 resolves a backslash before any non-alphanumeric character to that character itself, so such an escape is part of a literal.

The analysis only accepted a fixed list of escaped metacharacters, which left RE2::QuoteMeta output on the re2 path, it escapes every non-alphanumeric byte, so a needle containing a space, % or : was not recognized as an anchored literal.

Changelog category (leave one):

  • Performance Improvement

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

Anchored literal regular expressions whose literal contains an escaped character, such as ^https\:// or \%3D$, are now matched by a comparison instead of the regular expression engine. This speeds up match, extract, countMatches, regexpPosition and LIKE queries.


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

Version info

  • Merged into: 26.9.1.581 (included in 26.9 and later)

…rics

RE2 resolves a backslash before any non-alphanumeric character to that
character itself, so such an escape is part of a literal.

The analysis only accepted a fixed list of escaped metacharacters, which
left `RE2::QuoteMeta` output on the re2 path: it escapes every
non-alphanumeric byte, so a needle containing a space, `%` or `:` was
not recognized as an anchored literal.
@clickhouse-gh

clickhouse-gh Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f37ac84]

Summary: ❌

job_name test_name status info comment
LLVM Coverage FAIL
Generate LLVM Coverage Diff Report FAIL cidb IGNORED
Print Uncovered Code FAIL cidb IGNORED
Stress test (arm_asan_ubsan, s3) ERROR IGNORED
Parser memory check ERROR
Resolve master binary ERROR IGNORED

AI Review

Summary

This PR broadens the anchored-literal regexp fast path to accept RE2-style escapes of non-alphanumeric bytes, so patterns such as ^https\\:// and \\%3D$ can stay on the byte-comparison path instead of falling back to re2. I did not find a remaining correctness, safety, or evidence gap in the current version of the change.

Final Verdict

Status: ✅ Approve

LLVM Coverage Report

⚠️ No coverage measurement for commit f37ac84: bash ci/jobs/scripts/generate_diff_coverage_report.sh failed (its output is on the Generate LLVM Coverage Diff Report result).

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Aug 31, 2026
@ahmadov
ahmadov requested a review from rschu1ze August 31, 2026 15:01
@clickhouse-gh

clickhouse-gh Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

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

no significant changes detected. K_source=6 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 576868ec-2db6-4841-b8c5-159d0774d02e
  • MIRAI run: db6a2325-548d-4412-822e-d12ae25de62a
  • PR check IDs:
    • clickbench_930628_1788377819
    • clickbench_930634_1788377819
    • clickbench_930640_1788377819
    • tpch_adapted_1_official_930651_1788377819
    • tpch_adapted_1_official_930663_1788377819
    • tpch_adapted_1_official_930699_1788377819

@clickhouse-gh

clickhouse-gh Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing f37ac84f2 with master 84ac4b282 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of bb3c0a852; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

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

Job report

@rschu1ze rschu1ze self-assigned this Sep 2, 2026
@ahmadov
ahmadov added this pull request to the merge queue Sep 3, 2026
Merged via the queue into master with commit 5eda964 Sep 3, 2026
502 of 515 checks passed
@ahmadov
ahmadov deleted the ahmadov/optimized-regex-2 branch September 3, 2026 10:23
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 3, 2026
pull Bot pushed a commit to AnotherGenZ/ClickHouse that referenced this pull request Sep 24, 2026
Canonicalize coverage paths, fail selection on stale or incompatible
snapshots, and replace broad admission with precise coverage evidence.
Protect changed and previously failed tests under a unified ceiling.

Persist one selection manifest per PR SHA, validate nightly shard exports,
and report repeated execution. Keep entry-count scoring experiments and
the expanded targeted matrix gated on historical evaluation. Durable CIDB
run identity remains dependent on an external schema migration.

Related: ClickHouse#117331
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