Optimize string conversion comparison - #110744
Conversation
|
Workflow [PR], commit [9f45d6e] Summary: ❌
AI ReviewSummaryThis PR adds PR Metadata
Suggested replacement: Optimize Findings❌ Blockers
Tests
Final Verdict❌ Changes requested. |
Added new settings for optimization and compatibility.
| if (i + 1 < pattern.size()) | ||
| result += pattern[++i]; | ||
| else | ||
| result += c; |
There was a problem hiding this comment.
LIKE patterns ending with a backslash are supposed to raise CANNOT_PARSE_ESCAPE_SEQUENCE, but extractLikeRequiredChars treats the trailing \ as a literal required byte. That means toString(number) LIKE '%\\' can be pruned to 0 (and NOT LIKE to 1) instead of preserving the existing exception. Can we validate or reject invalid patterns before using this helper for pruning?
|
|
||
| bool has_string_elements = false; | ||
| for (const auto & element_type : tuple_type->getElements()) | ||
| has_string_elements |= isStringOrFixedString(removeLowCardinality(element_type)); |
There was a problem hiding this comment.
The escape-sequence guard here only recognizes String / FixedString, but tuple elements of type Dynamic, Variant, and JSON also go through serializeTextQuoted inside tuples while scalar toString uses raw serializeText. For a Dynamic string value a\nb, toString((x, 1)) LIKE '%nb%' matches the escaped tuple rendering, while the rewritten toString(x) LIKE '%nb%' runs on the raw newline and returns false. This rewrite needs to exclude every type whose quoted serialization can inject escapes, not just plain strings.
|
📊 Cloud Performance Report ✅ AI verdict: This PR adds a single analyzer pass (OptimizeStringConversionComparisonPass) that only rewrites expressions of the form op(toString(x), 'constant') where op is equals/like/ilike/position over restricted-alphabet types like numbers, dates and tuples of them. None of the flagged clickbench queries (Q8 aggregation, Q18, Q34) use that idiom, so the pass cannot plausibly change their execution time. The flagged +10.8% (Q8) and +10.4% (Q18) are off the changed code path — Q8's source runs were also extremely noisy — so both were downgraded to not_sure, and Q34 was already correctly held within master's variance band. clickbenchFlagged queries (3 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
Closes: #108955
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Type-based pruning of expressions involving toString