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::PhysicalNestedLoopJoin Class Reference

PhysicalNestedLoopJoin represents a nested loop join between two tables. More...

Inheritance diagram for duckdb::PhysicalNestedLoopJoin:
Collaboration diagram for duckdb::PhysicalNestedLoopJoin:

Public Member Functions

 PhysicalNestedLoopJoin (PhysicalPlan &physical_plan, LogicalComparisonJoin &op, PhysicalOperator &left, PhysicalOperator &right, vector< JoinCondition > cond, JoinType join_type, idx_t estimated_cardinality, unique_ptr< JoinFilterPushdownInfo > pushdown_info)
 PhysicalNestedLoopJoin (PhysicalPlan &physical_plan, LogicalComparisonJoin &op, PhysicalOperator &left, PhysicalOperator &right, vector< JoinCondition > cond, JoinType join_type, idx_t estimated_cardinality)
unique_ptr< OperatorState > GetOperatorState (ExecutionContext &context) const override
bool ParallelOperator () const override
unique_ptr< GlobalSourceState > GetGlobalSourceState (ClientContext &context) const override
unique_ptr< LocalSourceState > GetLocalSourceState (ExecutionContext &context, GlobalSourceState &gstate) const override
SourceResultType GetDataInternal (ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const override
bool IsSource () const override
bool ParallelSource () const override
unique_ptr< GlobalSinkState > GetGlobalSinkState (ClientContext &context) const override
unique_ptr< LocalSinkState > GetLocalSinkState (ExecutionContext &context) const override
SinkResultType Sink (ExecutionContext &context, DataChunk &chunk, OperatorSinkInput &input) const override
SinkCombineResultType Combine (ExecutionContext &context, OperatorSinkCombineInput &input) const override
SinkFinalizeType Finalize (Pipeline &pipeline, Event &event, ClientContext &context, OperatorSinkFinalizeInput &input) const override
bool IsSink () const override
bool ParallelSink () const override
vector< LogicalType > GetJoinTypes () const
 Returns a list of the types of the join conditions.
Public Member Functions inherited from duckdb::PhysicalComparisonJoin
 PhysicalComparisonJoin (PhysicalPlan &physical_plan, LogicalOperator &op, PhysicalOperatorType type, vector< JoinCondition > cond, JoinType join_type, idx_t estimated_cardinality)
InsertionOrderPreservingMap< string > ParamsToString () const override
Public Member Functions inherited from duckdb::PhysicalJoin
 PhysicalJoin (PhysicalPlan &physical_plan, LogicalOperator &op, PhysicalOperatorType type, JoinType join_type, idx_t estimated_cardinality)
bool EmptyResultIfRHSIsEmpty () const
void BuildPipelines (Pipeline &current, MetaPipeline &meta_pipeline) override
vector< const_reference< PhysicalOperator > > GetSources () const override
OrderPreservationType SourceOrder () const override
 The type of order emitted by the operator (as a source).
OrderPreservationType OperatorOrder () const override
 The influence the operator has on order (insertion order means no influence).
bool SinkOrderDependent () const override
Public Member Functions inherited from duckdb::CachingPhysicalOperator
 CachingPhysicalOperator (PhysicalPlan &physical_plan, PhysicalOperatorType type, vector< LogicalType > types, idx_t estimated_cardinality)
OperatorResultType Execute (ExecutionContext &context, DataChunk &input, DataChunk &chunk, GlobalOperatorState &gstate, OperatorState &state) const final
OperatorFinalizeResultType FinalExecute (ExecutionContext &context, DataChunk &chunk, GlobalOperatorState &gstate, OperatorState &state) const final
bool RequiresFinalExecute () const final
Public Member Functions inherited from duckdb::PhysicalOperator
 PhysicalOperator (PhysicalPlan &physical_plan, PhysicalOperatorType type, vector< LogicalType > types, idx_t estimated_cardinality)
 PhysicalOperator (const PhysicalOperator &other)=delete
 Deleted copy constructors.
PhysicalOperator & operator= (const PhysicalOperator &)=delete
virtual string GetName () const
virtual string ToString (ExplainFormat format=ExplainFormat::DEFAULT) const
void Print () const
virtual vector< const_reference< PhysicalOperator > > GetChildren () const
const vector< LogicalType > & GetTypes () const
 Return a vector of the types that will be returned by this operator.
virtual bool Equals (const PhysicalOperator &other) const
idx_t EstimatedThreadCount () const
 Functions to help decide how to set up pipeline dependencies.
bool CanSaturateThreads (ClientContext &context) const
virtual void Verify ()
virtual unique_ptr< GlobalOperatorState > GetGlobalOperatorState (ClientContext &context) const
virtual OperatorFinalResultType OperatorFinalize (Pipeline &pipeline, Event &event, ClientContext &context, OperatorFinalizeInput &input) const
virtual bool RequiresOperatorFinalize () const
SourceResultType GetData (ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const
virtual OperatorPartitionData GetPartitionData (ExecutionContext &context, DataChunk &chunk, GlobalSourceState &gstate, LocalSourceState &lstate, const OperatorPartitionInfo &partition_info) const
virtual bool SupportsPartitioning (const OperatorPartitionInfo &partition_info) const
virtual ProgressData GetProgress (ClientContext &context, GlobalSourceState &gstate) const
 Returns the current progress percentage, or a negative value if progress bars are not supported.
virtual ProgressData GetSinkProgress (ClientContext &context, GlobalSinkState &gstate, const ProgressData source_progress) const
 Returns the current progress percentage, or a negative value if progress bars are not supported.
virtual InsertionOrderPreservingMap< string > ExtraSourceParams (GlobalSourceState &gstate, LocalSourceState &lstate) const
virtual void PrepareFinalize (ClientContext &context, GlobalSinkState &sink_state) const
virtual SinkNextBatchType NextBatch (ExecutionContext &context, OperatorSinkNextBatchInput &input) const
virtual OperatorPartitionInfo RequiredPartitionInfo () const
bool AllSourcesSupportBatchIndex () const
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const

Static Public Member Functions

static bool IsSupported (const vector< JoinCondition > &conditions, JoinType join_type)
Static Public Member Functions inherited from duckdb::PhysicalComparisonJoin
static void ReorderConditions (vector< JoinCondition > &conditions)
 Re-order join conditions so that equality predicates are first, followed by other predicates.
static void ConstructEmptyJoinResult (JoinType type, bool has_null, DataChunk &input, DataChunk &result)
 Construct the join result of a join with an empty RHS.
static void ConstructFullOuterJoinResult (bool *found_match, ColumnDataCollection &input, DataChunk &result, ColumnDataScanState &scan_state)
 Construct the remainder of a Full Outer Join based on which tuples in the RHS found no match.
Static Public Member Functions inherited from duckdb::PhysicalJoin
static bool HasNullValues (DataChunk &chunk)
static void ConstructSemiJoinResult (DataChunk &left, DataChunk &result, bool found_match[])
static void ConstructAntiJoinResult (DataChunk &left, DataChunk &result, bool found_match[])
static void ConstructMarkJoinResult (DataChunk &join_keys, DataChunk &left, DataChunk &result, bool found_match[], bool has_null)
static void BuildJoinPipelines (Pipeline &current, MetaPipeline &meta_pipeline, PhysicalOperator &op, bool build_rhs=true)
Static Public Member Functions inherited from duckdb::PhysicalOperator
static void SetEstimatedCardinality (InsertionOrderPreservingMap< string > &result, idx_t estimated_cardinality)
static idx_t GetMaxThreadMemory (ClientContext &context)
 The maximum amount of memory the operator should use per thread.
static OperatorCachingMode SelectOperatorCachingMode (ExecutionContext &context)
 Whether operator caching is allowed in the current execution context.

Public Attributes

unique_ptr< Expression > predicate
Public Attributes inherited from duckdb::PhysicalComparisonJoin
vector< JoinCondition > conditions
unique_ptr< JoinFilterPushdownInfo > filter_pushdown
 Scans where we should push generated filters into (if any).
Public Attributes inherited from duckdb::PhysicalJoin
JoinType join_type
Public Attributes inherited from duckdb::CachingPhysicalOperator
bool caching_supported
Public Attributes inherited from duckdb::PhysicalOperator
ArenaLinkedList< reference< PhysicalOperator > > children
 The child operators.
PhysicalOperatorType type
 The physical operator type.
vector< LogicalType > types
 The return types.
idx_t estimated_cardinality
 The estimated cardinality.
unique_ptr< GlobalSinkState > sink_state
 The global sink state.
unique_ptr< GlobalOperatorState > op_state
 The global operator state.
mutex lock
 Lock for (re)setting any of the operator states.

Static Public Attributes

static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::NESTED_LOOP_JOIN
Static Public Attributes inherited from duckdb::PhysicalJoin
static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::INVALID
Static Public Attributes inherited from duckdb::CachingPhysicalOperator
static constexpr const idx_t CACHE_THRESHOLD = 64
Static Public Attributes inherited from duckdb::PhysicalOperator
static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::INVALID

Protected Member Functions

OperatorResultType ExecuteInternal (ExecutionContext &context, DataChunk &input, DataChunk &chunk, GlobalOperatorState &gstate, OperatorState &state) const override
 Child classes need to implement the ExecuteInternal method instead of the Execute.

Private Member Functions

void ResolveSimpleJoin (ExecutionContext &context, DataChunk &input, DataChunk &chunk, OperatorState &state) const
OperatorResultType ResolveComplexJoin (ExecutionContext &context, DataChunk &input, DataChunk &chunk, OperatorState &state) const

Detailed Description

PhysicalNestedLoopJoin represents a nested loop join between two tables.

Constructor & Destructor Documentation

◆ PhysicalNestedLoopJoin() [1/2]

duckdb::PhysicalNestedLoopJoin::PhysicalNestedLoopJoin ( PhysicalPlan & physical_plan,
LogicalComparisonJoin & op,
PhysicalOperator & left,
PhysicalOperator & right,
vector< JoinCondition > cond,
JoinType join_type,
idx_t estimated_cardinality,
unique_ptr< JoinFilterPushdownInfo > pushdown_info )
188152 : PhysicalComparisonJoin(physical_plan, op, PhysicalOperatorType::NESTED_LOOP_JOIN, std::move(cond), join_type,
188154 predicate(std::move(op.predicate)) {
188155 filter_pushdown = std::move(pushdown_info_p);
188156 children.push_back(left);
188157 children.push_back(right);
188158}
unique_ptr< JoinFilterPushdownInfo > filter_pushdown
Scans where we should push generated filters into (if any).
Definition duckdb.cpp:180824
idx_t estimated_cardinality
The estimated cardinality.
Definition duckdb.hpp:22154
ArenaLinkedList< reference< PhysicalOperator > > children
The child operators.
Definition duckdb.hpp:22148

◆ PhysicalNestedLoopJoin() [2/2]

duckdb::PhysicalNestedLoopJoin::PhysicalNestedLoopJoin ( PhysicalPlan & physical_plan,
LogicalComparisonJoin & op,
PhysicalOperator & left,
PhysicalOperator & right,
vector< JoinCondition > cond,
JoinType join_type,
idx_t estimated_cardinality )
188164 : PhysicalNestedLoopJoin(physical_plan, op, left, right, std::move(cond), join_type, estimated_cardinality,
188165 nullptr) {
188166}

Member Function Documentation

◆ GetOperatorState()

unique_ptr< OperatorState > duckdb::PhysicalNestedLoopJoin::GetOperatorState ( ExecutionContext & context) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

188457 {
188458 return make_uniq<PhysicalNestedLoopJoinState>(context.client, *this, conditions);
188459}

◆ ParallelOperator()

bool duckdb::PhysicalNestedLoopJoin::ParallelOperator ( ) const
inlineoverridevirtual

Reimplemented from duckdb::PhysicalOperator.

188083 {
188084 return true;
188085 }

◆ ExecuteInternal()

OperatorResultType duckdb::PhysicalNestedLoopJoin::ExecuteInternal ( ExecutionContext & context,
DataChunk & input,
DataChunk & chunk,
GlobalOperatorState & gstate,
OperatorState & state ) const
overrideprotectedvirtual

Child classes need to implement the ExecuteInternal method instead of the Execute.

Implements duckdb::CachingPhysicalOperator.

188463 {
188464 auto &gstate = sink_state->Cast<NestedLoopJoinGlobalState>();
188465
188466 if (gstate.right_payload_data.Count() == 0) {
188467 // empty RHS
188468 if (!EmptyResultIfRHSIsEmpty()) {
188469 ConstructEmptyJoinResult(join_type, gstate.has_null, input, chunk);
188470 return OperatorResultType::NEED_MORE_INPUT;
188471 } else {
188472 return OperatorResultType::FINISHED;
188473 }
188474 }
188475
188476 switch (join_type) {
188477 case JoinType::SEMI:
188478 case JoinType::ANTI:
188479 case JoinType::MARK:
188480 // simple joins can have max STANDARD_VECTOR_SIZE matches per chunk
188481 ResolveSimpleJoin(context, input, chunk, state_p);
188482 return OperatorResultType::NEED_MORE_INPUT;
188483 case JoinType::LEFT:
188484 case JoinType::INNER:
188485 case JoinType::OUTER:
188486 case JoinType::RIGHT:
188487 return ResolveComplexJoin(context, input, chunk, state_p);
188488 default:
188489 throw NotImplementedException("Unimplemented type " + JoinTypeToString(join_type) + " for nested loop join!");
188490 }
188491}
static void ConstructEmptyJoinResult(JoinType type, bool has_null, DataChunk &input, DataChunk &result)
Construct the join result of a join with an empty RHS.
Definition duckdb.cpp:183858
unique_ptr< GlobalSinkState > sink_state
The global sink state.
Definition duckdb.hpp:22157
Here is the call graph for this function:

◆ GetGlobalSourceState()

unique_ptr< GlobalSourceState > duckdb::PhysicalNestedLoopJoin::GetGlobalSourceState ( ClientContext & context) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

188643 {
188644 return make_uniq<NestedLoopJoinGlobalScanState>(*this);
188645}

◆ GetLocalSourceState()

unique_ptr< LocalSourceState > duckdb::PhysicalNestedLoopJoin::GetLocalSourceState ( ExecutionContext & context,
GlobalSourceState & gstate ) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

188648 {
188649 return make_uniq<NestedLoopJoinLocalScanState>(*this, gstate.Cast<NestedLoopJoinGlobalScanState>());
188650}

◆ GetDataInternal()

SourceResultType duckdb::PhysicalNestedLoopJoin::GetDataInternal ( ExecutionContext & context,
DataChunk & chunk,
OperatorSourceInput & input ) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

188653 {
188654 D_ASSERT(PropagatesBuildSide(join_type));
188655 // check if we need to scan any unmatched tuples from the RHS for the full/right outer join
188656 auto &sink = sink_state->Cast<NestedLoopJoinGlobalState>();
188657 auto &gstate = input.global_state.Cast<NestedLoopJoinGlobalScanState>();
188658 auto &lstate = input.local_state.Cast<NestedLoopJoinLocalScanState>();
188659
188660 // if the LHS is exhausted in a FULL/RIGHT OUTER JOIN, we scan chunks we still need to output
188661 sink.right_outer.Scan(gstate.scan_state, lstate.scan_state, chunk);
188662
188663 return chunk.size() == 0 ? SourceResultType::FINISHED : SourceResultType::HAVE_MORE_OUTPUT;
188664}
bool PropagatesBuildSide(JoinType type)
Whether the build side is propagated out of the join.
Definition duckdb.cpp:68427

◆ IsSource()

bool duckdb::PhysicalNestedLoopJoin::IsSource ( ) const
inlineoverridevirtual

Reimplemented from duckdb::PhysicalOperator.

188100 {
188101 return PropagatesBuildSide(join_type);
188102 }

◆ ParallelSource()

bool duckdb::PhysicalNestedLoopJoin::ParallelSource ( ) const
inlineoverridevirtual

Reimplemented from duckdb::PhysicalOperator.

188103 {
188104 return true;
188105 }

◆ GetGlobalSinkState()

unique_ptr< GlobalSinkState > duckdb::PhysicalNestedLoopJoin::GetGlobalSinkState ( ClientContext & context) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

188396 {
188397 return make_uniq<NestedLoopJoinGlobalState>(context, *this);
188398}

◆ GetLocalSinkState()

unique_ptr< LocalSinkState > duckdb::PhysicalNestedLoopJoin::GetLocalSinkState ( ExecutionContext & context) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

188400 {
188401 auto &gstate = sink_state->Cast<NestedLoopJoinGlobalState>();
188402 return make_uniq<NestedLoopJoinLocalState>(context.client, *this, gstate);
188403}

◆ Sink()

SinkResultType duckdb::PhysicalNestedLoopJoin::Sink ( ExecutionContext & context,
DataChunk & chunk,
OperatorSinkInput & input ) const
overridevirtual

The sink method is called constantly with new input, as long as new input is available. Note that this method CAN be called in parallel, proper locking is needed when accessing dat a inside the GlobalSinkState.

Reimplemented from duckdb::PhysicalOperator.

188341 {
188342 auto &gstate = input.global_state.Cast<NestedLoopJoinGlobalState>();
188343 auto &lstate = input.local_state.Cast<NestedLoopJoinLocalState>();
188344
188345 // resolve the join expression of the right side
188346 lstate.right_condition.Reset();
188347 lstate.rhs_executor.Execute(chunk, lstate.right_condition);
188348
188349 if (filter_pushdown && !gstate.skip_filter_pushdown) {
188350 filter_pushdown->Sink(lstate.right_condition, *lstate.local_filter_state);
188351 }
188352
188353 // if we have not seen any NULL values yet, and we are performing a MARK join, check if there are NULL values in
188354 // this chunk
188355 if (join_type == JoinType::MARK && !gstate.has_null) {
188356 if (HasNullValues(lstate.right_condition)) {
188357 gstate.has_null = true;
188358 }
188359 }
188360
188361 // append the payload data and the conditions
188362 lock_guard<mutex> nj_guard(gstate.nj_lock);
188363 gstate.right_payload_data.Append(chunk);
188364 gstate.right_condition_data.Append(lstate.right_condition);
188365 return SinkResultType::NEED_MORE_INPUT;
188366}

◆ Combine()

SinkCombineResultType duckdb::PhysicalNestedLoopJoin::Combine ( ExecutionContext & context,
OperatorSinkCombineInput & input ) const
overridevirtual

The combine is called when a single thread has completed execution of its part of the pipeline, it is the final time that a specific LocalSinkState is accessible. This method can be called in parallel while other Sink() or Combine() calls are active on the same GlobalSinkState.

Reimplemented from duckdb::PhysicalOperator.

188369 {
188370 auto &gstate = input.global_state.Cast<NestedLoopJoinGlobalState>();
188371 auto &lstate = input.local_state.Cast<NestedLoopJoinLocalState>();
188372
188373 auto &client_profiler = QueryProfiler::Get(context.client);
188374 context.thread.profiler.Flush(*this);
188375 client_profiler.Flush(context.thread.profiler);
188376 if (filter_pushdown && !gstate.skip_filter_pushdown) {
188377 filter_pushdown->Combine(*gstate.global_filter_state, *lstate.local_filter_state);
188378 }
188379 return SinkCombineResultType::FINISHED;
188380}

◆ Finalize()

SinkFinalizeType duckdb::PhysicalNestedLoopJoin::Finalize ( Pipeline & pipeline,
Event & event,
ClientContext & context,
OperatorSinkFinalizeInput & input ) const
overridevirtual

The finalize is called when ALL threads are finished execution. It is called only once per pipeline, and is entirely single threaded. If Finalize returns SinkResultType::Finished, the sink is marked as finished

Reimplemented from duckdb::PhysicalOperator.

188383 {
188384 auto &gsink = input.global_state.Cast<NestedLoopJoinGlobalState>();
188385 if (filter_pushdown && !gsink.skip_filter_pushdown) {
188386 (void)filter_pushdown->Finalize(context, nullptr, *gsink.global_filter_state, *this);
188387 }
188388
188389 gsink.right_outer.Initialize(gsink.right_payload_data.Count());
188390 if (gsink.right_payload_data.Count() == 0 && EmptyResultIfRHSIsEmpty()) {
188391 return SinkFinalizeType::NO_OUTPUT_POSSIBLE;
188392 }
188393 return SinkFinalizeType::READY;
188394}

◆ IsSink()

bool duckdb::PhysicalNestedLoopJoin::IsSink ( ) const
inlineoverridevirtual

Reimplemented from duckdb::PhysicalOperator.

188116 {
188117 return true;
188118 }

◆ ParallelSink()

bool duckdb::PhysicalNestedLoopJoin::ParallelSink ( ) const
inlineoverridevirtual

Reimplemented from duckdb::PhysicalOperator.

188119 {
188120 return true;
188121 }

◆ IsSupported()

bool duckdb::PhysicalNestedLoopJoin::IsSupported ( const vector< JoinCondition > & conditions,
JoinType join_type )
static
188257 {
188258 if (join_type == JoinType::MARK) {
188259 return true;
188260 }
188261 for (auto &cond : conditions) {
188262 if (cond.left->return_type.InternalType() == PhysicalType::STRUCT ||
188263 cond.left->return_type.InternalType() == PhysicalType::LIST ||
188264 cond.left->return_type.InternalType() == PhysicalType::ARRAY) {
188265 return false;
188266 }
188267 }
188268 // To avoid situations like https://github.com/duckdb/duckdb/issues/10046
188269 // If there is an equality in the conditions, a hash join is planned
188270 // with one condition, we can use mark join logic, otherwise we should use physical blockwise nl join
188271 if (join_type == JoinType::SEMI || join_type == JoinType::ANTI) {
188272 return conditions.size() == 1;
188273 }
188274 return true;
188275}
@ LIST
A list of some logical data type.
Definition duckdb.hpp:2813
@ STRUCT
Struct of logical types.
Definition duckdb.hpp:2816

◆ GetJoinTypes()

vector< LogicalType > duckdb::PhysicalNestedLoopJoin::GetJoinTypes ( ) const

Returns a list of the types of the join conditions.

188332 {
188333 vector<LogicalType> result;
188334 for (auto &op : conditions) {
188335 result.push_back(op.right->return_type);
188336 }
188337 return result;
188338}

◆ ResolveSimpleJoin()

void duckdb::PhysicalNestedLoopJoin::ResolveSimpleJoin ( ExecutionContext & context,
DataChunk & input,
DataChunk & chunk,
OperatorState & state ) const
private
188494 {
188495 auto &state = state_p.Cast<PhysicalNestedLoopJoinState>();
188496 auto &gstate = sink_state->Cast<NestedLoopJoinGlobalState>();
188497
188498 // resolve the left join condition for the current chunk
188499 state.left_condition.Reset();
188500 state.lhs_executor.Execute(input, state.left_condition);
188501
188502 bool found_match[STANDARD_VECTOR_SIZE] = {false};
188503 NestedLoopJoinMark::Perform(state.left_condition, gstate.right_condition_data, found_match, conditions);
188504 switch (join_type) {
188505 case JoinType::MARK:
188506 // now construct the mark join result from the found matches
188507 PhysicalJoin::ConstructMarkJoinResult(state.left_condition, input, chunk, found_match, gstate.has_null);
188508 break;
188509 case JoinType::SEMI:
188510 // construct the semi join result from the found matches
188511 PhysicalJoin::ConstructSemiJoinResult(input, chunk, found_match);
188512 break;
188513 case JoinType::ANTI:
188514 // construct the anti join result from the found matches
188515 PhysicalJoin::ConstructAntiJoinResult(input, chunk, found_match);
188516 break;
188517 default:
188518 throw NotImplementedException("Unimplemented type for simple nested loop join!");
188519 }
188520}

◆ ResolveComplexJoin()

OperatorResultType duckdb::PhysicalNestedLoopJoin::ResolveComplexJoin ( ExecutionContext & context,
DataChunk & input,
DataChunk & chunk,
OperatorState & state ) const
private
188523 {
188524 auto &state = state_p.Cast<PhysicalNestedLoopJoinState>();
188525 auto &gstate = sink_state->Cast<NestedLoopJoinGlobalState>();
188526
188527 idx_t match_count;
188528 do {
188529 if (state.fetch_next_right) {
188530 // we exhausted the chunk on the right: move to the next chunk on the right
188531 state.left_tuple = 0;
188532 state.right_tuple = 0;
188533 state.fetch_next_right = false;
188534 // check if we exhausted all chunks on the RHS
188535 if (gstate.right_condition_data.Scan(state.condition_scan_state, state.right_condition)) {
188536 if (!gstate.right_payload_data.Scan(state.payload_scan_state, state.right_payload)) {
188537 throw InternalException("Nested loop join: payload and conditions are unaligned!?");
188538 }
188539 if (state.right_condition.size() != state.right_payload.size()) {
188540 throw InternalException("Nested loop join: payload and conditions are unaligned!?");
188541 }
188542 } else {
188543 // we exhausted all chunks on the right: move to the next chunk on the left
188544 state.fetch_next_left = true;
188545 if (state.left_outer.Enabled()) {
188546 // left join: before we move to the next chunk, see if we need to output any vectors that didn't
188547 // have a match found
188548 state.left_outer.ConstructLeftJoinResult(input, chunk);
188549 state.left_outer.Reset();
188550 }
188551 return OperatorResultType::NEED_MORE_INPUT;
188552 }
188553 }
188554 if (state.fetch_next_left) {
188555 // resolve the left join condition for the current chunk
188556 state.left_condition.Reset();
188557 state.lhs_executor.Execute(input, state.left_condition);
188558
188559 state.left_tuple = 0;
188560 state.right_tuple = 0;
188561 gstate.right_condition_data.InitializeScan(state.condition_scan_state);
188562 gstate.right_condition_data.Scan(state.condition_scan_state, state.right_condition);
188563
188564 gstate.right_payload_data.InitializeScan(state.payload_scan_state);
188565 gstate.right_payload_data.Scan(state.payload_scan_state, state.right_payload);
188566 state.fetch_next_left = false;
188567 }
188568 // now we have a left and a right chunk that we can join together
188569 // note that we only get here in the case of a LEFT, INNER or FULL join
188570 auto &left_chunk = input;
188571 auto &right_condition = state.right_condition;
188572 auto &right_payload = state.right_payload;
188573
188574 // sanity check
188575 left_chunk.Verify();
188576 right_condition.Verify();
188577 right_payload.Verify();
188578
188579 // now perform the join
188580 SelectionVector lvector(STANDARD_VECTOR_SIZE), rvector(STANDARD_VECTOR_SIZE);
188581 match_count = NestedLoopJoinInner::Perform(state.left_tuple, state.right_tuple, state.left_condition,
188582 right_condition, lvector, rvector, conditions);
188583 // we have finished resolving the join conditions
188584 if (match_count > 0) {
188585 // we have matching tuples!
188586 // construct the result
188587 chunk.Slice(input, lvector, match_count);
188588 chunk.Slice(right_payload, rvector, match_count, input.ColumnCount());
188589
188590 // If we have a predicate, apply it to the result
188591 if (predicate) {
188592 auto &sel = state.pred_matches;
188593 match_count = state.pred_executor.SelectExpression(chunk, sel);
188594 chunk.Slice(sel, match_count);
188595 lvector.SliceInPlace(sel, match_count);
188596 rvector.SliceInPlace(sel, match_count);
188597 }
188598
188599 state.left_outer.SetMatches(lvector, match_count);
188600 gstate.right_outer.SetMatches(rvector, match_count, state.condition_scan_state.current_row_index);
188601 }
188602
188603 // check if we exhausted the RHS, if we did we need to move to the next right chunk in the next iteration
188604 if (state.right_tuple >= right_condition.size()) {
188605 state.fetch_next_right = true;
188606 }
188607 } while (match_count == 0);
188608 return OperatorResultType::HAVE_MORE_OUTPUT;
188609}
DUCKDB_API void Verify()
Definition duckdb.cpp:117115
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: