Skip to content

Commit

Permalink
Backport #54696 to 23.8: Fix: avoid using regex match, possibly conta…
Browse files Browse the repository at this point in the history
…ining alternation, as a key condition.
  • Loading branch information
robot-clickhouse committed Nov 2, 2023
1 parent f6d503e commit 378b062
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Storages/MergeTree/KeyCondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,12 @@ const KeyCondition::AtomMap KeyCondition::atom_map
if (value.getType() != Field::Types::String)
return false;

String prefix = extractFixedPrefixFromRegularExpression(value.get<const String &>());
const String & expression = value.get<const String &>();
// This optimization can't process alternation - this would require a comprehensive parsing of regular expression.
if (expression.contains('|'))
return false;

String prefix = extractFixedPrefixFromRegularExpression(expression);
if (prefix.empty())
return false;

Expand Down
1 change: 1 addition & 0 deletions tests/queries/0_stateless/02462_match_regexp_pk.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ SELECT count() FROM mt_match_pk WHERE match(v, '^ab');
SELECT count() FROM mt_match_pk WHERE match(v, '^a.');
SELECT count() FROM mt_match_pk WHERE match(v, '^ab*');
SELECT count() FROM mt_match_pk WHERE match(v, '^ac?');
SELECT count() FROM mt_match_pk WHERE match(v, '^a$|^b'); -- {serverError INDEX_NOT_USED}

0 comments on commit 378b062

Please sign in to comment.