Skip to content

Commit

Permalink
Use final binder table index to initialize physical planner
Browse files Browse the repository at this point in the history
  • Loading branch information
kryonix committed Jul 17, 2024
1 parent a14b34e commit ff675e0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/execution/physical_plan/plan_delim_join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@
#include "duckdb/execution/physical_plan_generator.hpp"
#include "duckdb/planner/expression/bound_reference_expression.hpp"

#include "duckdb/execution/operator/scan/physical_column_data_scan.hpp"

namespace duckdb {

static void GatherDelimScans(const PhysicalOperator &op, vector<const_reference<PhysicalOperator>> &delim_scans) {
static void GatherDelimScans(PhysicalOperator &op, vector<const_reference<PhysicalOperator>> &delim_scans,
idx_t delim_index) {
if (op.type == PhysicalOperatorType::DELIM_SCAN) {
// This should be auto &scan = op.Cast<PhysicalColumnDataScan>();, however, Cast<> does
// not work for this case currently.
PhysicalColumnDataScan &scan = reinterpret_cast<PhysicalColumnDataScan &>(op);
scan.delim_index = optional_idx(delim_index);
delim_scans.push_back(op);
}
for (auto &child : op.children) {
GatherDelimScans(*child, delim_scans);
GatherDelimScans(*child, delim_scans, delim_index);
}
}

Expand All @@ -27,7 +34,7 @@ unique_ptr<PhysicalOperator> PhysicalPlanGenerator::PlanDelimJoin(LogicalCompari
// first gather the scans on the duplicate eliminated data set from the delim side
const idx_t delim_idx = op.delim_flipped ? 0 : 1;
vector<const_reference<PhysicalOperator>> delim_scans;
GatherDelimScans(*plan->children[delim_idx], delim_scans);
GatherDelimScans(*plan->children[delim_idx], delim_scans, ++this->delim_index);
if (delim_scans.empty()) {
// no duplicate eliminated scans in the delim side!
// in this case we don't need to create a delim join
Expand All @@ -45,14 +52,16 @@ unique_ptr<PhysicalOperator> PhysicalPlanGenerator::PlanDelimJoin(LogicalCompari
// now create the duplicate eliminated join
unique_ptr<PhysicalDelimJoin> delim_join;
if (op.delim_flipped) {
delim_join =
make_uniq<PhysicalRightDelimJoin>(op.types, std::move(plan), delim_scans, op.estimated_cardinality, optional_idx(++this->delim_index));
delim_join = make_uniq<PhysicalRightDelimJoin>(op.types, std::move(plan), delim_scans, op.estimated_cardinality,
optional_idx(this->delim_index));
} else {
delim_join = make_uniq<PhysicalLeftDelimJoin>(op.types, std::move(plan), delim_scans, op.estimated_cardinality, optional_idx(++this->delim_index));
delim_join = make_uniq<PhysicalLeftDelimJoin>(op.types, std::move(plan), delim_scans, op.estimated_cardinality,
optional_idx(this->delim_index));
}
// we still have to create the DISTINCT clause that is used to generate the duplicate eliminated chunk
delim_join->distinct = make_uniq<PhysicalHashAggregate>(context, delim_types, std::move(distinct_expressions),
std::move(distinct_groups), op.estimated_cardinality);

return std::move(delim_join);
}

Expand Down
1 change: 1 addition & 0 deletions src/include/duckdb/execution/physical_plan_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class PhysicalPlanGenerator {
bool PreserveInsertionOrder(PhysicalOperator &plan);
bool UseBatchIndex(PhysicalOperator &plan);

public:
idx_t delim_index = 0;

private:
Expand Down
1 change: 1 addition & 0 deletions src/main/client_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ ClientContext::CreatePreparedStatementInternal(ClientContextLock &lock, const st
profiler.StartPhase("physical_planner");
// now convert logical query plan into a physical query plan
PhysicalPlanGenerator physical_planner(*this);
physical_planner.delim_index = planner.binder->GenerateTableIndex();
auto physical_plan = physical_planner.CreatePlan(std::move(plan));
profiler.EndPhase();

Expand Down

0 comments on commit ff675e0

Please sign in to comment.