Skip to content

Commit

Permalink
Add explicit table info to the scan node of query plan and pipeline
Browse files Browse the repository at this point in the history
:) explain plan select * from table1 t1 left join table2 t2 on t1.name = t2.name;
┌─explain──────────────────────────────────────────────────────────────────────────────────────┐
│ Expression ((Projection + Before ORDER BY))                                                  │
│   Join (JOIN)                                                                                │
│     Expression (Before JOIN)                                                                 │
│       SettingQuotaAndLimits (Set limits and quota after reading from storage)                │
│         ReadFromMergeTree (default.table1)                                                   │
│     Expression ((Joined actions + (Rename joined columns + (Projection + Before ORDER BY)))) │
│       SettingQuotaAndLimits (Set limits and quota after reading from storage)                │
│         ReadFromMergeTree (default.table2)                                                   │
└──────────────────────────────────────────────────────────────────────────────────────────────┘

:) explain pipeline select * from table1 t1 left join table2 t2 on t1.name = t2.name;
┌─explain──────────────────────────────────────────┐
│ (Expression)                                     │
│ ExpressionTransform × 24                         │
│   (Join)                                         │
│   JoiningTransform × 24 2 → 1                    │
│     Resize 1 → 24                                │
│       FillingRightJoinSide                       │
│         Resize 24 → 1                            │
│           (Expression)                           │
│           ExpressionTransform × 24               │
│             (SettingQuotaAndLimits)              │
│               (ReadFromMergeTree default.table1) │
│               MergeTreeThread × 24 0 → 1         │
│           (Expression)                           │
│           ExpressionTransform × 24               │
│             (SettingQuotaAndLimits)              │
│               (ReadFromMergeTree default.table2) │
│               MergeTreeThread × 24 0 → 1         │
└──────────────────────────────────────────────────┘
  • Loading branch information
helifu authored and vdimir committed Mar 24, 2022
1 parent 283e20a commit 8a5bd2d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/Processors/QueryPlan/QueryPlan.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <Processors/QueryPlan/QueryPlan.h>
#include <Processors/QueryPlan/IQueryPlanStep.h>
#include <Processors/QueryPlan/ReadFromMergeTree.h>
#include <QueryPipeline/QueryPipelineBuilder.h>
#include <IO/WriteBuffer.h>
#include <IO/Operators.h>
Expand Down Expand Up @@ -387,7 +388,15 @@ void QueryPlan::explainPlan(WriteBuffer & buffer, const ExplainPlanOptions & opt

static void explainPipelineStep(IQueryPlanStep & step, IQueryPlanStep::FormatSettings & settings)
{
settings.out << String(settings.offset, settings.indent_char) << "(" << step.getName() << ")\n";
// Add explicit description to the scan node of pipeline.
if (ReadFromMergeTree::READ_FROM_MERGETREE_NAME == step.getName())
{
settings.out << String(settings.offset, settings.indent_char) << "(" << step.getName() << " " << step.getStepDescription() << ")\n";
}
else
{
settings.out << String(settings.offset, settings.indent_char) << "(" << step.getName() << ")\n";
}
size_t current_offset = settings.offset;
step.describePipeline(settings);
if (current_offset == settings.offset)
Expand Down
5 changes: 5 additions & 0 deletions src/Processors/QueryPlan/ReadFromMergeTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ namespace ErrorCodes
extern const int LOGICAL_ERROR;
}

const std::string ReadFromMergeTree::READ_FROM_MERGETREE_NAME = "ReadFromMergeTree";

static MergeTreeReaderSettings getMergeTreeReaderSettings(const ContextPtr & context)
{
const auto & settings = context->getSettingsRef();
Expand Down Expand Up @@ -112,6 +114,9 @@ ReadFromMergeTree::ReadFromMergeTree(

if (enable_parallel_reading)
read_task_callback = context->getMergeTreeReadTaskCallback();

/// Add explicit description.
setStepDescription(data.getStorageID().getFullNameNotQuoted());
}

Pipe ReadFromMergeTree::readFromPool(
Expand Down
3 changes: 2 additions & 1 deletion src/Processors/QueryPlan/ReadFromMergeTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ class ReadFromMergeTree final : public ISourceStep
bool enable_parallel_reading
);

String getName() const override { return "ReadFromMergeTree"; }
static const std::string READ_FROM_MERGETREE_NAME;
String getName() const override { return READ_FROM_MERGETREE_NAME; }

void initializePipeline(QueryPipelineBuilder & pipeline, const BuildQueryPipelineSettings &) override;

Expand Down

0 comments on commit 8a5bd2d

Please sign in to comment.