HappenLee commented on code in PR #66788:
URL: https://github.com/apache/doris/pull/66788#discussion_r3785432784
##########
be/src/exprs/function/like.cpp:
##########
@@ -36,6 +37,109 @@
#include "exprs/function/simple_function_factory.h"
namespace doris {
+namespace {
+
+bool is_larger_than_fifty(std::string_view str) {
+ int number = 0;
+ auto [_, error] = std::from_chars(str.data(), str.data() + str.size(),
number);
+ return error == std::errc() && number > 50;
+}
+
+std::string mask_escaped_characters_and_character_classes(std::string_view
regexp) {
+ std::string masked_regexp(regexp);
+ bool escaped = false;
+ bool in_character_class = false;
+ bool character_class_can_close = false;
+ for (char& masked_character : masked_regexp) {
+ const char current = masked_character;
+ if (escaped) {
+ masked_character = ' ';
+ escaped = false;
+ if (in_character_class) {
+ character_class_can_close = true;
+ }
+ continue;
+ }
+ if (current == '\\') {
+ masked_character = ' ';
+ escaped = true;
+ continue;
+ }
+ if (in_character_class) {
+ masked_character = ' ';
+ if (current == ']' && character_class_can_close) {
+ in_character_class = false;
+ } else if (current != '^' || character_class_can_close) {
+ character_class_can_close = true;
+ }
+ continue;
+ }
+ if (current == '[') {
+ masked_character = ' ';
+ in_character_class = true;
+ character_class_can_close = false;
+ }
+ }
+ return masked_regexp;
+}
+
+/// Bounded repetitions can expand Hyperscan's compiler graph and make
compilation extremely
+/// expensive. This checker is adapted from ClickHouse's
`SlowWithHyperscanChecker`.
+class SlowWithHyperscanChecker {
+public:
+ SlowWithHyperscanChecker()
+ : _searcher_one_repeat(R"(\{\s*([\d]+)\s*,?\s*})"),
+ _searcher_two_repeats(R"(\{\s*([\d]+)\s*,\s*([\d]+)\s*\})") {}
+
+ bool is_slow(std::string_view regexp) const {
+ const std::string masked_regexp =
mask_escaped_characters_and_character_classes(regexp);
+ return is_slow_one_repeat(masked_regexp) ||
is_slow_two_repeats(masked_regexp);
Review Comment:
That's fine and it meets expectations.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]