Merge pull request #45244 from bigo-sg/improve_like

Add fast path for col like '%%' or col like '%'  or match(col, '.*')
This commit is contained in:
Robert Schulze 2023-01-16 08:36:20 +01:00 committed by GitHub
commit ff493c439c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -118,6 +118,16 @@ struct MatchImpl
if (haystack_offsets.empty())
return;
/// Shortcut for the silly but practical case that the pattern matches everything/nothing independently of the haystack:
/// - col [not] [i]like '%' / '%%'
/// - match(col, '.*')
if ((is_like && (needle == "%" or needle == "%%")) || (!is_like && (needle == ".*" || needle == ".*?")))
{
for (auto & x : res)
x = !negate;
return;
}
/// Special case that the [I]LIKE expression reduces to finding a substring in a string
String strstr_pattern;
if (is_like && impl::likePatternIsSubstring(needle, strstr_pattern))
@ -267,6 +277,16 @@ struct MatchImpl
if (haystack.empty())
return;
/// Shortcut for the silly but practical case that the pattern matches everything/nothing independently of the haystack:
/// - col [not] [i]like '%' / '%%'
/// - match(col, '.*')
if ((is_like && (needle == "%" or needle == "%%")) || (!is_like && (needle == ".*" || needle == ".*?")))
{
for (auto & x : res)
x = !negate;
return;
}
/// Special case that the [I]LIKE expression reduces to finding a substring in a string
String strstr_pattern;
if (is_like && impl::likePatternIsSubstring(needle, strstr_pattern))