From 536bd62f5411ece8ae9d9c7ec0f6069ea39e3be1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Wed, 28 Jun 2023 09:46:19 +0000 Subject: [PATCH] Add support for optimizer_switch syntax --- lib/set_parser.cpp | 16 ++++++++++++++-- test/tap/tests/setparser_test_common.h | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/set_parser.cpp b/lib/set_parser.cpp index 73e072536..a57890a83 100644 --- a/lib/set_parser.cpp +++ b/lib/set_parser.cpp @@ -15,7 +15,7 @@ static void remove_quotes(string& v) { char firstChar = v[0]; char lastChar = v[v.length()-1]; if (firstChar == lastChar) { - if (firstChar == '\'' || firstChar == '"') { + if (firstChar == '\'' || firstChar == '"' || firstChar == '`') { v.erase(v.length()-1, 1); v.erase(0, 1); } @@ -182,7 +182,19 @@ void SetParser::generateRE_parse1v2() { var_patterns.push_back(s); // add with quote } - + // regex for optimizer_switch + { + string v1 = "(?:on|off)"; // on|off + string v2 = "\\w+=" + v1; // "\\w+=(?:on|off)" , example: index_merge_sort_union=on + string v3 = v2 + "(?:," + v2 + ")*"; // "\\w+=(?:on|off)(?:,\\w+=(?:on|off))*" + // example index_merge=on,index_merge_union=on,index_merge_sort_union=off + // note: spaces are not allowed + // NOTE: the whole set of flags must be quoted + for (auto it = quote_symbol.begin(); it != quote_symbol.end(); it++) { + string s = *it + v3 + *it; + var_patterns.push_back(s); // add with quote + } + } // DO NOT REMOVE THIS COMMENTED CODE diff --git a/test/tap/tests/setparser_test_common.h b/test/tap/tests/setparser_test_common.h index 9392a376e..9c8e50d96 100644 --- a/test/tap/tests/setparser_test_common.h +++ b/test/tap/tests/setparser_test_common.h @@ -191,6 +191,8 @@ static Test various[] = { { "SET SESSION sql_safe_updates = 1", { Expected("sql_safe_updates", {"1"}) } }, { "SET SQL_SAFE_UPDATES = OFF", { Expected("sql_safe_updates", {"OFF"}) } }, { "SET @@sql_safe_updates = ON", { Expected("sql_safe_updates", {"ON"}) } }, + { "SET optimizer_switch=`index_merge=OFF`" , { Expected("optimizer_switch", {"index_merge=OFF"}) } }, + { "SET optimizer_switch='index_merge=on,index_merge_union=off,index_merge_sort_union=on'" , { Expected("optimizer_switch", {"index_merge=on,index_merge_union=off,index_merge_sort_union=on"}) } }, }; static Test multiple[] = {