2020-06-08 09:14:58 +00:00
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
|
|
#include <list>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class DataStream;
|
|
|
|
|
|
|
|
class IQueryPlanStep;
|
|
|
|
using QueryPlanStepPtr = std::unique_ptr<IQueryPlanStep>;
|
|
|
|
|
|
|
|
class QueryPipeline;
|
|
|
|
using QueryPipelinePtr = std::unique_ptr<QueryPipeline>;
|
|
|
|
|
2020-06-19 14:42:01 +00:00
|
|
|
class Context;
|
2020-06-22 14:37:42 +00:00
|
|
|
class WriteBuffer;
|
2020-06-19 14:42:01 +00:00
|
|
|
|
2020-06-08 09:14:58 +00:00
|
|
|
/// A tree of query steps.
|
|
|
|
class QueryPlan
|
|
|
|
{
|
|
|
|
public:
|
2020-06-22 14:37:42 +00:00
|
|
|
QueryPlan();
|
2020-06-19 14:42:01 +00:00
|
|
|
~QueryPlan();
|
|
|
|
|
2020-06-18 17:45:00 +00:00
|
|
|
void unitePlans(QueryPlanStepPtr step, std::vector<QueryPlan> plans);
|
2020-06-08 09:14:58 +00:00
|
|
|
void addStep(QueryPlanStepPtr step);
|
|
|
|
|
|
|
|
bool isInitialized() const { return root != nullptr; } /// Tree is not empty
|
|
|
|
bool isCompleted() const; /// Tree is not empty and root hasOutputStream()
|
|
|
|
const DataStream & getCurrentDataStream() const; /// Checks that (isInitialized() && !isCompleted())
|
|
|
|
|
|
|
|
QueryPipelinePtr buildQueryPipeline();
|
|
|
|
|
2020-06-23 11:26:06 +00:00
|
|
|
struct ExplainOptions
|
|
|
|
{
|
|
|
|
bool header = false;
|
2020-06-23 14:11:15 +00:00
|
|
|
bool description = true;
|
2020-06-23 16:06:56 +00:00
|
|
|
bool actions = false;
|
2020-06-23 11:26:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void explain(WriteBuffer & buffer, const ExplainOptions & options);
|
2020-06-25 09:39:17 +00:00
|
|
|
void explainPipeline(WriteBuffer & buffer);
|
2020-06-22 14:37:42 +00:00
|
|
|
|
2020-06-18 17:45:00 +00:00
|
|
|
/// Set upper limit for the recommend number of threads. Will be applied to the newly-created pipelines.
|
|
|
|
/// TODO: make it in a better way.
|
|
|
|
void setMaxThreads(size_t max_threads_) { max_threads = max_threads_; }
|
|
|
|
|
2020-06-19 14:42:01 +00:00
|
|
|
void addInterpreterContext(std::shared_ptr<Context> context);
|
|
|
|
|
2020-06-08 09:14:58 +00:00
|
|
|
private:
|
|
|
|
struct Node
|
|
|
|
{
|
|
|
|
QueryPlanStepPtr step;
|
2020-06-16 14:11:19 +00:00
|
|
|
std::vector<Node *> children = {};
|
2020-06-08 09:14:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
using Nodes = std::list<Node>;
|
|
|
|
Nodes nodes;
|
|
|
|
|
|
|
|
Node * root = nullptr;
|
|
|
|
|
|
|
|
void checkInitialized() const;
|
|
|
|
void checkNotCompleted() const;
|
2020-06-18 17:45:00 +00:00
|
|
|
|
|
|
|
size_t max_threads = 0;
|
2020-06-19 14:42:01 +00:00
|
|
|
|
|
|
|
std::vector<std::shared_ptr<Context>> interpreter_context;
|
2020-06-08 09:14:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|