Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::HashJoinGlobalSourceState Class Reference
Inheritance diagram for duckdb::HashJoinGlobalSourceState:
Collaboration diagram for duckdb::HashJoinGlobalSourceState:

Public Member Functions

 HashJoinGlobalSourceState (const PhysicalHashJoin &op, const ClientContext &context)
void Initialize (HashJoinGlobalSinkState &sink)
 Initialize this source state using the info in the sink.
bool TryPrepareNextStage (HashJoinGlobalSinkState &sink)
 Try to prepare the next stage.
void PrepareBuild (HashJoinGlobalSinkState &sink)
 Prepare the next build/probe/scan_ht stage for external hash join (must hold lock).
void PrepareProbe (HashJoinGlobalSinkState &sink)
void PrepareScanHT (HashJoinGlobalSinkState &sink)
bool AssignTask (HashJoinGlobalSinkState &sink, HashJoinLocalSourceState &lstate)
 Assigns a task to a local source state.
idx_t MaxThreads () override
Public Member Functions inherited from duckdb::GlobalSourceState
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const
Public Member Functions inherited from duckdb::StateWithBlockableTasks
unique_lock< mutex > Lock ()
void PreventBlocking (const unique_lock< mutex > &guard)
bool BlockTask (const unique_lock< mutex > &guard, const InterruptState &interrupt_state)
 Add a task to 'blocked_tasks' before returning SourceResultType::BLOCKED (must hold the lock).
bool CanBlock (const unique_lock< mutex > &guard) const
bool UnblockTasks (const unique_lock< mutex > &guard)
 Unblock all tasks (must hold the lock).
SinkResultType BlockSink (const unique_lock< mutex > &guard, const InterruptState &interrupt_state)
SourceResultType BlockSource (const unique_lock< mutex > &guard, const InterruptState &interrupt_state)
void VerifyLock (const unique_lock< mutex > &guard) const

Public Attributes

const PhysicalHashJoin & op
atomic< HashJoinSourceStage > global_stage
 For synchronizing the external hash join.
idx_t build_chunk_idx = DConstants::INVALID_INDEX
 For HT build synchronization.
idx_t build_chunk_count
idx_t build_chunk_done
idx_t build_chunks_per_thread = DConstants::INVALID_INDEX
atomic< idx_t > probe_chunk_count
 For probe synchronization.
atomic< idx_t > probe_chunk_done
idx_t probe_count
 To determine the number of threads.
idx_t parallel_scan_chunk_count
idx_t full_outer_chunk_idx = DConstants::INVALID_INDEX
 For full/outer synchronization.
atomic< idx_t > full_outer_chunk_count
atomic< idx_t > full_outer_chunk_done
idx_t full_outer_chunks_per_thread = DConstants::INVALID_INDEX
vector< InterruptState > blocked_tasks

Constructor & Destructor Documentation

◆ HashJoinGlobalSourceState()

duckdb::HashJoinGlobalSourceState::HashJoinGlobalSourceState ( const PhysicalHashJoin & op,
const ClientContext & context )
185455 : op(op), global_stage(HashJoinSourceStage::INIT), build_chunk_count(0), build_chunk_done(0), probe_chunk_count(0),
185456 probe_chunk_done(0), probe_count(op.children[0].get().estimated_cardinality),
185457 parallel_scan_chunk_count(context.config.verify_parallelism ? 1 : 120), full_outer_chunk_count(0),
185458 full_outer_chunk_done(0) {
185459}
atomic< HashJoinSourceStage > global_stage
For synchronizing the external hash join.
Definition duckdb.cpp:185376
atomic< idx_t > probe_chunk_count
For probe synchronization.
Definition duckdb.cpp:185385
idx_t probe_count
To determine the number of threads.
Definition duckdb.cpp:185389

Member Function Documentation

◆ Initialize()

void duckdb::HashJoinGlobalSourceState::Initialize ( HashJoinGlobalSinkState & sink)

Initialize this source state using the info in the sink.

185461 {
185462 auto guard = Lock();
185463 if (global_stage != HashJoinSourceStage::INIT) {
185464 // Another thread initialized
185465 return;
185466 }
185467
185468 // Finalize the probe spill
185469 if (sink.probe_spill) {
185470 sink.probe_spill->Finalize();
185471 }
185472
185473 global_stage = HashJoinSourceStage::PROBE;
185474 TryPrepareNextStage(sink);
185475}
bool TryPrepareNextStage(HashJoinGlobalSinkState &sink)
Try to prepare the next stage.
Definition duckdb.cpp:185477
Here is the call graph for this function:

◆ TryPrepareNextStage()

bool duckdb::HashJoinGlobalSourceState::TryPrepareNextStage ( HashJoinGlobalSinkState & sink)

Try to prepare the next stage.

185477 {
185478 switch (global_stage.load()) {
185479 case HashJoinSourceStage::BUILD:
185480 if (build_chunk_done == build_chunk_count) {
185481 sink.hash_table->GetDataCollection().VerifyEverythingPinned();
185482 sink.hash_table->finalized = true;
185483 PrepareProbe(sink);
185484 return true;
185485 }
185486 break;
185487 case HashJoinSourceStage::PROBE:
185488 if (probe_chunk_done == probe_chunk_count) {
185489 if (PropagatesBuildSide(op.join_type)) {
185490 PrepareScanHT(sink);
185491 } else {
185492 PrepareBuild(sink);
185493 }
185494 return true;
185495 }
185496 break;
185497 case HashJoinSourceStage::SCAN_HT:
185498 if (full_outer_chunk_done == full_outer_chunk_count) {
185499 PrepareBuild(sink);
185500 return true;
185501 }
185502 break;
185503 default:
185504 break;
185505 }
185506 return false;
185507}
void PrepareBuild(HashJoinGlobalSinkState &sink)
Prepare the next build/probe/scan_ht stage for external hash join (must hold lock).
Definition duckdb.cpp:185509
bool PropagatesBuildSide(JoinType type)
Whether the build side is propagated out of the join.
Definition duckdb.cpp:68427
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PrepareBuild()

void duckdb::HashJoinGlobalSourceState::PrepareBuild ( HashJoinGlobalSinkState & sink)

Prepare the next build/probe/scan_ht stage for external hash join (must hold lock).

185509 {
185510 D_ASSERT(global_stage != HashJoinSourceStage::BUILD);
185511 auto &ht = *sink.hash_table;
185512
185513 // Update remaining size
185514 sink.temporary_memory_state->SetRemainingSizeAndUpdateReservation(sink.context, ht.GetRemainingSize() +
185515 sink.probe_side_requirement);
185516
185517 // Try to put the next partitions in the block collection of the HT
185518 D_ASSERT(!sink.external || sink.temporary_memory_state->GetReservation() >= sink.probe_side_requirement);
185519 if (!sink.external ||
185520 !ht.PrepareExternalFinalize(sink.temporary_memory_state->GetReservation() - sink.probe_side_requirement)) {
185521 global_stage = HashJoinSourceStage::DONE;
185522 sink.temporary_memory_state->SetZero();
185523 return;
185524 }
185525
185526 auto &data_collection = ht.GetDataCollection();
185527 if (data_collection.Count() == 0 && op.EmptyResultIfRHSIsEmpty()) {
185528 PrepareBuild(sink);
185529 return;
185530 }
185531
185532 build_chunk_idx = 0;
185533 build_chunk_count = data_collection.ChunkCount();
185534 build_chunk_done = 0;
185535
185536 if (sink.context.config.verify_parallelism) {
185537 build_chunks_per_thread = 1;
185538 } else {
185539 if (KeysAreSkewed(sink)) {
185540 build_chunks_per_thread = build_chunk_count; // This forces single-threaded building
185541 } else {
185542 build_chunks_per_thread = // Same task size as in HashJoinFinalizeEvent
185543 MaxValue<idx_t>(MinValue(build_chunk_count, HashJoinFinalizeEvent::CHUNKS_PER_TASK), 1);
185544 }
185545 }
185546
185547 ht.AllocatePointerTable();
185548 ht.InitializePointerTable(0, ht.capacity);
185549
185550 global_stage = HashJoinSourceStage::BUILD;
185551}
idx_t build_chunk_idx
For HT build synchronization.
Definition duckdb.cpp:185379
static bool KeysAreSkewed(const HashJoinGlobalSinkState &sink)
Definition duckdb.cpp:184600
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PrepareProbe()

void duckdb::HashJoinGlobalSourceState::PrepareProbe ( HashJoinGlobalSinkState & sink)
185553 {
185554 sink.probe_spill->PrepareNextProbe();
185555 const auto &consumer = *sink.probe_spill->consumer;
185556
185557 probe_chunk_count = consumer.Count() == 0 ? 0 : consumer.ChunkCount();
185558 probe_chunk_done = 0;
185559
185560 global_stage = HashJoinSourceStage::PROBE;
185561 if (probe_chunk_count == 0) {
185562 TryPrepareNextStage(sink);
185563 return;
185564 }
185565}

◆ PrepareScanHT()

void duckdb::HashJoinGlobalSourceState::PrepareScanHT ( HashJoinGlobalSinkState & sink)
185567 {
185568 D_ASSERT(global_stage != HashJoinSourceStage::SCAN_HT);
185569 auto &ht = *sink.hash_table;
185570
185571 auto &data_collection = ht.GetDataCollection();
185573 full_outer_chunk_count = data_collection.ChunkCount();
185574 full_outer_chunk_done = 0;
185575
185576 full_outer_chunks_per_thread =
185577 MaxValue<idx_t>((full_outer_chunk_count + sink.num_threads - 1) / sink.num_threads, 1);
185578
185579 global_stage = HashJoinSourceStage::SCAN_HT;
185580}
idx_t full_outer_chunk_idx
For full/outer synchronization.
Definition duckdb.cpp:185393

◆ AssignTask()

bool duckdb::HashJoinGlobalSourceState::AssignTask ( HashJoinGlobalSinkState & sink,
HashJoinLocalSourceState & lstate )

Assigns a task to a local source state.

185582 {
185583 D_ASSERT(lstate.TaskFinished());
185584
185585 auto guard = Lock();
185586 switch (global_stage.load()) {
185587 case HashJoinSourceStage::BUILD:
185588 if (build_chunk_idx != build_chunk_count) {
185589 lstate.local_stage = global_stage;
185590 lstate.build_chunk_idx_from = build_chunk_idx;
185591 build_chunk_idx = MinValue<idx_t>(build_chunk_count, build_chunk_idx + build_chunks_per_thread);
185592 lstate.build_chunk_idx_to = build_chunk_idx;
185593 return true;
185594 }
185595 break;
185596 case HashJoinSourceStage::PROBE:
185597 if (sink.probe_spill->consumer && sink.probe_spill->consumer->AssignChunk(lstate.probe_local_scan)) {
185598 lstate.local_stage = global_stage;
185599 lstate.empty_ht_probe_in_progress = false;
185600 return true;
185601 }
185602 break;
185603 case HashJoinSourceStage::SCAN_HT:
185604 if (full_outer_chunk_idx != full_outer_chunk_count) {
185605 lstate.local_stage = global_stage;
185606 lstate.full_outer_chunk_idx_from = full_outer_chunk_idx;
185608 MinValue<idx_t>(full_outer_chunk_count, full_outer_chunk_idx + full_outer_chunks_per_thread);
185609 lstate.full_outer_chunk_idx_to = full_outer_chunk_idx;
185610 return true;
185611 }
185612 break;
185613 case HashJoinSourceStage::DONE:
185614 break;
185615 default:
185616 throw InternalException("Unexpected HashJoinSourceStage in AssignTask!");
185617 }
185618 return false;
185619}
Here is the call graph for this function:

◆ MaxThreads()

idx_t duckdb::HashJoinGlobalSourceState::MaxThreads ( )
inlineoverridevirtual

Reimplemented from duckdb::GlobalSourceState.

185357 {
185358 D_ASSERT(op.sink_state);
185359 auto &gstate = op.sink_state->Cast<HashJoinGlobalSinkState>();
185360
185361 idx_t count;
185362 if (gstate.probe_spill) {
185363 count = probe_count;
185364 } else if (PropagatesBuildSide(op.join_type)) {
185365 count = gstate.hash_table->Count();
185366 } else {
185367 return 0;
185368 }
185369 return count / ((idx_t)STANDARD_VECTOR_SIZE * parallel_scan_chunk_count);
185370 }
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

The documentation for this class was generated from the following file: