2012-07-31 19:08:49 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/IAST.h>
|
2012-07-31 19:08:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2017-05-27 17:27:16 +00:00
|
|
|
/** OPTIMIZE query
|
2012-07-31 19:08:49 +00:00
|
|
|
*/
|
|
|
|
class ASTOptimizeQuery : public IAST
|
|
|
|
{
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
String database;
|
|
|
|
String table;
|
2012-07-31 19:08:49 +00:00
|
|
|
|
2017-05-27 17:27:16 +00:00
|
|
|
/// The partition to optimize can be specified.
|
2017-09-06 20:34:26 +00:00
|
|
|
ASTPtr partition;
|
2017-05-27 17:27:16 +00:00
|
|
|
/// A flag can be specified - perform optimization "to the end" instead of one step.
|
2017-04-01 07:20:54 +00:00
|
|
|
bool final;
|
2017-04-13 13:13:08 +00:00
|
|
|
/// Do deduplicate (default: false)
|
|
|
|
bool deduplicate;
|
2016-05-16 18:43:38 +00:00
|
|
|
|
2017-05-27 17:27:16 +00:00
|
|
|
/** Get the text that identifies this element. */
|
2018-06-03 20:39:06 +00:00
|
|
|
String getID() const override { return "OptimizeQuery_" + database + "_" + table + (final ? "_final" : "") + (deduplicate ? "_deduplicate" : ""); }
|
2012-07-31 19:08:49 +00:00
|
|
|
|
2017-09-06 20:34:26 +00:00
|
|
|
ASTPtr clone() const override
|
|
|
|
{
|
|
|
|
auto res = std::make_shared<ASTOptimizeQuery>(*this);
|
|
|
|
res->children.clear();
|
|
|
|
|
|
|
|
if (partition)
|
|
|
|
{
|
|
|
|
res->partition = partition->clone();
|
|
|
|
res->children.push_back(res->partition);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2015-08-05 21:38:31 +00:00
|
|
|
|
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
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);
|
|
|
|
|
2017-09-06 20:34:26 +00:00
|
|
|
if (partition)
|
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << " PARTITION " << (settings.hilite ? hilite_none : "");
|
|
|
|
partition->formatImpl(settings, state, frame);
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
if (final)
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << " FINAL" << (settings.hilite ? hilite_none : "");
|
2017-04-13 13:13:08 +00:00
|
|
|
|
|
|
|
if (deduplicate)
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << " DEDUPLICATE" << (settings.hilite ? hilite_none : "");
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2012-07-31 19:08:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|