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

Public Member Functions

 PhysicalPiecewiseMergeJoin (PhysicalPlan &physical_plan, LogicalComparisonJoin &op, PhysicalOperator &left, PhysicalOperator &right, vector< JoinCondition > cond, JoinType join_type, idx_t estimated_cardinality, unique_ptr< JoinFilterPushdownInfo > pushdown_info)
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
Public Member Functions inherited from duckdb::PhysicalRangeJoin
 PhysicalRangeJoin (PhysicalPlan &physical_plan, LogicalComparisonJoin &op, PhysicalOperatorType type, PhysicalOperator &left, PhysicalOperator &right, vector< JoinCondition > cond, JoinType join_type, idx_t estimated_cardinality, unique_ptr< JoinFilterPushdownInfo > pushdown_info)
void ProjectResult (DataChunk &chunk, DataChunk &result) const
 Utility to project full width internal chunks to projected results.
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

Public Attributes

vector< LogicalType > join_key_types
vector< BoundOrderByNode > lhs_orders
vector< BoundOrderByNode > rhs_orders
Public Attributes inherited from duckdb::PhysicalRangeJoin
ProjectionMapping left_projection_map
ProjectionMapping right_projection_map
vector< LogicalType > unprojected_types
 The full set of types (left + right child).
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::PIECEWISE_MERGE_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

Additional Inherited Members

Public Types inherited from duckdb::PhysicalRangeJoin
using ProjectionMapping = vector<column_t>
Static Public Member Functions inherited from duckdb::PhysicalRangeJoin
static void SliceSortedPayload (DataChunk &chunk, GlobalSortedTable &table, ExternalBlockIteratorState &state, TupleDataChunkState &chunk_state, const idx_t chunk_idx, const unsafe_vector< idx_t > &result, SortedRunScanState &scan_state)
static idx_t SelectJoinTail (const ExpressionType &condition, Vector &left, Vector &right, const SelectionVector *sel, idx_t count, SelectionVector *true_sel)
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.

Detailed Description

PhysicalPiecewiseMergeJoin represents a piecewise merge loop join between two tables

Constructor & Destructor Documentation

◆ PhysicalPiecewiseMergeJoin()

duckdb::PhysicalPiecewiseMergeJoin::PhysicalPiecewiseMergeJoin ( PhysicalPlan & physical_plan,
LogicalComparisonJoin & op,
PhysicalOperator & left,
PhysicalOperator & right,
vector< JoinCondition > cond,
JoinType join_type,
idx_t estimated_cardinality,
unique_ptr< JoinFilterPushdownInfo > pushdown_info )
188770 : PhysicalRangeJoin(physical_plan, op, PhysicalOperatorType::PIECEWISE_MERGE_JOIN, left, right, std::move(cond),
188771 join_type, estimated_cardinality, std::move(pushdown_info_p)) {
188772 for (auto &join_cond : conditions) {
188773 D_ASSERT(join_cond.left->return_type == join_cond.right->return_type);
188774 join_key_types.push_back(join_cond.left->return_type);
188775
188776 // Convert the conditions to sort orders
188777 auto left_expr = join_cond.left->Copy();
188778 auto right_expr = join_cond.right->Copy();
188779 switch (join_cond.comparison) {
188780 case ExpressionType::COMPARE_LESSTHAN:
188781 case ExpressionType::COMPARE_LESSTHANOREQUALTO:
188782 lhs_orders.emplace_back(OrderType::ASCENDING, OrderByNullType::NULLS_LAST, std::move(left_expr));
188783 rhs_orders.emplace_back(OrderType::ASCENDING, OrderByNullType::NULLS_LAST, std::move(right_expr));
188784 break;
188785 case ExpressionType::COMPARE_GREATERTHAN:
188786 case ExpressionType::COMPARE_GREATERTHANOREQUALTO:
188787 lhs_orders.emplace_back(OrderType::DESCENDING, OrderByNullType::NULLS_LAST, std::move(left_expr));
188788 rhs_orders.emplace_back(OrderType::DESCENDING, OrderByNullType::NULLS_LAST, std::move(right_expr));
188789 break;
188790 case ExpressionType::COMPARE_NOTEQUAL:
188791 case ExpressionType::COMPARE_DISTINCT_FROM:
188792 // Allowed in multi-predicate joins, but can't be first/sort.
188793 D_ASSERT(!lhs_orders.empty());
188794 lhs_orders.emplace_back(OrderType::INVALID, OrderByNullType::NULLS_LAST, std::move(left_expr));
188795 rhs_orders.emplace_back(OrderType::INVALID, OrderByNullType::NULLS_LAST, std::move(right_expr));
188796 break;
188797
188798 default:
188799 // COMPARE EQUAL not supported with merge join
188800 throw NotImplementedException("Unimplemented join type for merge join");
188801 }
188802 }
188803}
idx_t estimated_cardinality
The estimated cardinality.
Definition duckdb.hpp:22154

Member Function Documentation

◆ GetOperatorState()

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

Reimplemented from duckdb::PhysicalOperator.

189033 {
189034 return make_uniq<PiecewiseMergeJoinState>(context.client, *this);
189035}

◆ ParallelOperator()

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

Reimplemented from duckdb::PhysicalOperator.

188703 {
188704 return true;
188705 }

◆ ExecuteInternal()

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

189436 {
189437 auto &gstate = sink_state->Cast<MergeJoinGlobalState>();
189438
189439 if (gstate.Count() == 0) {
189440 // empty RHS
189441 if (!EmptyResultIfRHSIsEmpty()) {
189442 ConstructEmptyJoinResult(join_type, gstate.table->has_null, input, chunk);
189443 return OperatorResultType::NEED_MORE_INPUT;
189444 } else {
189445 return OperatorResultType::FINISHED;
189446 }
189447 }
189448
189449 input.Verify();
189450 switch (join_type) {
189451 case JoinType::SEMI:
189452 case JoinType::ANTI:
189453 case JoinType::MARK:
189454 // simple joins can have max STANDARD_VECTOR_SIZE matches per chunk
189455 ResolveSimpleJoin(context, input, chunk, state);
189456 return OperatorResultType::NEED_MORE_INPUT;
189457 case JoinType::LEFT:
189458 case JoinType::INNER:
189459 case JoinType::RIGHT:
189460 case JoinType::OUTER:
189461 return ResolveComplexJoin(context, input, chunk, state);
189462 default:
189463 throw NotImplementedException("Unimplemented type for piecewise merge loop join!");
189464 }
189465}
DUCKDB_API void Verify()
Definition duckdb.cpp:117115
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::PhysicalPiecewiseMergeJoin::GetGlobalSourceState ( ClientContext & context) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

189509 {
189510 auto &gsink = sink_state->Cast<MergeJoinGlobalState>();
189511 return make_uniq<PiecewiseJoinGlobalScanState>(*gsink.table->sorted->payload_data);
189512}

◆ GetLocalSourceState()

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

Reimplemented from duckdb::PhysicalOperator.

189515 {
189516 return make_uniq<PiecewiseJoinLocalScanState>(gstate.Cast<PiecewiseJoinGlobalScanState>());
189517}

◆ GetDataInternal()

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

Reimplemented from duckdb::PhysicalOperator.

189520 {
189521 D_ASSERT(PropagatesBuildSide(join_type));
189522 // check if we need to scan any unmatched tuples from the RHS for the full/right outer join
189523 auto &gsink = sink_state->Cast<MergeJoinGlobalState>();
189524 auto &gsource = source.global_state.Cast<PiecewiseJoinGlobalScanState>();
189525
189526 // RHS was empty, so nothing to do?
189527 if (!gsink.table->count) {
189528 return SourceResultType::FINISHED;
189529 }
189530
189531 // if the LHS is exhausted in a FULL/RIGHT OUTER JOIN, we scan the found_match for any chunks we
189532 // still need to output
189533 const auto found_match = gsink.table->found_match.get();
189534
189535 auto &lsource = source.local_state.Cast<PiecewiseJoinLocalScanState>();
189536 auto &rhs_chunk = lsource.rhs_chunk;
189537 auto &rsel = lsource.rsel;
189538 for (;;) {
189539 // Read the next sorted chunk
189540 rhs_chunk.Reset();
189541 const auto rhs_pos = gsource.Scan(lsource.scanner, rhs_chunk);
189542
189543 const auto count = rhs_chunk.size();
189544 if (count == 0) {
189545 return result.size() == 0 ? SourceResultType::FINISHED : SourceResultType::HAVE_MORE_OUTPUT;
189546 }
189547
189548 idx_t result_count = 0;
189549 // figure out which tuples didn't find a match in the RHS
189550 for (idx_t i = 0; i < count; i++) {
189551 if (!found_match[rhs_pos + i]) {
189552 rsel.set_index(result_count++, i);
189553 }
189554 }
189555
189556 if (result_count > 0) {
189557 // if there were any tuples that didn't find a match, output them
189558 const idx_t left_column_count = children[0].get().GetTypes().size();
189559 for (idx_t col_idx = 0; col_idx < left_column_count; ++col_idx) {
189560 result.data[col_idx].SetVectorType(VectorType::CONSTANT_VECTOR);
189561 ConstantVector::SetNull(result.data[col_idx], true);
189562 }
189563 const idx_t right_column_count = children[1].get().GetTypes().size();
189564 for (idx_t col_idx = 0; col_idx < right_column_count; ++col_idx) {
189565 result.data[left_column_count + col_idx].Slice(rhs_chunk.data[col_idx], rsel, result_count);
189566 }
189567 result.SetCardinality(result_count);
189568 break;
189569 }
189570 }
189571
189572 return result.size() == 0 ? SourceResultType::FINISHED : SourceResultType::HAVE_MORE_OUTPUT;
189573}
ArenaLinkedList< reference< PhysicalOperator > > children
The child operators.
Definition duckdb.hpp:22148
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
bool PropagatesBuildSide(JoinType type)
Whether the build side is propagated out of the join.
Definition duckdb.cpp:68427

◆ IsSource()

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

Reimplemented from duckdb::PhysicalOperator.

188720 {
188721 return PropagatesBuildSide(join_type);
188722 }

◆ ParallelSource()

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

Reimplemented from duckdb::PhysicalOperator.

188723 {
188724 return true;
188725 }

◆ GetGlobalSinkState()

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

Reimplemented from duckdb::PhysicalOperator.

188859 {
188860 return make_uniq<MergeJoinGlobalState>(context, *this);
188861}

◆ GetLocalSinkState()

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

Reimplemented from duckdb::PhysicalOperator.

188863 {
188864 // We only sink the RHS
188865 auto &gstate = sink_state->Cast<MergeJoinGlobalState>();
188866 return make_uniq<MergeJoinLocalState>(context, gstate, 1U);
188867}

◆ Sink()

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

188875 {
188876 auto &gstate = input.global_state.Cast<MergeJoinGlobalState>();
188877 auto &lstate = input.local_state.Cast<MergeJoinLocalState>();
188878
188879 gstate.Sink(context, chunk, lstate);
188880
188881 if (filter_pushdown && !gstate.skip_filter_pushdown) {
188882 filter_pushdown->Sink(lstate.table.keys, *lstate.local_filter_state);
188883 }
188884
188885 return SinkResultType::NEED_MORE_INPUT;
188886}
unique_ptr< JoinFilterPushdownInfo > filter_pushdown
Scans where we should push generated filters into (if any).
Definition duckdb.cpp:180824

◆ Combine()

SinkCombineResultType duckdb::PhysicalPiecewiseMergeJoin::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.

188889 {
188890 auto &gstate = input.global_state.Cast<MergeJoinGlobalState>();
188891 auto &lstate = input.local_state.Cast<MergeJoinLocalState>();
188892 gstate.table->Combine(context, lstate.table);
188893 auto &client_profiler = QueryProfiler::Get(context.client);
188894
188895 context.thread.profiler.Flush(*this);
188896 client_profiler.Flush(context.thread.profiler);
188897 if (filter_pushdown && !gstate.skip_filter_pushdown) {
188898 filter_pushdown->Combine(*gstate.global_filter_state, *lstate.local_filter_state);
188899 }
188900
188901 return SinkCombineResultType::FINISHED;
188902}

◆ Finalize()

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

188908 {
188909 auto &gstate = input.global_state.Cast<MergeJoinGlobalState>();
188910 if (filter_pushdown && !gstate.skip_filter_pushdown) {
188911 (void)filter_pushdown->Finalize(client, nullptr, *gstate.global_filter_state, *this);
188912 }
188913
188914 gstate.table->Finalize(client, input.interrupt_state);
188915
188916 if (PropagatesBuildSide(join_type)) {
188917 // for FULL/RIGHT OUTER JOIN, initialize found_match to false for every tuple
188918 gstate.table->IntializeMatches();
188919 }
188920
188921 if (gstate.table->Count() == 0 && EmptyResultIfRHSIsEmpty()) {
188922 // Empty input!
188923 gstate.table->MaterializeEmpty(client);
188924 return SinkFinalizeType::NO_OUTPUT_POSSIBLE;
188925 }
188926
188927 // Sort the current input child
188928 gstate.table->Materialize(pipeline, event);
188929
188930 return SinkFinalizeType::READY;
188931}
Here is the call graph for this function:

◆ IsSink()

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

Reimplemented from duckdb::PhysicalOperator.

188736 {
188737 return true;
188738 }

◆ ParallelSink()

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

Reimplemented from duckdb::PhysicalOperator.

188739 {
188740 return true;
188741 }

◆ ResolveSimpleJoin()

void duckdb::PhysicalPiecewiseMergeJoin::ResolveSimpleJoin ( ExecutionContext & context,
DataChunk & input,
DataChunk & chunk,
OperatorState & state ) const
private
189147 {
189148 auto &state = state_p.Cast<PiecewiseMergeJoinState>();
189149 auto &gstate = sink_state->Cast<MergeJoinGlobalState>();
189150
189151 state.ResolveJoinKeys(context, input);
189152 auto &lhs_table = *state.lhs_global_table;
189153 auto &lhs_keys = state.lhs_local_table->keys;
189154
189155 // perform the actual join
189156 bool found_match[STANDARD_VECTOR_SIZE];
189157 memset(found_match, 0, sizeof(found_match));
189158 MergeJoinSimpleBlocks(state, gstate, found_match, conditions[0].comparison);
189159
189160 // use the sorted payload
189161 const auto lhs_not_null = lhs_table.count - lhs_table.has_null;
189162 auto &payload = state.lhs_payload;
189163
189164 // now construct the result based on the join result
189165 switch (join_type) {
189166 case JoinType::MARK: {
189167 // The only part of the join keys that is actually used is the validity mask.
189168 // Since the payload is sorted, we can just set the tail end of the validity masks to invalid.
189169 for (auto &key : lhs_keys.data) {
189170 key.Flatten(lhs_keys.size());
189171 auto &mask = FlatVector::Validity(key);
189172 if (mask.AllValid()) {
189173 continue;
189174 }
189175 mask.SetAllValid(lhs_not_null);
189176 for (idx_t i = lhs_not_null; i < lhs_table.count; ++i) {
189177 mask.SetInvalid(i);
189178 }
189179 }
189180 // So we make a set of keys that have the validity mask set for the
189181 PhysicalJoin::ConstructMarkJoinResult(lhs_keys, payload, chunk, found_match, gstate.table->has_null);
189182 break;
189183 }
189184 case JoinType::SEMI:
189185 PhysicalJoin::ConstructSemiJoinResult(payload, chunk, found_match);
189186 break;
189187 case JoinType::ANTI:
189188 PhysicalJoin::ConstructAntiJoinResult(payload, chunk, found_match);
189189 break;
189190 default:
189191 throw NotImplementedException("Unimplemented join type for merge join");
189192 }
189193}
GMat mask(const GMat &src, const GMat &mask)

◆ ResolveComplexJoin()

OperatorResultType duckdb::PhysicalPiecewiseMergeJoin::ResolveComplexJoin ( ExecutionContext & context,
DataChunk & input,
DataChunk & chunk,
OperatorState & state ) const
private
189308 {
189309 auto &state = state_p.Cast<PiecewiseMergeJoinState>();
189310 auto &gstate = sink_state->Cast<MergeJoinGlobalState>();
189311 const auto left_cols = input.ColumnCount();
189312 const auto tail_cols = conditions.size() - 1;
189313
189314 do {
189315 if (state.first_fetch) {
189316 state.ResolveJoinKeys(context, input);
189317 state.lhs_payload.Verify();
189318
189319 state.right_chunk_index = 0;
189320 state.right_base = 0;
189321 state.left_position = 0;
189322 state.prev_left_index = 0;
189323 state.right_position = 0;
189324 state.first_fetch = false;
189325 state.finished = false;
189326 }
189327 if (state.finished) {
189328 if (state.left_outer.Enabled()) {
189329 // left join: before we move to the next chunk, see if we need to output any vectors that didn't
189330 // have a match found
189331 state.left_outer.ConstructLeftJoinResult(state.lhs_payload, chunk);
189332 state.left_outer.Reset();
189333 }
189334 state.first_fetch = true;
189335 state.finished = false;
189336 return OperatorResultType::NEED_MORE_INPUT;
189337 }
189338
189339 auto &lhs_table = *state.lhs_global_table;
189340 const auto lhs_not_null = lhs_table.count - lhs_table.has_null;
189341 ChunkMergeInfo left_info(*state.lhs_iterator, 0, state.left_position, lhs_not_null);
189342
189343 auto &rhs_table = *gstate.table;
189344 auto &rhs_iterator = *state.rhs_iterator;
189345 const auto rhs_not_null = SortedChunkNotNull(state.right_chunk_index, rhs_table.count, rhs_table.has_null);
189346 ChunkMergeInfo right_info(rhs_iterator, state.right_chunk_index, state.right_position, rhs_not_null);
189347
189348 // Repin so we don't hang on to data after we have scanned it
189349 // Note we only do this for the RHS because the LHS is only one chunk.
189350 rhs_table.Repin(rhs_iterator);
189351
189352 idx_t result_count = MergeJoinComplexBlocks(state.sort_key_type, left_info, right_info,
189353 conditions[0].comparison, state.prev_left_index);
189354 if (result_count == 0) {
189355 // exhausted this chunk on the right side
189356 // move to the next right chunk
189357 state.left_position = 0;
189358 state.right_position = 0;
189359 state.right_base += STANDARD_VECTOR_SIZE;
189360 state.right_chunk_index++;
189361 if (state.right_chunk_index >= rhs_table.BlockCount()) {
189362 state.finished = true;
189363 }
189364 } else {
189365 // found matches: extract them
189366 SliceSortedPayload(state.rhs_input, rhs_table, rhs_iterator, state.rhs_chunk_state, right_info.block_idx,
189367 right_info.rhs, *state.rhs_scan_state);
189368
189369 chunk.Reset();
189370 for (idx_t col_idx = 0; col_idx < chunk.ColumnCount(); ++col_idx) {
189371 if (col_idx < left_cols) {
189372 chunk.data[col_idx].Slice(state.lhs_payload.data[col_idx], left_info.lhs, result_count);
189373 } else {
189374 chunk.data[col_idx].Reference(state.rhs_input.data[col_idx - left_cols]);
189375 }
189376 }
189377 chunk.SetCardinality(result_count);
189378
189379 auto sel = FlatVector::IncrementalSelectionVector();
189380 if (tail_cols) {
189381 // If there are more expressions to compute,
189382 // split the result chunk into the left and right halves
189383 // so we can compute the values for comparison.
189384 state.rhs_executor.SetChunk(state.rhs_input);
189385 state.rhs_keys.Reset();
189386
189387 auto tail_count = result_count;
189388 for (size_t cmp_idx = 1; cmp_idx < conditions.size(); ++cmp_idx) {
189389 Vector left(state.lhs_local_table->keys.data[cmp_idx]);
189390 left.Slice(left_info.lhs, result_count);
189391
189392 auto &right = state.rhs_keys.data[cmp_idx];
189393 state.rhs_executor.ExecuteExpression(cmp_idx, right);
189394
189395 if (tail_count < result_count) {
189396 left.Slice(*sel, tail_count);
189397 right.Slice(*sel, tail_count);
189398 }
189399 tail_count =
189400 SelectJoinTail(conditions[cmp_idx].comparison, left, right, sel, tail_count, &state.sel);
189401 sel = &state.sel;
189402 }
189403
189404 if (tail_count < result_count) {
189405 result_count = tail_count;
189406 if (result_count == 0) {
189407 // Need to reset here otherwise we may use the non-flat chunk when constructing LEFT/OUTER
189408 chunk.Reset();
189409 } else {
189410 chunk.Slice(*sel, result_count);
189411 }
189412 }
189413 }
189414
189415 // found matches: mark the found matches if required
189416 if (state.left_outer.Enabled()) {
189417 for (idx_t i = 0; i < result_count; i++) {
189418 state.left_outer.SetMatch(left_info.lhs[sel->get_index(i)]);
189419 }
189420 }
189421 if (gstate.table->found_match) {
189422 // Absolute position of the block + start position inside that block
189423 for (idx_t i = 0; i < result_count; i++) {
189424 gstate.table->found_match[state.right_base + right_info.rhs[sel->get_index(i)]] = true;
189425 }
189426 }
189427 chunk.SetCardinality(result_count);
189428 chunk.Verify();
189429 }
189430 } while (chunk.size() == 0);
189431 return OperatorResultType::HAVE_MORE_OUTPUT;
189432}
DUCKDB_API void Reset()
Definition duckdb.cpp:116840
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445

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