2019-03-15 13:49:58 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Core/QueryProcessingStage.h>
|
2021-07-31 07:45:26 +00:00
|
|
|
#include <optional>
|
2019-03-15 13:49:58 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* to_stage
|
|
|
|
* - the stage to which the query is to be executed. By default - till to the end.
|
|
|
|
* You can perform till the intermediate aggregation state, which are combined from different servers for distributed query processing.
|
|
|
|
*
|
|
|
|
* subquery_depth
|
|
|
|
* - to control the limit on the depth of nesting of subqueries. For subqueries, a value that is incremented by one is passed;
|
|
|
|
* for INSERT SELECT, a value 1 is passed instead of 0.
|
|
|
|
*
|
|
|
|
* only_analyze
|
|
|
|
* - the object was created only for query analysis.
|
2019-03-15 15:57:18 +00:00
|
|
|
*
|
|
|
|
* is_subquery
|
|
|
|
* - there could be some specific for subqueries. Ex. there's no need to pass duplicated columns in results, cause of indirect results.
|
2020-12-18 06:54:38 +00:00
|
|
|
*
|
|
|
|
* is_internal
|
|
|
|
* - the object was created only for internal queries.
|
2019-03-15 13:49:58 +00:00
|
|
|
*/
|
2019-03-18 12:05:51 +00:00
|
|
|
struct SelectQueryOptions
|
2019-03-15 13:49:58 +00:00
|
|
|
{
|
2019-03-18 12:05:51 +00:00
|
|
|
QueryProcessingStage::Enum to_stage;
|
|
|
|
size_t subquery_depth;
|
2019-11-11 01:11:32 +00:00
|
|
|
bool only_analyze = false;
|
|
|
|
bool modify_inplace = false;
|
|
|
|
bool remove_duplicates = false;
|
|
|
|
bool ignore_quota = false;
|
|
|
|
bool ignore_limits = false;
|
2021-04-22 08:43:35 +00:00
|
|
|
/// This flag is needed to analyze query ignoring table projections.
|
|
|
|
/// It is needed because we build another one InterpreterSelectQuery while analyzing projections.
|
|
|
|
/// It helps to avoid infinite recursion.
|
2021-02-10 14:12:49 +00:00
|
|
|
bool ignore_projections = false;
|
2021-07-07 05:01:30 +00:00
|
|
|
/// This flag is also used for projection analysis.
|
|
|
|
/// It is needed because lazy normal projections require special planning in FetchColumns stage, such as adding WHERE transform.
|
|
|
|
/// It is also used to avoid adding aggregating step when aggregate projection is chosen.
|
|
|
|
bool is_projection_query = false;
|
2021-12-17 17:36:37 +00:00
|
|
|
/// This flag is needed for projection description.
|
|
|
|
/// Otherwise, keys for GROUP BY may be removed as constants.
|
|
|
|
bool ignore_ast_optimizations = false;
|
2021-02-10 14:12:49 +00:00
|
|
|
bool ignore_alias = false;
|
2020-12-18 06:54:38 +00:00
|
|
|
bool is_internal = false;
|
2021-02-08 16:25:24 +00:00
|
|
|
bool is_subquery = false; // non-subquery can also have subquery_depth > 0, e.g. insert select
|
2021-06-24 14:57:21 +00:00
|
|
|
bool with_all_cols = false; /// asterisk include materialized and aliased columns
|
2022-01-11 12:19:41 +00:00
|
|
|
bool settings_limit_offset_done = false;
|
2022-04-07 11:43:49 +00:00
|
|
|
bool is_explain = false; /// The value is true if it's explain statement.
|
2019-03-18 12:05:51 +00:00
|
|
|
|
2021-07-31 07:50:16 +00:00
|
|
|
/// These two fields are used to evaluate shardNum() and shardCount() function when
|
2021-07-31 07:45:26 +00:00
|
|
|
/// prefer_localhost_replica == 1 and local instance is selected. They are needed because local
|
|
|
|
/// instance might have multiple shards and scalars can only hold one value.
|
|
|
|
std::optional<UInt32> shard_num;
|
|
|
|
std::optional<UInt32> shard_count;
|
|
|
|
|
2021-06-24 14:14:36 +00:00
|
|
|
SelectQueryOptions(
|
|
|
|
QueryProcessingStage::Enum stage = QueryProcessingStage::Complete,
|
|
|
|
size_t depth = 0,
|
2022-01-11 12:19:41 +00:00
|
|
|
bool is_subquery_ = false,
|
|
|
|
bool settings_limit_offset_done_ = false)
|
|
|
|
: to_stage(stage), subquery_depth(depth), is_subquery(is_subquery_),
|
|
|
|
settings_limit_offset_done(settings_limit_offset_done_)
|
2021-06-24 14:14:36 +00:00
|
|
|
{}
|
2019-03-15 13:49:58 +00:00
|
|
|
|
2019-03-18 12:05:51 +00:00
|
|
|
SelectQueryOptions copy() const { return *this; }
|
2019-03-15 13:49:58 +00:00
|
|
|
|
2019-03-18 12:05:51 +00:00
|
|
|
SelectQueryOptions subquery() const
|
2019-03-15 13:49:58 +00:00
|
|
|
{
|
2019-03-15 15:57:18 +00:00
|
|
|
SelectQueryOptions out = *this;
|
2019-03-18 12:05:51 +00:00
|
|
|
out.to_stage = QueryProcessingStage::Complete;
|
2019-03-15 15:57:18 +00:00
|
|
|
++out.subquery_depth;
|
2021-02-08 16:25:24 +00:00
|
|
|
out.is_subquery = true;
|
2019-03-15 15:57:18 +00:00
|
|
|
return out;
|
2019-03-15 13:49:58 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 00:57:00 +00:00
|
|
|
SelectQueryOptions & analyze(bool dry_run = true)
|
2019-03-15 13:49:58 +00:00
|
|
|
{
|
2020-03-18 00:57:00 +00:00
|
|
|
only_analyze = dry_run;
|
2019-03-18 12:05:51 +00:00
|
|
|
return *this;
|
2019-03-15 13:49:58 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 12:05:51 +00:00
|
|
|
SelectQueryOptions & modify(bool value = true)
|
2019-03-15 13:49:58 +00:00
|
|
|
{
|
2019-03-18 12:05:51 +00:00
|
|
|
modify_inplace = value;
|
|
|
|
return *this;
|
2019-03-15 13:49:58 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 12:05:51 +00:00
|
|
|
SelectQueryOptions & noModify() { return modify(false); }
|
|
|
|
|
2019-03-18 14:56:33 +00:00
|
|
|
SelectQueryOptions & removeDuplicates(bool value = true)
|
|
|
|
{
|
|
|
|
remove_duplicates = value;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-03-18 12:05:51 +00:00
|
|
|
SelectQueryOptions & noSubquery()
|
2019-03-15 13:49:58 +00:00
|
|
|
{
|
2019-03-18 12:05:51 +00:00
|
|
|
subquery_depth = 0;
|
|
|
|
return *this;
|
2019-03-15 13:49:58 +00:00
|
|
|
}
|
2019-06-14 19:27:53 +00:00
|
|
|
|
|
|
|
SelectQueryOptions & ignoreLimits(bool value = true)
|
|
|
|
{
|
|
|
|
ignore_limits = value;
|
|
|
|
return *this;
|
|
|
|
}
|
2020-12-18 06:54:38 +00:00
|
|
|
|
2021-02-10 14:12:49 +00:00
|
|
|
SelectQueryOptions & ignoreProjections(bool value = true)
|
|
|
|
{
|
|
|
|
ignore_projections = value;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2021-07-07 05:01:30 +00:00
|
|
|
SelectQueryOptions & projectionQuery(bool value = true)
|
2021-04-22 08:43:35 +00:00
|
|
|
{
|
2021-07-07 05:01:30 +00:00
|
|
|
is_projection_query = value;
|
2021-04-22 08:43:35 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2021-02-10 14:12:49 +00:00
|
|
|
SelectQueryOptions & ignoreAlias(bool value = true)
|
|
|
|
{
|
|
|
|
ignore_alias = value;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2022-06-01 00:50:28 +00:00
|
|
|
SelectQueryOptions & ignoreASTOptimizations(bool value = true)
|
2021-12-17 17:36:37 +00:00
|
|
|
{
|
|
|
|
ignore_ast_optimizations = value;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2020-12-18 06:54:38 +00:00
|
|
|
SelectQueryOptions & setInternal(bool value = false)
|
|
|
|
{
|
|
|
|
is_internal = value;
|
|
|
|
return *this;
|
|
|
|
}
|
2021-06-24 14:14:36 +00:00
|
|
|
|
2021-06-24 14:57:21 +00:00
|
|
|
SelectQueryOptions & setWithAllColumns(bool value = true)
|
2021-06-24 14:14:36 +00:00
|
|
|
{
|
2021-06-24 14:57:21 +00:00
|
|
|
with_all_cols = value;
|
2021-06-24 14:14:36 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2021-07-31 07:45:26 +00:00
|
|
|
|
|
|
|
SelectQueryOptions & setShardInfo(UInt32 shard_num_, UInt32 shard_count_)
|
|
|
|
{
|
|
|
|
shard_num = shard_num_;
|
|
|
|
shard_count = shard_count_;
|
|
|
|
return *this;
|
|
|
|
}
|
2022-04-07 11:43:49 +00:00
|
|
|
|
|
|
|
SelectQueryOptions & setExplain(bool value = true)
|
|
|
|
{
|
|
|
|
is_explain = value;
|
|
|
|
return *this;
|
|
|
|
}
|
2019-03-15 13:49:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|