Merge pull request #15536 from ClickHouse/fix_ilike

Separate cache for ilike after like
This commit is contained in:
alexey-milovidov 2020-10-03 02:07:40 +03:00 committed by GitHub
commit cb708212a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 10 deletions

View File

@ -141,10 +141,7 @@ struct MatchImpl
{
size_t size = offsets.size();
constexpr int flags = case_insensitive ?
Regexps::Regexp::RE_CASELESS : 0;
auto regexp = Regexps::get<like, true>(pattern, flags);
auto regexp = Regexps::get<like, true, case_insensitive>(pattern);
std::string required_substring;
bool is_trivial;

View File

@ -58,21 +58,24 @@ namespace Regexps
* You must hold the ownership while using the object.
* In destructor, it returns the object back to the Pool for further reuse.
*/
template <bool like, bool no_capture>
inline Pool::Pointer get(const std::string & pattern, int flags = 0)
template <bool like, bool no_capture, bool case_insensitive = false>
inline Pool::Pointer get(const std::string & pattern)
{
/// C++11 has thread-safe function-local statics on most modern compilers.
static Pool known_regexps; /// Different variables for different pattern parameters.
return known_regexps.get(pattern, [flags, &pattern]
return known_regexps.get(pattern, [&pattern]
{
int flags_final = flags | OptimizedRegularExpression::RE_DOT_NL;
int flags = OptimizedRegularExpression::RE_DOT_NL;
if (no_capture)
flags_final |= OptimizedRegularExpression::RE_NO_CAPTURE;
flags |= OptimizedRegularExpression::RE_NO_CAPTURE;
if (case_insensitive)
flags |= Regexps::Regexp::RE_CASELESS;
ProfileEvents::increment(ProfileEvents::RegexpCreated);
return new Regexp{createRegexp<like>(pattern, flags_final)};
return new Regexp{createRegexp<like>(pattern, flags)};
});
}
}

View File

@ -0,0 +1,4 @@
1
1
1
0

View File

@ -0,0 +1,5 @@
SELECT 'hello' like 'hell%';
SELECT 'HELLO' ilike 'hell%';
SELECT 'world' ilike 'Wo%Ld';
SELECT 'world' like 'Wo%Ld';