Limit push down.

This commit is contained in:
Nikolai Kochetov 2020-07-23 13:20:38 +03:00
parent 16e8c61438
commit b4852e4c69
2 changed files with 45 additions and 0 deletions

View File

@ -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();
}
}
}

View File

@ -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