Skip to content

Commit

Permalink
polishing up the PR
Browse files Browse the repository at this point in the history
  • Loading branch information
lnkuiper committed May 30, 2024
1 parent 60f5a97 commit b91f11d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
21 changes: 12 additions & 9 deletions src/execution/operator/scan/physical_column_data_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ PhysicalColumnDataScan::PhysicalColumnDataScan(vector<LogicalType> types, Physic
: PhysicalOperator(op_type, std::move(types), estimated_cardinality), collection(nullptr), cte_index(cte_index) {
}

class PhysicalColumnGlobalDataScanState : public GlobalSourceState {
class PhysicalColumnDataGlobalScanState : public GlobalSourceState {
public:
PhysicalColumnGlobalDataScanState(const ClientContext &context, const ColumnDataCollection &collection)
: max_threads(MaxValue<idx_t>(
context.config.verify_parallelism ? collection.ChunkCount() : collection.ChunkCount() / 60, 1)) {
PhysicalColumnDataGlobalScanState(const ClientContext &context, const ColumnDataCollection &collection)
: max_threads(MaxValue<idx_t>(context.config.verify_parallelism ? collection.ChunkCount()
: collection.ChunkCount() / CHUNKS_PER_THREAD,
1)) {
collection.InitializeScan(global_scan_state);
}

Expand All @@ -33,27 +34,29 @@ class PhysicalColumnGlobalDataScanState : public GlobalSourceState {

public:
ColumnDataParallelScanState global_scan_state;

static constexpr idx_t CHUNKS_PER_THREAD = 32;
const idx_t max_threads;
};

class PhysicalColumnLocalDataScanState : public LocalSourceState {
class PhysicalColumnDataLocalScanState : public LocalSourceState {
public:
ColumnDataLocalScanState local_scan_state;
};

unique_ptr<GlobalSourceState> PhysicalColumnDataScan::GetGlobalSourceState(ClientContext &context) const {
return make_uniq<PhysicalColumnGlobalDataScanState>(context, *collection);
return make_uniq<PhysicalColumnDataGlobalScanState>(context, *collection);
}

unique_ptr<LocalSourceState> PhysicalColumnDataScan::GetLocalSourceState(ExecutionContext &,
GlobalSourceState &) const {
return make_uniq<PhysicalColumnLocalDataScanState>();
return make_uniq<PhysicalColumnDataLocalScanState>();
}

SourceResultType PhysicalColumnDataScan::GetData(ExecutionContext &context, DataChunk &chunk,
OperatorSourceInput &input) const {
auto &gstate = input.global_state.Cast<PhysicalColumnGlobalDataScanState>();
auto &lstate = input.local_state.Cast<PhysicalColumnLocalDataScanState>();
auto &gstate = input.global_state.Cast<PhysicalColumnDataGlobalScanState>();
auto &lstate = input.local_state.Cast<PhysicalColumnDataLocalScanState>();
collection->Scan(gstate.global_scan_state, lstate.local_scan_state, chunk);
return chunk.size() == 0 ? SourceResultType::FINISHED : SourceResultType::HAVE_MORE_OUTPUT;
}
Expand Down
1 change: 1 addition & 0 deletions src/include/duckdb/common/optionally_owned_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include "duckdb/common/exception.hpp"
#include "duckdb/common/optional_ptr.hpp"
#include "duckdb/common/unique_ptr.hpp"

namespace duckdb {
Expand Down
2 changes: 2 additions & 0 deletions src/optimizer/join_order/relation_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ void RelationManager::AddAggregateOrWindowRelation(LogicalOperator &op, optional
}
}
relations.push_back(std::move(relation));
op.estimated_cardinality = stats.cardinality;
op.has_estimated_cardinality = true;
}

void RelationManager::AddRelation(LogicalOperator &op, optional_ptr<LogicalOperator> parent,
Expand Down
5 changes: 4 additions & 1 deletion test/optimizer/joins/delim_join_dont_explode.test_slow
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ exists(
----
143 values hashing to dc5d1675d206057ccfe13739a38ee082

# The query plan here used to join the two SEQ_SCANs first, and then join the DELIM_SCAN,
# Since PR #12290, we can reorder DELIM_SCANS
# Now the DELIM_SCAN is joined with a SEQ_SCAN first, and then with the SEQ_SCAN
query II
EXPLAIN
SELECT *
Expand All @@ -59,7 +62,7 @@ exists(
)
order by bt.id
----
physical_plan <REGEX>:.*HASH_JOIN.*DELIM_SCAN.*SEQ_SCAN.*SEQ_SCAN.*
physical_plan <REGEX>:.*HASH_JOIN.*SEQ_SCAN.*DELIM_SCAN.*SEQ_SCAN.*



0 comments on commit b91f11d

Please sign in to comment.