2020-11-01 13:54:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Interpreters/Context.h>
|
|
|
|
#include <Interpreters/IInterpreter.h>
|
|
|
|
#include <Interpreters/SelectQueryOptions.h>
|
|
|
|
#include <Parsers/IAST_fwd.h>
|
2021-07-31 07:45:26 +00:00
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
2020-11-01 13:54:07 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2022-05-20 19:49:31 +00:00
|
|
|
|
2020-11-01 13:54:07 +00:00
|
|
|
class IInterpreterUnionOrSelectQuery : public IInterpreter
|
|
|
|
{
|
|
|
|
public:
|
2022-07-05 22:47:00 +00:00
|
|
|
IInterpreterUnionOrSelectQuery(const ASTPtr & query_ptr_, const ContextPtr & context_, const SelectQueryOptions & options_)
|
2022-05-30 08:57:51 +00:00
|
|
|
: IInterpreterUnionOrSelectQuery(query_ptr_, Context::createCopy(context_), options_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-07-05 22:47:00 +00:00
|
|
|
IInterpreterUnionOrSelectQuery(const ASTPtr & query_ptr_, const ContextMutablePtr & context_, const SelectQueryOptions & options_)
|
2020-11-01 13:54:07 +00:00
|
|
|
: query_ptr(query_ptr_)
|
2022-05-30 08:57:51 +00:00
|
|
|
, context(context_)
|
2020-11-01 13:54:07 +00:00
|
|
|
, options(options_)
|
|
|
|
, max_streams(context->getSettingsRef().max_threads)
|
|
|
|
{
|
2021-07-31 07:45:26 +00:00
|
|
|
if (options.shard_num)
|
2022-04-06 06:53:10 +00:00
|
|
|
context->addSpecialScalar(
|
2021-07-31 07:45:26 +00:00
|
|
|
"_shard_num",
|
|
|
|
Block{{DataTypeUInt32().createColumnConst(1, *options.shard_num), std::make_shared<DataTypeUInt32>(), "_shard_num"}});
|
|
|
|
if (options.shard_count)
|
2022-04-06 06:53:10 +00:00
|
|
|
context->addSpecialScalar(
|
2021-07-31 07:45:26 +00:00
|
|
|
"_shard_count",
|
|
|
|
Block{{DataTypeUInt32().createColumnConst(1, *options.shard_count), std::make_shared<DataTypeUInt32>(), "_shard_count"}});
|
2020-11-01 13:54:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void buildQueryPlan(QueryPlan & query_plan) = 0;
|
2022-05-23 13:46:57 +00:00
|
|
|
QueryPipelineBuilder buildQueryPipeline();
|
2023-04-02 08:09:39 +00:00
|
|
|
QueryPipelineBuilder buildQueryPipeline(QueryPlan & query_plan);
|
2020-11-01 13:54:07 +00:00
|
|
|
|
|
|
|
virtual void ignoreWithTotals() = 0;
|
|
|
|
|
2022-06-05 14:31:07 +00:00
|
|
|
~IInterpreterUnionOrSelectQuery() override = default;
|
2020-11-01 13:54:07 +00:00
|
|
|
|
|
|
|
Block getSampleBlock() { return result_header; }
|
|
|
|
|
|
|
|
size_t getMaxStreams() const { return max_streams; }
|
|
|
|
|
2022-01-28 11:39:56 +00:00
|
|
|
/// Returns whether the query uses the view source from the Context
|
|
|
|
/// The view source is a virtual storage that currently only materialized views use to replace the source table
|
|
|
|
/// with the incoming block only
|
|
|
|
/// This flag is useful to know for how long we can cache scalars generated by this query: If it doesn't use the virtual storage
|
|
|
|
/// then we can cache the scalars forever (for any query that doesn't use the virtual storage either), but if it does use the virtual
|
|
|
|
/// storage then we can only keep the scalar result around while we are working with that source block
|
|
|
|
/// You can find more details about this under ExecuteScalarSubqueriesMatcher::visit
|
2022-03-13 11:59:20 +00:00
|
|
|
bool usesViewSource() const { return uses_view_source; }
|
2022-01-17 18:32:55 +00:00
|
|
|
|
2022-06-02 10:34:40 +00:00
|
|
|
/// Add limits from external query.
|
2022-05-31 14:43:38 +00:00
|
|
|
void addStorageLimits(const StorageLimitsList & limits);
|
|
|
|
|
2022-11-04 15:44:31 +00:00
|
|
|
ContextPtr getContext() const { return context; }
|
|
|
|
|
2020-11-01 13:54:07 +00:00
|
|
|
protected:
|
|
|
|
ASTPtr query_ptr;
|
2021-05-31 14:49:02 +00:00
|
|
|
ContextMutablePtr context;
|
2020-11-01 13:54:07 +00:00
|
|
|
Block result_header;
|
|
|
|
SelectQueryOptions options;
|
2022-05-31 14:43:38 +00:00
|
|
|
StorageLimitsList storage_limits;
|
|
|
|
|
2020-11-01 13:54:07 +00:00
|
|
|
size_t max_streams = 1;
|
2020-12-17 14:16:14 +00:00
|
|
|
bool settings_limit_offset_needed = false;
|
|
|
|
bool settings_limit_offset_done = false;
|
2022-01-17 18:32:55 +00:00
|
|
|
bool uses_view_source = false;
|
2022-06-02 10:34:40 +00:00
|
|
|
|
|
|
|
/// Set quotas to query pipeline.
|
|
|
|
void setQuota(QueryPipeline & pipeline) const;
|
2022-07-06 12:37:37 +00:00
|
|
|
/// Add filter from additional_post_filter setting.
|
|
|
|
void addAdditionalPostFilter(QueryPlan & plan) const;
|
2022-06-02 10:34:40 +00:00
|
|
|
|
|
|
|
static StorageLimits getStorageLimits(const Context & context, const SelectQueryOptions & options);
|
2020-11-01 13:54:07 +00:00
|
|
|
};
|
|
|
|
}
|