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

Classes

struct  ConflictData
 

Public Member Functions

 ConflictManager (const VerifyExistenceType lookup_type, const idx_t chunk_size, optional_ptr< ConflictInfo > conflict_info=nullptr)
 
bool AddHit (const idx_t index_in_chunk, const row_t row_id)
 Returns true, if we need to throw, otherwise, adds the hit and returns false.
 
bool AddSecondHit (const idx_t index_in_chunk, const row_t row_id)
 Returns true, if we need to throw, otherwise, adds the second hit and returns false.
 
bool AddNull (const idx_t index_in_chunk)
 Returns true, if we need to throw, otherwise, adds the NULL and returns false.
 
optional_idx GetFirstInvalidIndex (const idx_t count, const bool negate=false)
 Returns the index of the first (in)valid row, if any.
 
void FinalizeGlobal (DuckTransaction &transaction, DataTable &table)
 Finalizes a global conflict manager.
 
void FinalizeLocal (DataTable &table, LocalStorage &storage)
 Finalizes a local conflict manager.
 
void FinishLookup ()
 Determines if we are finished registering conflicts.
 
const ConflictInfoGetConflictInfo () const
 Get the conflict information.
 
void SetMode (const ConflictManagerMode mode_p)
 Sets the mode of the conflict manager.
 
void AddIndex (BoundIndex &index, optional_ptr< BoundIndex > delete_index)
 Adds an index and its respective delete_index.
 
bool IndexMatches (BoundIndex &index)
 Returns true, if the index is in this conflict manager.
 
const vector< reference< BoundIndex > > & MatchingIndexes () const
 Returns a reference to the matching indexes.
 
const vector< optional_ptr< BoundIndex > > & MatchingDeleteIndexes () const
 Returns a reference to the matching delete indexes.
 
VerifyExistenceType GetVerifyExistenceType () const
 Returns the existence verification type.
 
bool HasConflicts () const
 Returns true, if there are any conflicts, else false.
 
idx_t ConflictCount () const
 Returns the number of conflicts.
 
VectorGetRowIds ()
 
SelectionVectorGetInvertedSel () const
 
idx_t GetFirstIndex () const
 Returns the first index in a chunk with a conflict.
 
ValidityArrayGetFirstValidity ()
 Returns the validity array of the first conflict data.
 

Static Public Attributes

static constexpr uint8_t FIRST = 0
 
static constexpr uint8_t SECOND = 1
 

Private Member Functions

bool IsConflict (LookupResultType type)
 Returns true, if we register a conflict for the lookup type.
 
bool AddHit (const idx_t index_in_chunk, const std::function< void()> &callback)
 Adds a hit to the conflicts.
 
void Finalize (const std::function< bool(const row_t row_id)> &callback)
 Determine visible row ID for each index with two possible row IDs.
 
bool ShouldThrow (const idx_t index_in_chunk) const
 Returns true, if the conflict manager should throw an exception, else false.
 
bool IgnoreNulls () const
 Returns true, if we ignore NULLs, else false.
 
ConflictDataGetConflictData (const idx_t i)
 
void AddRowId (const idx_t index_in_chunk, const row_t row_id)
 Adds a row ID to the primary conflict data.
 
void AddSecondRowId (const idx_t index_in_chunk, const row_t row_id)
 Adds a row ID to the secondary conflict data.
 

Private Attributes

VerifyExistenceType verify_existence_type
 The type of constraint verification for which we're using the conflict manager.
 
idx_t chunk_size
 The count of the data chunk for which we've created the conflict manager.
 
optional_ptr< ConflictInfoconflict_info
 Optional information to match indexes to the conflict target.
 
ConflictManagerMode mode
 The mode of the conflict manager.
 
vector< reference< BoundIndex > > matching_indexes
 Indexes matching the conflict target.
 
vector< optional_ptr< BoundIndex > > matching_delete_indexes
 Delete indexes matching the conflict target.
 
case_insensitive_set_t index_names
 All matching indexes by their name (unique identifier).
 
unordered_set< idx_tconflict_rows
 Registers all conflicting rows in a data chunk.
 
bool finished = false
 True, if we can skip recording any further conflicts.
 
array< ConflictData, 2 > conflict_data
 

Detailed Description

The conflict manager tracks conflicts during constraint verification. It decides when/if to throw, and records conflicts to be used later in case of ON CONFLICT DO. The conflict manager operates on a per-chunk basis, i.e., we construct a new conflict manager per incoming chunk. On conflict manager can gather conflicts across multiple indexes, if they match the ON CONFLICT DO target.

Member Function Documentation

◆ GetConflictInfo()

const ConflictInfo & duckdb::ConflictManager::GetConflictInfo ( ) const
inline

Get the conflict information.

55822 {
55823 return *conflict_info;
55824 }
optional_ptr< ConflictInfo > conflict_info
Optional information to match indexes to the conflict target.
Definition duckdb.cpp:55893

◆ SetMode()

void duckdb::ConflictManager::SetMode ( const ConflictManagerMode  mode_p)
inline

Sets the mode of the conflict manager.

55826 {
55827 D_ASSERT(mode_p != ConflictManagerMode::SCAN || conflict_info != nullptr);
55828 mode = mode_p;
55829 }
ConflictManagerMode mode
The mode of the conflict manager.
Definition duckdb.cpp:55895

◆ AddIndex()

void duckdb::ConflictManager::AddIndex ( BoundIndex index,
optional_ptr< BoundIndex delete_index 
)
inline

Adds an index and its respective delete_index.

55832 {
55833 matching_indexes.push_back(index);
55834 matching_delete_indexes.push_back(delete_index);
55835 index_names.insert(index.name);
55836 }
vector< reference< BoundIndex > > matching_indexes
Indexes matching the conflict target.
Definition duckdb.cpp:55898
case_insensitive_set_t index_names
All matching indexes by their name (unique identifier).
Definition duckdb.cpp:55902
vector< optional_ptr< BoundIndex > > matching_delete_indexes
Delete indexes matching the conflict target.
Definition duckdb.cpp:55900
index

◆ IndexMatches()

bool duckdb::ConflictManager::IndexMatches ( BoundIndex index)
inline

Returns true, if the index is in this conflict manager.

55838 {
55839 return index_names.find(index.name) != index_names.end();
55840 }

◆ MatchingIndexes()

const vector< reference< BoundIndex > > & duckdb::ConflictManager::MatchingIndexes ( ) const
inline

Returns a reference to the matching indexes.

55842 {
55843 return matching_indexes;
55844 }

◆ MatchingDeleteIndexes()

const vector< optional_ptr< BoundIndex > > & duckdb::ConflictManager::MatchingDeleteIndexes ( ) const
inline

Returns a reference to the matching delete indexes.

55846 {
55848 }

◆ GetVerifyExistenceType()

VerifyExistenceType duckdb::ConflictManager::GetVerifyExistenceType ( ) const
inline

Returns the existence verification type.

55851 {
55852 return verify_existence_type;
55853 }
VerifyExistenceType verify_existence_type
The type of constraint verification for which we're using the conflict manager.
Definition duckdb.cpp:55889

◆ HasConflicts()

bool duckdb::ConflictManager::HasConflicts ( ) const
inline

Returns true, if there are any conflicts, else false.

55855 {
55856 return conflict_data[FIRST].sel != nullptr;
55857 }
array< ConflictData, 2 > conflict_data
Definition duckdb.cpp:55957
Here is the caller graph for this function:

◆ ConflictCount()

idx_t duckdb::ConflictManager::ConflictCount ( ) const
inline

Returns the number of conflicts.

55859 {
55860 if (!HasConflicts()) {
55861 return 0;
55862 }
55863 return conflict_data[FIRST].count;
55864 }
bool HasConflicts() const
Returns true, if there are any conflicts, else false.
Definition duckdb.cpp:55855
Here is the call graph for this function:

◆ GetRowIds()

Vector & duckdb::ConflictManager::GetRowIds ( )
inline

Returns a reference to the row IDs. Must be called after Finalize[Global|Local].

55867 {
55868 D_ASSERT(!conflict_data[SECOND].sel);
55869 return *GetConflictData(FIRST).row_ids;
55870 }
ConflictData & GetConflictData(const idx_t i)
Definition duckdb.cpp:55973
unique_ptr< Vector > row_ids
Row IDs.
Definition duckdb.cpp:55919
Here is the call graph for this function:

◆ GetInvertedSel()

SelectionVector & duckdb::ConflictManager::GetInvertedSel ( ) const
inline

Returns a reference to the inverted selection vector. Must be called after Finalize[Global|Local].

55873 {
55874 D_ASSERT(!conflict_data[SECOND].sel);
55875 return *conflict_data[FIRST].inverted_sel;
55876 }
Here is the caller graph for this function:

◆ GetFirstIndex()

idx_t duckdb::ConflictManager::GetFirstIndex ( ) const
inline

Returns the first index in a chunk with a conflict.

55878 {
55879 return GetInvertedSel().get_index(0);
55880 }
SelectionVector & GetInvertedSel() const
Definition duckdb.cpp:55873
Here is the call graph for this function:

◆ GetFirstValidity()

ValidityArray & duckdb::ConflictManager::GetFirstValidity ( )
inline

Returns the validity array of the first conflict data.

55882 {
55883 D_ASSERT(HasConflicts());
55884 return conflict_data[FIRST].validity;
55885 }
Here is the call graph for this function:

◆ GetConflictData()

ConflictData & duckdb::ConflictManager::GetConflictData ( const idx_t  i)
inlineprivate

Returns a reference to the conflict data (FIRST or SECOND), and initializes it, if uninitialized.

55973 {
55974 if (conflict_data[i].sel) {
55975 return conflict_data[i];
55976 }
55977 conflict_data[i].sel = make_uniq<SelectionVector>(chunk_size);
55978 conflict_data[i].inverted_sel = make_uniq<SelectionVector>(chunk_size);
55979 conflict_data[i].validity.Initialize(chunk_size, false);
55980 conflict_data[i].row_ids = make_uniq<Vector>(LogicalType::ROW_TYPE, chunk_size);
55981 conflict_data[i].row_ids_data = FlatVector::GetData<row_t>(*conflict_data[i].row_ids);
55982 return conflict_data[i];
55983 }
idx_t chunk_size
The count of the data chunk for which we've created the conflict manager.
Definition duckdb.cpp:55891
Here is the caller graph for this function:

◆ AddRowId()

void duckdb::ConflictManager::AddRowId ( const idx_t  index_in_chunk,
const row_t  row_id 
)
inlineprivate

Adds a row ID to the primary conflict data.

55986 {
55987 // Only ON CONFLICT DO NOTHING can have multiple conflict targets,
55988 // which can cause multiple row IDs per index_in_chunk.
55989 // We let them overwrite each other, as we don't need the row IDs later.
55990 auto elem = conflict_rows.find(index_in_chunk);
55991 if (elem == conflict_rows.end()) {
55992 // We have not yet seen this conflict: insert.
55993 conflict_rows.insert(index_in_chunk);
55994 GetConflictData(FIRST).Insert(index_in_chunk, row_id);
55995 }
55996 }
unordered_set< idx_t > conflict_rows
Registers all conflicting rows in a data chunk.
Definition duckdb.cpp:55905
void Insert(const idx_t index_in_chunk, const row_t row_id)
Inserts a conflict into the two selection vectors, the row IDs, and the validity.
Definition duckdb.cpp:55927
Here is the call graph for this function:

◆ AddSecondRowId()

void duckdb::ConflictManager::AddSecondRowId ( const idx_t  index_in_chunk,
const row_t  row_id 
)
inlineprivate

Adds a row ID to the secondary conflict data.

55999 {
56000 D_ASSERT(conflict_rows.find(index_in_chunk) != conflict_rows.end());
56001 GetConflictData(SECOND).Insert(index_in_chunk, row_id);
56002 }
Here is the call graph for this function:

Member Data Documentation

◆ conflict_data

array<ConflictData, 2> duckdb::ConflictManager::conflict_data
private

With the introduction of delete indexes, it is now possible to have up to two row IDs in a UNIQUE/PRIMARY KEY leaf. Only one of the row IDs is visible to the transaction in which we're using the conflict manager. Thus, we need to register both row IDs when scanning, and later Finalize the conflict data to only contain the visible row ID.


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