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::JoinHashTable::ScanStructure Struct Reference
Collaboration diagram for duckdb::JoinHashTable::ScanStructure:

Public Member Functions

 ScanStructure (JoinHashTable &ht, TupleDataChunkState &key_state)
void Next (DataChunk &keys, DataChunk &left, DataChunk &result)
 Get the next batch of data from the scan structure.
bool PointersExhausted () const
 Are pointer chains all pointing to NULL?
void AdvancePointers ()
void AdvancePointers (const SelectionVector &sel, idx_t sel_count)
void GatherResult (Vector &result, const SelectionVector &result_vector, const SelectionVector &sel_vector, const idx_t count, const idx_t col_idx)
void GatherResult (Vector &result, const SelectionVector &sel_vector, const idx_t count, const idx_t col_idx)
void GatherResult (Vector &result, const idx_t count, const idx_t col_idx)
idx_t ResolvePredicates (DataChunk &keys, SelectionVector &match_sel, SelectionVector *no_match_sel)

Public Attributes

TupleDataChunkState & key_state
Vector pointers
 Directly point to the entry in the hash table.
idx_t count
SelectionVector sel_vector
SelectionVector chain_match_sel_vector
SelectionVector chain_no_match_sel_vector
unsafe_unique_array< bool > found_match
JoinHashTable & ht
bool finished
bool is_null
bool has_null_value_filter = false
Vector rhs_pointers
SelectionVector lhs_sel_vector
idx_t last_match_count
SelectionVector last_sel_vector

Private Member Functions

void NextInnerJoin (DataChunk &keys, DataChunk &left, DataChunk &result)
 Next operator for the inner join.
void NextSemiJoin (DataChunk &keys, DataChunk &left, DataChunk &result)
 Next operator for the semi join.
void NextAntiJoin (DataChunk &keys, DataChunk &left, DataChunk &result)
 Next operator for the anti join.
void NextRightSemiOrAntiJoin (DataChunk &keys)
 Next operator for the RIGHT semi and anti join.
void NextLeftJoin (DataChunk &keys, DataChunk &left, DataChunk &result)
 Next operator for the left outer join.
void NextMarkJoin (DataChunk &keys, DataChunk &left, DataChunk &result)
 Next operator for the mark join.
void NextSingleJoin (DataChunk &keys, DataChunk &left, DataChunk &result)
 Next operator for the single join.
void ScanKeyMatches (DataChunk &keys)
template<bool MATCH>
void NextSemiOrAntiJoin (DataChunk &keys, DataChunk &left, DataChunk &result)
void ConstructMarkJoinResult (DataChunk &join_keys, DataChunk &child, DataChunk &result)
idx_t ScanInnerJoin (DataChunk &keys, SelectionVector &result_vector)
void UpdateCompactionBuffer (idx_t base_count, SelectionVector &result_vector, idx_t result_count)
 Update the data chunk compaction buffer.

Detailed Description

Scan structure that can be used to resume scans, as a single probe can return 1024*N values (where N is the size of the HT). This is returned by the JoinHashTable::Scan function and can be used to resume a probe.

Constructor & Destructor Documentation

◆ ScanStructure()

duckdb::ScanStructure::ScanStructure ( JoinHashTable & ht,
TupleDataChunkState & key_state )
explicit
158220 : key_state(key_state_p), pointers(LogicalType::POINTER), count(0), sel_vector(STANDARD_VECTOR_SIZE),
158221 chain_match_sel_vector(STANDARD_VECTOR_SIZE), chain_no_match_sel_vector(STANDARD_VECTOR_SIZE),
158222 found_match(make_unsafe_uniq_array_uninitialized<bool>(STANDARD_VECTOR_SIZE)), ht(ht_p), finished(false),
158223 is_null(true), rhs_pointers(LogicalType::POINTER), lhs_sel_vector(STANDARD_VECTOR_SIZE), last_match_count(0),
158224 last_sel_vector(STANDARD_VECTOR_SIZE) {
158225}
Vector pointers
Directly point to the entry in the hash table.
Definition duckdb.cpp:156984

Member Function Documentation

◆ Next()

void duckdb::ScanStructure::Next ( DataChunk & keys,
DataChunk & left,
DataChunk & result )

Get the next batch of data from the scan structure.

158227 {
158228 D_ASSERT(keys.size() == left.size());
158229 if (finished) {
158230 return;
158231 }
158232 switch (ht.join_type) {
158233 case JoinType::INNER:
158234 case JoinType::RIGHT:
158235 NextInnerJoin(keys, left, result);
158236 break;
158237 case JoinType::SEMI:
158238 NextSemiJoin(keys, left, result);
158239 break;
158240 case JoinType::MARK:
158241 NextMarkJoin(keys, left, result);
158242 break;
158243 case JoinType::ANTI:
158244 NextAntiJoin(keys, left, result);
158245 break;
158246 case JoinType::RIGHT_ANTI:
158247 case JoinType::RIGHT_SEMI:
158249 break;
158250 case JoinType::OUTER:
158251 case JoinType::LEFT:
158252 NextLeftJoin(keys, left, result);
158253 break;
158254 case JoinType::SINGLE:
158255 NextSingleJoin(keys, left, result);
158256 break;
158257 default:
158258 throw InternalException("Unhandled join type in JoinHashTable");
158259 }
158260}
void NextMarkJoin(DataChunk &keys, DataChunk &left, DataChunk &result)
Next operator for the mark join.
Definition duckdb.cpp:158598
void NextInnerJoin(DataChunk &keys, DataChunk &left, DataChunk &result)
Next operator for the inner join.
Definition duckdb.cpp:158370
void NextAntiJoin(DataChunk &keys, DataChunk &left, DataChunk &result)
Next operator for the anti join.
Definition duckdb.cpp:158502
void NextRightSemiOrAntiJoin(DataChunk &keys)
Next operator for the RIGHT semi and anti join.
Definition duckdb.cpp:158511
void NextSingleJoin(DataChunk &keys, DataChunk &left, DataChunk &result)
Next operator for the single join.
Definition duckdb.cpp:158703
void NextLeftJoin(DataChunk &keys, DataChunk &left, DataChunk &result)
Next operator for the left outer join.
Definition duckdb.cpp:158671
void NextSemiJoin(DataChunk &keys, DataChunk &left, DataChunk &result)
Next operator for the semi join.
Definition duckdb.cpp:158493
Here is the call graph for this function:

◆ PointersExhausted()

bool duckdb::ScanStructure::PointersExhausted ( ) const

Are pointer chains all pointing to NULL?

158262 {
158263 // AdvancePointers creates a "new_count" for every pointer advanced during the
158264 // previous advance pointers call. If no pointers are advanced, new_count = 0.
158265 // count is then set ot new_count.
158266 return count == 0;
158267}
Here is the caller graph for this function:

◆ NextInnerJoin()

void duckdb::ScanStructure::NextInnerJoin ( DataChunk & keys,
DataChunk & left,
DataChunk & result )
private

Next operator for the inner join.

158370 {
158371 if (ht.join_type != JoinType::RIGHT_SEMI && ht.join_type != JoinType::RIGHT_ANTI) {
158372 D_ASSERT(result.ColumnCount() == left.ColumnCount() + ht.output_columns.size());
158373 }
158374
158375 idx_t base_count = 0;
158376 idx_t result_count;
158377 while (this->count > 0) {
158378 // if we have saved the match result, we need not call ScanInnerJoin again
158379 if (last_match_count == 0) {
158380 result_count = ScanInnerJoin(keys, chain_match_sel_vector);
158381 } else {
158382 chain_match_sel_vector.Initialize(last_sel_vector);
158383 result_count = last_match_count;
158384 last_match_count = 0;
158385 }
158386
158387 if (result_count > 0) {
158388 // the result chunk cannot contain more data, we record the match result for future use
158389 if (base_count + result_count > STANDARD_VECTOR_SIZE) {
158390 last_sel_vector.Initialize(chain_match_sel_vector);
158391 last_match_count = result_count;
158392 break;
158393 }
158394
158395 if (PropagatesBuildSide(ht.join_type)) {
158396 // full/right outer join: mark join matches as FOUND in the HT
158397 auto ptrs = FlatVector::GetData<data_ptr_t>(pointers);
158398 for (idx_t i = 0; i < result_count; i++) {
158399 auto idx = chain_match_sel_vector.get_index(i);
158400 // NOTE: threadsan reports this as a data race because this can be set concurrently by separate
158401 // threads Technically it is, but it does not matter, since the only value that can be written is
158402 // "true"
158403 Store<bool>(true, ptrs[idx] + ht.tuple_size);
158404 }
158405 }
158406
158407 if (ht.join_type != JoinType::RIGHT_SEMI && ht.join_type != JoinType::RIGHT_ANTI) {
158408 // Fast Path: if there is NO more than one element in the chain, we construct the result chunk directly
158409 if (!ht.chains_longer_than_one) {
158410 // matches were found
158411 // on the LHS, we create a slice using the result vector
158412 result.Slice(left, chain_match_sel_vector, result_count);
158413
158414 // on the RHS, we need to fetch the data from the hash table
158415 for (idx_t i = 0; i < ht.output_columns.size(); i++) {
158416 auto &vector = result.data[left.ColumnCount() + i];
158417 const auto output_col_idx = ht.output_columns[i];
158418 D_ASSERT(vector.GetType() == ht.layout_ptr->GetTypes()[output_col_idx]);
158419 GatherResult(vector, chain_match_sel_vector, result_count, output_col_idx);
158420 }
158421
158422 AdvancePointers();
158423 return;
158424 }
158425
158426 // Common Path: use a buffer to store temporary data
158427 UpdateCompactionBuffer(base_count, chain_match_sel_vector, result_count);
158428 base_count += result_count;
158429 }
158430 }
158431 AdvancePointers();
158432 }
158433
158434 if (base_count > 0) {
158435 // create result chunk, we have two steps:
158436 // 1) slice LHS vectors
158437 result.Slice(left, lhs_sel_vector, base_count);
158438
158439 // 2) gather RHS vectors
158440 for (idx_t i = 0; i < ht.output_columns.size(); i++) {
158441 auto &vector = result.data[left.ColumnCount() + i];
158442 const auto output_col_idx = ht.output_columns[i];
158443 D_ASSERT(vector.GetType() == ht.layout_ptr->GetTypes()[output_col_idx]);
158444 GatherResult(vector, base_count, output_col_idx);
158445 }
158446 }
158447}
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
void UpdateCompactionBuffer(idx_t base_count, SelectionVector &result_vector, idx_t result_count)
Update the data chunk compaction buffer.
Definition duckdb.cpp:158358
Here is the call graph for this function:
Here is the caller graph for this function:

◆ NextSemiJoin()

void duckdb::ScanStructure::NextSemiJoin ( DataChunk & keys,
DataChunk & left,
DataChunk & result )
private

Next operator for the semi join.

158493 {
158494 // first scan for key matches
158495 ScanKeyMatches(keys);
158496 // then construct the result from all tuples with a match
158497 NextSemiOrAntiJoin<true>(keys, left, result);
158498
158499 finished = true;
158500}
void ScanKeyMatches(DataChunk &keys)
Definition duckdb.cpp:158449
Here is the call graph for this function:
Here is the caller graph for this function:

◆ NextAntiJoin()

void duckdb::ScanStructure::NextAntiJoin ( DataChunk & keys,
DataChunk & left,
DataChunk & result )
private

Next operator for the anti join.

158502 {
158503 // first scan for key matches
158504 ScanKeyMatches(keys);
158505 // then construct the result from all tuples that did not find a match
158506 NextSemiOrAntiJoin<false>(keys, left, result);
158507
158508 finished = true;
158509}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ NextRightSemiOrAntiJoin()

void duckdb::ScanStructure::NextRightSemiOrAntiJoin ( DataChunk & keys)
private

Next operator for the RIGHT semi and anti join.

158511 {
158512 const auto ptrs = FlatVector::GetData<data_ptr_t>(pointers);
158513 while (!PointersExhausted()) {
158514 // resolve the equality_predicates for this set of keys
158515 idx_t result_count = ResolvePredicates(keys, chain_match_sel_vector, nullptr);
158516
158517 if (ht.non_equality_predicates.empty()) {
158518 // we only have equality predicates - the match is found for the entire chain
158519 for (idx_t i = 0; i < result_count; i++) {
158520 const auto idx = chain_match_sel_vector.get_index(i);
158521 auto &ptr = ptrs[idx];
158522 if (Load<bool>(ptr + ht.tuple_size)) { // Early out: chain has been fully marked as found before
158523 ptr = ht.dead_end.get();
158524 continue;
158525 }
158526
158527 // Fully mark chain as found
158528 while (true) {
158529 // NOTE: threadsan reports this as a data race because this can be set concurrently by separate
158530 // threads Technically it is, but it does not matter, since the only value that can be written is
158531 // "true"
158532 Store<bool>(true, ptr + ht.tuple_size);
158533 auto next_ptr = LoadPointer(ptr + ht.pointer_offset);
158534 if (!next_ptr) {
158535 break;
158536 }
158537 ptr = next_ptr;
158538 }
158539 }
158540 } else {
158541 // we have non-equality predicates - we need to evaluate the join condition for every row
158542 // for each match found in the current pass - mark the match as found
158543 for (idx_t i = 0; i < result_count; i++) {
158544 auto idx = chain_match_sel_vector.get_index(i);
158545 Store<bool>(true, ptrs[idx] + ht.tuple_size);
158546 }
158547 }
158548
158549 // check the next set of pointers
158550 AdvancePointers();
158551 }
158552
158553 finished = true;
158554}
bool PointersExhausted() const
Are pointer chains all pointing to NULL?
Definition duckdb.cpp:158262
Here is the call graph for this function:
Here is the caller graph for this function:

◆ NextLeftJoin()

void duckdb::ScanStructure::NextLeftJoin ( DataChunk & keys,
DataChunk & left,
DataChunk & result )
private

Next operator for the left outer join.

158671 {
158672 // a LEFT OUTER JOIN is identical to an INNER JOIN except all tuples that do
158673 // not have a match must return at least one tuple (with the right side set
158674 // to NULL in every column)
158675 NextInnerJoin(keys, left, result);
158676 if (result.size() == 0) {
158677 // no entries left from the normal join
158678 // fill in the result of the remaining left tuples
158679 // together with NULL values on the right-hand side
158680 idx_t remaining_count = 0;
158681 SelectionVector sel(STANDARD_VECTOR_SIZE);
158682 for (idx_t i = 0; i < left.size(); i++) {
158683 if (!found_match[i]) {
158684 sel.set_index(remaining_count++, i);
158685 }
158686 }
158687 if (remaining_count > 0) {
158688 // have remaining tuples
158689 // slice the left side with tuples that did not find a match
158690 result.Slice(left, sel, remaining_count);
158691
158692 // now set the right side to NULL
158693 for (idx_t i = left.ColumnCount(); i < result.ColumnCount(); i++) {
158694 Vector &vec = result.data[i];
158695 vec.SetVectorType(VectorType::CONSTANT_VECTOR);
158696 ConstantVector::SetNull(vec, true);
158697 }
158698 }
158699 finished = true;
158700 }
158701}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ NextMarkJoin()

void duckdb::ScanStructure::NextMarkJoin ( DataChunk & keys,
DataChunk & left,
DataChunk & result )
private

Next operator for the mark join.

158598 {
158599 D_ASSERT(result.ColumnCount() == left.ColumnCount() + 1);
158600 D_ASSERT(result.data.back().GetType() == LogicalType::BOOLEAN);
158601 // this method should only be called for a non-empty HT
158602 D_ASSERT(ht.Count() > 0);
158603
158604 ScanKeyMatches(keys);
158605 if (ht.correlated_mark_join_info.correlated_types.empty()) {
158606 ConstructMarkJoinResult(keys, left, result);
158607 } else {
158608 auto &info = ht.correlated_mark_join_info;
158609 lock_guard<mutex> mj_lock(info.mj_lock);
158610
158611 // there are correlated columns
158612 // first we fetch the counts from the aggregate hashtable corresponding to these entries
158613 D_ASSERT(keys.ColumnCount() == info.group_chunk.ColumnCount() + 1);
158614 info.group_chunk.SetCardinality(keys);
158615 for (idx_t i = 0; i < info.group_chunk.ColumnCount(); i++) {
158616 info.group_chunk.data[i].Reference(keys.data[i]);
158617 }
158618 info.correlated_counts->FetchAggregates(info.group_chunk, info.result_chunk);
158619
158620 // for the initial set of columns we just reference the left side
158621 result.SetCardinality(left);
158622 for (idx_t i = 0; i < left.ColumnCount(); i++) {
158623 result.data[i].Reference(left.data[i]);
158624 }
158625 // create the result matching vector
158626 auto &last_key = keys.data.back();
158627 auto &result_vector = result.data.back();
158628 // first set the nullmask based on whether or not there were NULL values in the join key
158629 result_vector.SetVectorType(VectorType::FLAT_VECTOR);
158630 auto bool_result = FlatVector::GetData<bool>(result_vector);
158631 auto &mask = FlatVector::Validity(result_vector);
158632 switch (last_key.GetVectorType()) {
158633 case VectorType::CONSTANT_VECTOR:
158634 if (ConstantVector::IsNull(last_key)) {
158635 mask.SetAllInvalid(left.size());
158636 }
158637 break;
158638 case VectorType::FLAT_VECTOR:
158639 mask.Copy(FlatVector::Validity(last_key), left.size());
158640 break;
158641 default: {
158642 UnifiedVectorFormat kdata;
158643 last_key.ToUnifiedFormat(keys.size(), kdata);
158644 for (idx_t i = 0; i < left.size(); i++) {
158645 auto kidx = kdata.sel->get_index(i);
158646 mask.Set(i, kdata.validity.RowIsValid(kidx));
158647 }
158648 break;
158649 }
158650 }
158651
158652 auto count_star = FlatVector::GetData<int64_t>(info.result_chunk.data[0]);
158653 auto count = FlatVector::GetData<int64_t>(info.result_chunk.data[1]);
158654 // set the entries to either true or false based on whether a match was found
158655 for (idx_t i = 0; i < left.size(); i++) {
158656 D_ASSERT(count_star[i] >= count[i]);
158657 bool_result[i] = found_match ? found_match[i] : false;
158658 if (!bool_result[i] && count_star[i] > count[i]) {
158659 // RHS has NULL value and result is false: set to null
158660 mask.SetInvalid(i);
158661 }
158662 if (count_star[i] == 0) {
158663 // count == 0, set nullmask to false (we know the result is false now)
158664 mask.SetValid(i);
158665 }
158666 }
158667 }
158668 finished = true;
158669}
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445
GMat mask(const GMat &src, const GMat &mask)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ NextSingleJoin()

void duckdb::ScanStructure::NextSingleJoin ( DataChunk & keys,
DataChunk & left,
DataChunk & result )
private

Next operator for the single join.

158703 {
158704 // single join
158705 // this join is similar to the semi join except that
158706 // (1) we actually return data from the RHS and
158707 // (2) we return NULL for that data if there is no match
158708 // (3) if single_join_error_on_multiple_rows is set, we need to keep looking for duplicates after fetching
158709 idx_t result_count = 0;
158710 SelectionVector result_sel(STANDARD_VECTOR_SIZE);
158711
158712 while (this->count > 0) {
158713 // resolve the equality_predicates for the current set of pointers
158714 idx_t match_count = ResolvePredicates(keys, chain_match_sel_vector, &chain_no_match_sel_vector);
158715 idx_t no_match_count = this->count - match_count;
158716
158717 // mark each of the matches as found
158718 for (idx_t i = 0; i < match_count; i++) {
158719 // found a match for this index
158720 auto index = chain_match_sel_vector.get_index(i);
158721 found_match[index] = true;
158722 result_sel.set_index(result_count++, index);
158723 }
158724 // continue searching for the ones where we did not find a match yet
158725 AdvancePointers(chain_no_match_sel_vector, no_match_count);
158726 }
158727 // reference the columns of the left side from the result
158728 D_ASSERT(left.ColumnCount() > 0);
158729 for (idx_t i = 0; i < left.ColumnCount(); i++) {
158730 result.data[i].Reference(left.data[i]);
158731 }
158732 // now fetch the data from the RHS
158733 for (idx_t i = 0; i < ht.output_columns.size(); i++) {
158734 auto &vector = result.data[left.ColumnCount() + i];
158735 // set NULL entries for every entry that was not found
158736 for (idx_t j = 0; j < left.size(); j++) {
158737 if (!found_match[j]) {
158738 FlatVector::SetNull(vector, j, true);
158739 }
158740 }
158741 const auto output_col_idx = ht.output_columns[i];
158742 D_ASSERT(vector.GetType() == ht.layout_ptr->GetTypes()[output_col_idx]);
158743 GatherResult(vector, result_sel, result_sel, result_count, output_col_idx);
158744 }
158745 result.SetCardinality(left.size());
158746
158747 // like the SEMI, ANTI and MARK join types, the SINGLE join only ever does one pass over the HT per input chunk
158748 finished = true;
158749
158750 if (ht.single_join_error_on_multiple_rows && result_count > 0) {
158751 // we need to throw an error if there are multiple rows per key
158752 // advance pointers for those rows
158753 AdvancePointers(result_sel, result_count);
158754
158755 // now resolve the predicates
158756 idx_t match_count = ResolvePredicates(keys, chain_match_sel_vector, nullptr);
158757 if (match_count > 0) {
158758 // we found at least one duplicate row - throw
158759 throw InvalidInputException(
158760 "More than one row returned by a subquery used as an expression - scalar subqueries can only "
158761 "return a single row.\n\nUse \"SET scalar_subquery_error_on_multiple_rows=false\" to revert to "
158762 "previous behavior of returning a random row.");
158763 }
158764
158765 this->count = 0;
158766 }
158767}
index
Here is the caller graph for this function:

◆ ScanKeyMatches()

void duckdb::ScanStructure::ScanKeyMatches ( DataChunk & keys)
private

Scan the hashtable for matches of the specified keys, setting the found_match[] array to true or false for every tuple

158449 {
158450 // the semi-join, anti-join and mark-join we handle a differently from the inner join
158451 // since there can be at most STANDARD_VECTOR_SIZE results
158452 // we handle the entire chunk in one call to Next().
158453 // for every pointer, we keep chasing pointers and doing comparisons.
158454 // this results in a boolean array indicating whether or not the tuple has a match
158455 // Start with the scan selection
158456
158457 while (this->count > 0) {
158458 // resolve the equality_predicates for the current set of pointers
158459 idx_t match_count = ResolvePredicates(keys, chain_match_sel_vector, &chain_no_match_sel_vector);
158460 idx_t no_match_count = this->count - match_count;
158461
158462 // mark each of the matches as found
158463 for (idx_t i = 0; i < match_count; i++) {
158464 found_match[chain_match_sel_vector.get_index(i)] = true;
158465 }
158466 // continue searching for the ones where we did not find a match yet
158467 AdvancePointers(chain_no_match_sel_vector, no_match_count);
158468 }
158469}
Here is the caller graph for this function:

◆ NextSemiOrAntiJoin()

template<bool MATCH>
void duckdb::ScanStructure::NextSemiOrAntiJoin ( DataChunk & keys,
DataChunk & left,
DataChunk & result )
private
158472 {
158473 D_ASSERT(left.ColumnCount() == result.ColumnCount());
158474 // create the selection vector from the matches that were found
158475 SelectionVector sel(STANDARD_VECTOR_SIZE);
158476 idx_t result_count = 0;
158477 for (idx_t i = 0; i < keys.size(); i++) {
158478 if (found_match[i] == MATCH) {
158479 // part of the result
158480 sel.set_index(result_count++, i);
158481 }
158482 }
158483 // construct the final result
158484 if (result_count > 0) {
158485 // we only return the columns on the left side
158486 // reference the columns of the left side from the result
158487 result.Slice(left, sel, result_count);
158488 } else {
158489 D_ASSERT(result.size() == 0);
158490 }
158491}

◆ ConstructMarkJoinResult()

void duckdb::ScanStructure::ConstructMarkJoinResult ( DataChunk & join_keys,
DataChunk & child,
DataChunk & result )
private
158556 {
158557 // for the initial set of columns we just reference the left side
158558 result.SetCardinality(child);
158559 for (idx_t i = 0; i < child.ColumnCount(); i++) {
158560 result.data[i].Reference(child.data[i]);
158561 }
158562 auto &mark_vector = result.data.back();
158563 mark_vector.SetVectorType(VectorType::FLAT_VECTOR);
158564 // first we set the NULL values from the join keys
158565 // if there is any NULL in the keys, the result is NULL
158566 auto bool_result = FlatVector::GetData<bool>(mark_vector);
158567 auto &mask = FlatVector::Validity(mark_vector);
158568 for (idx_t col_idx = 0; col_idx < join_keys.ColumnCount(); col_idx++) {
158569 if (ht.null_values_are_equal[col_idx]) {
158570 continue;
158571 }
158572 UnifiedVectorFormat jdata;
158573 join_keys.data[col_idx].ToUnifiedFormat(join_keys.size(), jdata);
158574 if (!jdata.validity.AllValid()) {
158575 for (idx_t i = 0; i < join_keys.size(); i++) {
158576 auto jidx = jdata.sel->get_index(i);
158577 if (!jdata.validity.RowIsValidUnsafe(jidx)) {
158578 mask.SetInvalid(i);
158579 }
158580 }
158581 }
158582 }
158583 // now set the remaining entries to either true or false based on whether a match was found
158584 D_ASSERT(found_match);
158585 for (idx_t i = 0; i < child.size(); i++) {
158586 bool_result[i] = found_match[i];
158587 }
158588 // if the right side contains NULL values, the result of any FALSE becomes NULL
158589 if (ht.has_null) {
158590 for (idx_t i = 0; i < child.size(); i++) {
158591 if (!bool_result[i]) {
158592 mask.SetInvalid(i);
158593 }
158594 }
158595 }
158596}

◆ ScanInnerJoin()

idx_t duckdb::ScanStructure::ScanInnerJoin ( DataChunk & keys,
SelectionVector & result_vector )
private
158297 {
158298 while (true) {
158299 // resolve the equality_predicates for this set of keys
158300 idx_t result_count = ResolvePredicates(keys, result_vector, nullptr);
158301
158302 // after doing all the comparisons set the found_match vector
158303 if (found_match) {
158304 for (idx_t i = 0; i < result_count; i++) {
158305 auto idx = result_vector.get_index(i);
158306 found_match[idx] = true;
158307 }
158308 }
158309 if (result_count > 0) {
158310 return result_count;
158311 }
158312 // no matches found: check the next set of pointers
158313 AdvancePointers();
158314 if (this->count == 0) {
158315 return 0;
158316 }
158317 }
158318}

◆ UpdateCompactionBuffer()

void duckdb::ScanStructure::UpdateCompactionBuffer ( idx_t base_count,
SelectionVector & result_vector,
idx_t result_count )
private

Update the data chunk compaction buffer.

158358 {
158359 // matches were found
158360 // record the result
158361 // on the LHS, we store result vector
158362 for (idx_t i = 0; i < result_count; i++) {
158363 lhs_sel_vector.set_index(base_count + i, result_vector.get_index(i));
158364 }
158365
158366 // on the RHS, we collect their pointers
158367 VectorOperations::Copy(pointers, rhs_pointers, result_vector, result_count, 0, base_count);
158368}
Here is the caller graph for this function:

◆ AdvancePointers() [1/2]

void duckdb::ScanStructure::AdvancePointers ( )
158339 {
158340 AdvancePointers(this->sel_vector, this->count);
158341}

◆ AdvancePointers() [2/2]

void duckdb::ScanStructure::AdvancePointers ( const SelectionVector & sel,
idx_t sel_count )
158320 {
158321 if (!ht.chains_longer_than_one) {
158322 this->count = 0;
158323 return;
158324 }
158325
158326 // now for all the pointers, we move on to the next set of pointers
158327 idx_t new_count = 0;
158328 auto ptrs = FlatVector::GetData<data_ptr_t>(this->pointers);
158329 for (idx_t i = 0; i < sel_count; i++) {
158330 auto idx = sel.get_index(i);
158331 ptrs[idx] = LoadPointer(ptrs[idx] + ht.pointer_offset);
158332 if (ptrs[idx]) {
158333 this->sel_vector.set_index(new_count++, idx);
158334 }
158335 }
158336 this->count = new_count;
158337}

◆ GatherResult() [1/3]

void duckdb::ScanStructure::GatherResult ( Vector & result,
const SelectionVector & result_vector,
const SelectionVector & sel_vector,
const idx_t count,
const idx_t col_idx )
158344 {
158345 ht.data_collection->Gather(pointers, sel_vector, count, col_no, result, result_vector, nullptr);
158346}

◆ GatherResult() [2/3]

void duckdb::ScanStructure::GatherResult ( Vector & result,
const SelectionVector & sel_vector,
const idx_t count,
const idx_t col_idx )
158349 {
158350 GatherResult(result, *FlatVector::IncrementalSelectionVector(), sel_vector, count, col_idx);
158351}

◆ GatherResult() [3/3]

void duckdb::ScanStructure::GatherResult ( Vector & result,
const idx_t count,
const idx_t col_idx )
158353 {
158354 ht.data_collection->Gather(rhs_pointers, *FlatVector::IncrementalSelectionVector(), count, col_idx, result,
158355 *FlatVector::IncrementalSelectionVector(), nullptr);
158356}

◆ ResolvePredicates()

idx_t duckdb::ScanStructure::ResolvePredicates ( DataChunk & keys,
SelectionVector & match_sel,
SelectionVector * no_match_sel )
158269 {
158270 // Initialize the found_match array to the current sel_vector
158271 for (idx_t i = 0; i < this->count; ++i) {
158272 match_sel.set_index(i, this->sel_vector.get_index(i));
158273 }
158274
158275 // If there is a matcher for the probing side because of non-equality predicates, use it
158276 idx_t result_count;
158277 if (ht.needs_chain_matcher) {
158278 idx_t no_match_count = 0;
158279 auto &matcher = no_match_sel ? ht.row_matcher_probe_no_match_sel : ht.row_matcher_probe;
158280 D_ASSERT(matcher);
158281
158282 // we need to only use the vectors with the indices of the columns that are used in the probe phase, namely
158283 // the non-equality columns
158284 result_count =
158285 matcher->Match(keys, key_state.vector_data, match_sel, this->count, pointers, no_match_sel, no_match_count);
158286 } else {
158287 // no match sel is the opposite of match sel
158288 result_count = this->count;
158289 }
158290
158291 // Update total probe match count
158292 ht.total_probe_matches.fetch_add(result_count, std::memory_order_relaxed);
158293
158294 return result_count;
158295}

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