| 1 | #pragma once |
|---|---|
| 2 | |
| 3 | #include <Parsers/IAST.h> |
| 4 | #include <Parsers/ASTQueryWithTableAndOutput.h> |
| 5 | #include <Parsers/ASTQueryWithOnCluster.h> |
| 6 | |
| 7 | namespace DB |
| 8 | { |
| 9 | |
| 10 | |
| 11 | /** OPTIMIZE query |
| 12 | */ |
| 13 | class ASTOptimizeQuery : public ASTQueryWithTableAndOutput, public ASTQueryWithOnCluster |
| 14 | { |
| 15 | public: |
| 16 | /// The partition to optimize can be specified. |
| 17 | ASTPtr partition; |
| 18 | /// A flag can be specified - perform optimization "to the end" instead of one step. |
| 19 | bool final; |
| 20 | /// Do deduplicate (default: false) |
| 21 | bool deduplicate; |
| 22 | |
| 23 | /** Get the text that identifies this element. */ |
| 24 | String getID(char delim) const override |
| 25 | { |
| 26 | return "OptimizeQuery"+ (delim + database) + delim + table + (final ? "_final": "") + (deduplicate ? "_deduplicate": ""); |
| 27 | } |
| 28 | |
| 29 | ASTPtr clone() const override |
| 30 | { |
| 31 | auto res = std::make_shared<ASTOptimizeQuery>(*this); |
| 32 | res->children.clear(); |
| 33 | |
| 34 | if (partition) |
| 35 | { |
| 36 | res->partition = partition->clone(); |
| 37 | res->children.push_back(res->partition); |
| 38 | } |
| 39 | |
| 40 | return res; |
| 41 | } |
| 42 | |
| 43 | void formatQueryImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override; |
| 44 | |
| 45 | ASTPtr getRewrittenASTWithoutOnCluster(const std::string &new_database) const override |
| 46 | { |
| 47 | return removeOnCluster<ASTOptimizeQuery>(clone(), new_database); |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | } |
| 52 |