mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-29 13:10:48 +00:00
Limit push down.
This commit is contained in:
parent
16e8c61438
commit
b4852e4c69
@ -4,6 +4,7 @@
|
||||
#include <IO/WriteBuffer.h>
|
||||
#include <IO/Operators.h>
|
||||
#include <stack>
|
||||
#include <Processors/QueryPlan/LimitStep.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
@ -307,4 +308,46 @@ void QueryPlan::explainPipeline(WriteBuffer & buffer, const ExplainPipelineOptio
|
||||
}
|
||||
}
|
||||
|
||||
static void tryPushDownLimit(QueryPlanStepPtr & parent, QueryPlanStepPtr & child)
|
||||
{
|
||||
const auto * limit = typeid_cast<const LimitStep *>(parent.get());
|
||||
|
||||
if (!limit)
|
||||
return;
|
||||
|
||||
/// Now we should decide if pushing down limit possible for this step.
|
||||
}
|
||||
|
||||
void QueryPlan::optimize()
|
||||
{
|
||||
struct Frame
|
||||
{
|
||||
Node * node;
|
||||
size_t next_child = 0;
|
||||
};
|
||||
|
||||
std::stack<Frame> stack;
|
||||
stack.push(Frame{.node = root});
|
||||
|
||||
while (!stack.empty())
|
||||
{
|
||||
auto & frame = stack.top();
|
||||
|
||||
if (frame.next_child == 0)
|
||||
{
|
||||
/// First entrance, try push down.
|
||||
if (frame.node->children.size() == 1)
|
||||
tryPushDownLimit(frame.node->step, frame.node->children.front()->step);
|
||||
}
|
||||
|
||||
if (frame.next_child < frame.node->children.size())
|
||||
{
|
||||
stack.push(Frame{frame.node->children[frame.next_child]});
|
||||
++frame.next_child;
|
||||
}
|
||||
else
|
||||
stack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,6 +33,8 @@ public:
|
||||
bool isCompleted() const; /// Tree is not empty and root hasOutputStream()
|
||||
const DataStream & getCurrentDataStream() const; /// Checks that (isInitialized() && !isCompleted())
|
||||
|
||||
void optimize();
|
||||
|
||||
QueryPipelinePtr buildQueryPipeline();
|
||||
|
||||
struct ExplainPlanOptions
|
||||
|
Loading…
Reference in New Issue
Block a user