From a4ae50ad1265c6422951817d1442b6b7f52b86d4 Mon Sep 17 00:00:00 2001 From: ywqzzy <592838129@qq.com> Date: Wed, 6 Apr 2022 15:47:03 +0800 Subject: [PATCH] update. Signed-off-by: ywqzzy <592838129@qq.com> --- dbms/src/Interpreters/InterpreterFactory.cpp | 7 -- .../Interpreters/InterpreterOptimizeQuery.cpp | 43 ---------- .../Interpreters/InterpreterOptimizeQuery.h | 46 ---------- dbms/src/Parsers/ASTOptimizeQuery.h | 76 ---------------- dbms/src/Parsers/ParserOptimizeQuery.cpp | 86 ------------------- dbms/src/Parsers/ParserOptimizeQuery.h | 33 ------- dbms/src/Parsers/ParserQuery.cpp | 21 ++--- 7 files changed, 8 insertions(+), 304 deletions(-) delete mode 100644 dbms/src/Interpreters/InterpreterOptimizeQuery.cpp delete mode 100644 dbms/src/Interpreters/InterpreterOptimizeQuery.h delete mode 100644 dbms/src/Parsers/ASTOptimizeQuery.h delete mode 100644 dbms/src/Parsers/ParserOptimizeQuery.cpp delete mode 100644 dbms/src/Parsers/ParserOptimizeQuery.h diff --git a/dbms/src/Interpreters/InterpreterFactory.cpp b/dbms/src/Interpreters/InterpreterFactory.cpp index 5231bbd3dd6..631df49227e 100644 --- a/dbms/src/Interpreters/InterpreterFactory.cpp +++ b/dbms/src/Interpreters/InterpreterFactory.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -45,7 +44,6 @@ #include #include #include -#include #include #include #include @@ -126,11 +124,6 @@ std::unique_ptr InterpreterFactory::get(ASTPtr & query, Context & /// readonly is checked inside InterpreterSetQuery return std::make_unique(query, context); } - else if (typeid_cast(query.get())) - { - throwIfReadOnly(context); - return std::make_unique(query, context); - } else if (typeid_cast(query.get())) { return std::make_unique(query, context); diff --git a/dbms/src/Interpreters/InterpreterOptimizeQuery.cpp b/dbms/src/Interpreters/InterpreterOptimizeQuery.cpp deleted file mode 100644 index 173065512b8..00000000000 --- a/dbms/src/Interpreters/InterpreterOptimizeQuery.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2022 PingCAP, Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include -#include -#include -#include - - -namespace DB -{ -namespace ErrorCodes -{ -extern const int BAD_ARGUMENTS; -} - - -BlockIO InterpreterOptimizeQuery::execute() -{ - const ASTOptimizeQuery & ast = typeid_cast(*query_ptr); - - if (ast.final && !ast.partition) - throw Exception("FINAL flag for OPTIMIZE query is meaningful only with specified PARTITION", ErrorCodes::BAD_ARGUMENTS); - - StoragePtr table = context.getTable(ast.database, ast.table); - auto table_lock = table->lockStructureForShare(RWLock::NO_QUERY); - table->optimize(query_ptr, ast.partition, ast.final, ast.deduplicate, context); - return {}; -} - -} // namespace DB diff --git a/dbms/src/Interpreters/InterpreterOptimizeQuery.h b/dbms/src/Interpreters/InterpreterOptimizeQuery.h deleted file mode 100644 index bf39aba9c71..00000000000 --- a/dbms/src/Interpreters/InterpreterOptimizeQuery.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2022 PingCAP, Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -#include - - -namespace DB -{ -class Context; -class IAST; -using ASTPtr = std::shared_ptr; - - -/** Just call method "optimize" for table. - */ -class InterpreterOptimizeQuery : public IInterpreter -{ -public: - InterpreterOptimizeQuery(const ASTPtr & query_ptr_, Context & context_) - : query_ptr(query_ptr_) - , context(context_) - { - } - - BlockIO execute() override; - -private: - ASTPtr query_ptr; - Context & context; -}; - - -} // namespace DB diff --git a/dbms/src/Parsers/ASTOptimizeQuery.h b/dbms/src/Parsers/ASTOptimizeQuery.h deleted file mode 100644 index 17d9e6ab41a..00000000000 --- a/dbms/src/Parsers/ASTOptimizeQuery.h +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2022 PingCAP, Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -#include - - -namespace DB -{ - - -/** OPTIMIZE query - */ -class ASTOptimizeQuery : public IAST -{ -public: - String database; - String table; - - /// The partition to optimize can be specified. - ASTPtr partition; - /// A flag can be specified - perform optimization "to the end" instead of one step. - bool final; - /// Do deduplicate (default: false) - bool deduplicate; - - /** Get the text that identifies this element. */ - String getID() const override { return "OptimizeQuery_" + database + "_" + table + (final ? "_final" : "") + (deduplicate ? "_deduplicate" : ""); }; - - ASTPtr clone() const override - { - auto res = std::make_shared(*this); - res->children.clear(); - - if (partition) - { - res->partition = partition->clone(); - res->children.push_back(res->partition); - } - - return res; - } - -protected: - void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override - { - settings.ostr << (settings.hilite ? hilite_keyword : "") << "OPTIMIZE TABLE " << (settings.hilite ? hilite_none : "") - << (!database.empty() ? backQuoteIfNeed(database) + "." : "") << backQuoteIfNeed(table); - - if (partition) - { - settings.ostr << (settings.hilite ? hilite_keyword : "") << " PARTITION " << (settings.hilite ? hilite_none : ""); - partition->formatImpl(settings, state, frame); - } - - if (final) - settings.ostr << (settings.hilite ? hilite_keyword : "") << " FINAL" << (settings.hilite ? hilite_none : ""); - - if (deduplicate) - settings.ostr << (settings.hilite ? hilite_keyword : "") << " DEDUPLICATE" << (settings.hilite ? hilite_none : ""); - } -}; - -} diff --git a/dbms/src/Parsers/ParserOptimizeQuery.cpp b/dbms/src/Parsers/ParserOptimizeQuery.cpp deleted file mode 100644 index 1b5f82ff682..00000000000 --- a/dbms/src/Parsers/ParserOptimizeQuery.cpp +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2022 PingCAP, Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include -#include - -#include -#include -#include - -#include - - -namespace DB -{ - - -bool ParserOptimizeQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) -{ - ParserKeyword s_optimize_table("OPTIMIZE TABLE"); - ParserKeyword s_partition("PARTITION"); - ParserKeyword s_final("FINAL"); - ParserKeyword s_deduplicate("DEDUPLICATE"); - ParserToken s_dot(TokenType::Dot); - ParserIdentifier name_p; - ParserPartition partition_p; - - ASTPtr database; - ASTPtr table; - ASTPtr partition; - bool final = false; - bool deduplicate = false; - - if (!s_optimize_table.ignore(pos, expected)) - return false; - - if (!name_p.parse(pos, table, expected)) - return false; - - if (s_dot.ignore(pos, expected)) - { - database = table; - if (!name_p.parse(pos, table, expected)) - return false; - } - - if (s_partition.ignore(pos, expected)) - { - if (!partition_p.parse(pos, partition, expected)) - return false; - } - - if (s_final.ignore(pos, expected)) - final = true; - - if (s_deduplicate.ignore(pos, expected)) - deduplicate = true; - - auto query = std::make_shared(); - node = query; - - if (database) - query->database = typeid_cast(*database).name; - if (table) - query->table = typeid_cast(*table).name; - query->partition = partition; - query->final = final; - query->deduplicate = deduplicate; - - return true; -} - - -} diff --git a/dbms/src/Parsers/ParserOptimizeQuery.h b/dbms/src/Parsers/ParserOptimizeQuery.h deleted file mode 100644 index c12cfb80c90..00000000000 --- a/dbms/src/Parsers/ParserOptimizeQuery.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2022 PingCAP, Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -#include -#include - - -namespace DB -{ - -/** Query OPTIMIZE TABLE [db.]name [PARTITION partition] [FINAL] [DEDUPLICATE] - */ -class ParserOptimizeQuery : public IParserBase -{ -protected: - const char * getName() const { return "OPTIMIZE query"; } - bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); -}; - -} diff --git a/dbms/src/Parsers/ParserQuery.cpp b/dbms/src/Parsers/ParserQuery.cpp index f6bb7d8ca32..4e20221df82 100644 --- a/dbms/src/Parsers/ParserQuery.cpp +++ b/dbms/src/Parsers/ParserQuery.cpp @@ -12,26 +12,23 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include -#include +#include #include -#include -#include #include +#include #include +#include +#include +#include +#include #include -#include -#include #include -#include #include #include -#include +#include namespace DB { - - bool ParserQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { ParserQueryWithOutput query_with_output_p; @@ -40,7 +37,6 @@ bool ParserQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) ParserSetQuery set_p; ParserDeleteQuery delete_p; ParserDBGInvokeQuery dbginvoke_p; - ParserOptimizeQuery optimize_p; ParserSystemQuery system_p; ParserTruncateQuery truncate_p; ParserManageQuery manage_p; @@ -51,7 +47,6 @@ bool ParserQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) || set_p.parse(pos, node, expected) || delete_p.parse(pos, node, expected) || dbginvoke_p.parse(pos, node, expected) - || optimize_p.parse(pos, node, expected) || system_p.parse(pos, node, expected) || truncate_p.parse(pos, node, expected) || manage_p.parse(pos, node, expected); @@ -59,4 +54,4 @@ bool ParserQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) return res; } -} +} // namespace DB