executor: Fix LIKE with non-ASCII patterns on unsigned-char platforms - #11038
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe change updates ASCII case-insensitive collation pattern compilation and matching. It validates byte values, handles non-ASCII data safely, preserves wildcard types, and collapses consecutive ChangesASCII CI matching
Estimated code review effort: 3 (Moderate) | ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
dbms/src/TiDB/Collation/Collator.cpp (1)
137-190: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse
UInt8for byte conversions.Replace raw
unsigned charwithUInt8forunsigned_escapeand each converted input byte. This keeps byte-width types consistent with the repository type policy.As per coding guidelines, “Use explicit width types from
dbms/src/Core/Types.h:UInt8,UInt32,Int64,Float64,String.”Proposed fix
-const auto unsigned_escape = static_cast<unsigned char>(escape); +const auto unsigned_escape = static_cast<UInt8>(escape); -auto c = static_cast<unsigned char>(pattern[i]); +auto c = static_cast<UInt8>(pattern[i]); -c = static_cast<unsigned char>(pattern[++i]); +c = static_cast<UInt8>(pattern[++i]); -const auto c = static_cast<unsigned char>(s[str_idx]); +const auto c = static_cast<UInt8>(s[str_idx]); -const auto c = static_cast<unsigned char>(s[str_idx]); +const auto c = static_cast<UInt8>(s[str_idx]);Also applies to: 319-325, 360-367
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@dbms/src/TiDB/Collation/Collator.cpp` around lines 137 - 190, In the collator pattern-processing logic, replace the raw unsigned char types used for unsigned_escape and converted pattern bytes with UInt8, including the corresponding conversions in the additional affected sections. Keep the existing escape handling and ASCII-range validation unchanged.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@dbms/src/TiDB/Collation/Collator.cpp`:
- Around line 137-190: In the collator pattern-processing logic, replace the raw
unsigned char types used for unsigned_escape and converted pattern bytes with
UInt8, including the corresponding conversions in the additional affected
sections. Keep the existing escape handling and ASCII-range validation
unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 45b56cd4-fc84-4379-883c-981bdbbd3806
📒 Files selected for processing (2)
dbms/src/TiDB/Collation/Collator.cppdbms/src/TiDB/tests/gtest_tidb_collator.cpp
|
/retest |
4 similar comments
|
/retest |
|
/retest |
|
/retest |
|
/retest |
|
/retest |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: windtalker, xzhangxian1008 The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
|
In response to a cherrypick label: cannot checkout |
|
In response to a cherrypick label: cannot checkout |
|
效率太高了,点赞。 |
|
/cherry-pick release-nextgen-202603 |
|
@JaySon-Huang: new pull request created to branch DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
What problem does this PR solve?
Issue Number: close #11037
Problem Summary
LIKEpattern matching can produce incorrect results for non-ASCII patterns on platforms wherecharis unsigned, such as Linux AArch64.The implementation used
charvalues as sentinel states while scanning UTF-8 characters. Bytes greater than0x7Fwere interpreted differently whencharis unsigned, causing the matcher to incorrectly handle escaped non-ASCII characters and patterns containing UTF-8 literals.The initial correctness fix avoided the signedness-dependent behavior, but introduced an extra per-character decoding cost in the hot matching path. This could cause a measurable performance regression for common
LIKEworkloads on AArch64.What is changed and how it works
charsentinel handling in theLIKEmatcher with an explicit representation that works consistently regardless of whether the compiler treatscharas signed or unsigned.As a result,
LIKEmatching is correct for non-ASCII patterns on unsigned-charplatforms, without giving up the substantial performance benefit of the prior optimized implementation.Check List
Tests
Side effects
Documentation
Release note
Summary by CodeRabbit
Bug Fixes
Tests