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::PhysicalBlockwiseNLJoin Class Reference
Inheritance diagram for duckdb::PhysicalBlockwiseNLJoin:
Collaboration diagram for duckdb::PhysicalBlockwiseNLJoin:

Public Member Functions

 PhysicalBlockwiseNLJoin (PhysicalPlan &physical_plan, LogicalOperator &op, PhysicalOperator &left, PhysicalOperator &right, unique_ptr< Expression > condition, 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
SinkFinalizeType Finalize (Pipeline &pipeline, Event &event, ClientContext &context, OperatorSinkFinalizeInput &input) const override
bool IsSink () const override
bool ParallelSink () const override
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 SinkCombineResultType Combine (ExecutionContext &context, OperatorSinkCombineInput &input) 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

Public Attributes

unique_ptr< Expression > condition
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::BLOCKWISE_NL_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.

Additional Inherited Members

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.

Detailed Description

PhysicalBlockwiseNLJoin represents a nested loop join between two tables on arbitrary expressions. This is different from the PhysicalNestedLoopJoin in that it does not require expressions to be comparisons between the LHS and the RHS.

Constructor & Destructor Documentation

◆ PhysicalBlockwiseNLJoin()

duckdb::PhysicalBlockwiseNLJoin::PhysicalBlockwiseNLJoin ( PhysicalPlan & physical_plan,
LogicalOperator & op,
PhysicalOperator & left,
PhysicalOperator & right,
unique_ptr< Expression > condition,
JoinType join_type,
idx_t estimated_cardinality )
183522 : PhysicalJoin(physical_plan, op, PhysicalOperatorType::BLOCKWISE_NL_JOIN, join_type, estimated_cardinality),
183523 condition(std::move(condition)) {
183524 children.push_back(left);
183525 children.push_back(right);
183526 // MARK and SINGLE joins not handled
183527 D_ASSERT(join_type != JoinType::MARK);
183528 D_ASSERT(join_type != JoinType::SINGLE);
183529}
idx_t estimated_cardinality
The estimated cardinality.
Definition duckdb.hpp:22154
ArenaLinkedList< reference< PhysicalOperator > > children
The child operators.
Definition duckdb.hpp:22148

Member Function Documentation

◆ GetOperatorState()

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

Reimplemented from duckdb::PhysicalOperator.

183612 {
183613 auto &gstate = sink_state->Cast<BlockwiseNLJoinGlobalState>();
183614 auto result = make_uniq<BlockwiseNLJoinState>(context, gstate.right_chunks, *this);
183615 if (join_type == JoinType::SEMI || join_type == JoinType::ANTI) {
183616 vector<LogicalType> intermediate_types;
183617 for (auto &type : children[0].get().GetTypes()) {
183618 intermediate_types.emplace_back(type);
183619 }
183620 for (auto &type : children[1].get().GetTypes()) {
183621 intermediate_types.emplace_back(type);
183622 }
183623 result->intermediate_chunk.Initialize(Allocator::DefaultAllocator(), intermediate_types);
183624 }
183625 if (join_type == JoinType::RIGHT_ANTI || join_type == JoinType::RIGHT_SEMI) {
183626 throw NotImplementedException("physical blockwise RIGHT_SEMI/RIGHT_ANTI join not yet implemented");
183627 }
183628 return std::move(result);
183629}
const vector< LogicalType > & GetTypes() const
Return a vector of the types that will be returned by this operator.
Definition duckdb.hpp:22174
unique_ptr< GlobalSinkState > sink_state
The global sink state.
Definition duckdb.hpp:22157
PhysicalOperatorType type
The physical operator type.
Definition duckdb.hpp:22150
__host__ cudaTextureObject_t get() const noexcept

◆ ParallelOperator()

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

Reimplemented from duckdb::PhysicalOperator.

183368 {
183369 return true;
183370 }

◆ ExecuteInternal()

OperatorResultType duckdb::PhysicalBlockwiseNLJoin::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.

183633 {
183634 D_ASSERT(input.size() > 0);
183635 auto &state = state_p.Cast<BlockwiseNLJoinState>();
183636 auto &gstate = sink_state->Cast<BlockwiseNLJoinGlobalState>();
183637
183638 if (gstate.right_chunks.Count() == 0) {
183639 // empty RHS
183640 if (!EmptyResultIfRHSIsEmpty()) {
183641 PhysicalComparisonJoin::ConstructEmptyJoinResult(join_type, false, input, chunk);
183642 return OperatorResultType::NEED_MORE_INPUT;
183643 } else {
183644 return OperatorResultType::FINISHED;
183645 }
183646 }
183647
183648 DataChunk *intermediate_chunk = &chunk;
183649 if (join_type == JoinType::SEMI || join_type == JoinType::ANTI) {
183650 intermediate_chunk = &state.intermediate_chunk;
183651 intermediate_chunk->Reset();
183652 }
183653
183654 // now perform the actual join
183655 // we perform a cross product, then execute the expression directly on the cross product result
183656 idx_t result_count = 0;
183657
183658 auto result = state.cross_product.Execute(input, *intermediate_chunk);
183659 if (result == OperatorResultType::NEED_MORE_INPUT) {
183660 // exhausted input, have to pull new LHS chunk
183661 if (state.left_outer.Enabled()) {
183662 // left join: before we move to the next chunk, see if we need to output any vectors that didn't
183663 // have a match found
183664 state.left_outer.ConstructLeftJoinResult(input, *intermediate_chunk);
183665 state.left_outer.Reset();
183666 }
183667
183668 if (join_type == JoinType::SEMI) {
183669 PhysicalJoin::ConstructSemiJoinResult(input, chunk, state.found_match);
183670 }
183671 if (join_type == JoinType::ANTI) {
183672 PhysicalJoin::ConstructAntiJoinResult(input, chunk, state.found_match);
183673 }
183674 state.ResetMatches();
183675
183676 return OperatorResultType::NEED_MORE_INPUT;
183677 }
183678
183679 // now perform the computation
183680 result_count = state.executor.SelectExpression(*intermediate_chunk, state.match_sel);
183681
183682 // handle anti and semi joins with different logic
183683 if (result_count > 0) {
183684 // found a match!
183685 // handle anti semi join conditions first
183686 if (join_type == JoinType::ANTI || join_type == JoinType::SEMI) {
183687 if (state.cross_product.ScanLHS()) {
183688 state.found_match[state.cross_product.PositionInChunk()] = true;
183689 } else {
183690 for (idx_t i = 0; i < result_count; i++) {
183691 state.found_match[state.match_sel.get_index(i)] = true;
183692 }
183693 }
183694 intermediate_chunk->Reset();
183695 // trick the loop to continue as semi and anti joins will never produce more output than
183696 // the LHS cardinality
183697 result_count = 0;
183698 } else {
183699 // check if the cross product is scanning the LHS or the RHS in its entirety
183700 if (!state.cross_product.ScanLHS()) {
183701 // set the match flags in the LHS
183702 state.left_outer.SetMatches(state.match_sel, result_count);
183703 // set the match flag in the RHS
183704 gstate.right_outer.SetMatch(state.cross_product.ScanPosition() + state.cross_product.PositionInChunk());
183705 } else {
183706 // set the match flag in the LHS
183707 state.left_outer.SetMatch(state.cross_product.PositionInChunk());
183708 // set the match flags in the RHS
183709 gstate.right_outer.SetMatches(state.match_sel, result_count, state.cross_product.ScanPosition());
183710 }
183711 intermediate_chunk->Slice(state.match_sel, result_count);
183712 }
183713 } else {
183714 // no result: reset the chunk
183715 intermediate_chunk->Reset();
183716 }
183717
183718 return OperatorResultType::HAVE_MORE_OUTPUT;
183719}
DUCKDB_API void Reset()
Definition duckdb.cpp:116840
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
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the call graph for this function:

◆ GetGlobalSourceState()

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

Reimplemented from duckdb::PhysicalOperator.

183760 {
183761 return make_uniq<BlockwiseNLJoinGlobalScanState>(*this);
183762}

◆ GetLocalSourceState()

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

Reimplemented from duckdb::PhysicalOperator.

183765 {
183766 return make_uniq<BlockwiseNLJoinLocalScanState>(*this, gstate.Cast<BlockwiseNLJoinGlobalScanState>());
183767}

◆ GetDataInternal()

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

Reimplemented from duckdb::PhysicalOperator.

183770 {
183771 D_ASSERT(PropagatesBuildSide(join_type));
183772 // check if we need to scan any unmatched tuples from the RHS for the full/right outer join
183773 auto &sink = sink_state->Cast<BlockwiseNLJoinGlobalState>();
183774 auto &gstate = input.global_state.Cast<BlockwiseNLJoinGlobalScanState>();
183775 auto &lstate = input.local_state.Cast<BlockwiseNLJoinLocalScanState>();
183776
183777 // if the LHS is exhausted in a FULL/RIGHT OUTER JOIN, we scan chunks we still need to output
183778 sink.right_outer.Scan(gstate.scan_state, lstate.scan_state, chunk);
183779
183780 return chunk.size() == 0 ? SourceResultType::FINISHED : SourceResultType::HAVE_MORE_OUTPUT;
183781}
bool PropagatesBuildSide(JoinType type)
Whether the build side is propagated out of the join.
Definition duckdb.cpp:68427

◆ IsSource()

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

Reimplemented from duckdb::PhysicalOperator.

183385 {
183386 return PropagatesBuildSide(join_type);
183387 }

◆ ParallelSource()

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

Reimplemented from duckdb::PhysicalOperator.

183388 {
183389 return true;
183390 }

◆ GetGlobalSinkState()

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

Reimplemented from duckdb::PhysicalOperator.

183551 {
183552 return make_uniq<BlockwiseNLJoinGlobalState>(context, *this);
183553}

◆ GetLocalSinkState()

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

Reimplemented from duckdb::PhysicalOperator.

183555 {
183556 return make_uniq<BlockwiseNLJoinLocalState>();
183557}

◆ Sink()

SinkResultType duckdb::PhysicalBlockwiseNLJoin::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.

183560 {
183561 auto &gstate = input.global_state.Cast<BlockwiseNLJoinGlobalState>();
183562 lock_guard<mutex> nl_lock(gstate.lock);
183563 gstate.right_chunks.Append(chunk);
183564 return SinkResultType::NEED_MORE_INPUT;
183565}

◆ Finalize()

SinkFinalizeType duckdb::PhysicalBlockwiseNLJoin::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.

183571 {
183572 auto &gstate = input.global_state.Cast<BlockwiseNLJoinGlobalState>();
183573 gstate.right_outer.Initialize(gstate.right_chunks.Count());
183574
183575 if (gstate.right_chunks.Count() == 0 && EmptyResultIfRHSIsEmpty()) {
183576 return SinkFinalizeType::NO_OUTPUT_POSSIBLE;
183577 }
183578 return SinkFinalizeType::READY;
183579}
Here is the call graph for this function:

◆ IsSink()

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

Reimplemented from duckdb::PhysicalOperator.

183400 {
183401 return true;
183402 }

◆ ParallelSink()

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

Reimplemented from duckdb::PhysicalOperator.

183403 {
183404 return true;
183405 }

◆ ParamsToString()

InsertionOrderPreservingMap< string > duckdb::PhysicalBlockwiseNLJoin::ParamsToString ( ) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

183721 {
183722 InsertionOrderPreservingMap<string> result;
183723 result["Join Type"] = EnumUtil::ToString(join_type);
183724 result["Condition"] = condition->GetName();
183725 return result;
183726}

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