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

Physically insert a set of data into a table. More...

Inheritance diagram for duckdb::PhysicalInsert:
Collaboration diagram for duckdb::PhysicalInsert:

Public Member Functions

 PhysicalInsert (PhysicalPlan &physical_plan, vector< LogicalType > types, TableCatalogEntry &table, vector< unique_ptr< BoundConstraint > > bound_constraints, vector< unique_ptr< Expression > > set_expressions, vector< PhysicalIndex > set_columns, vector< LogicalType > set_types, idx_t estimated_cardinality, bool return_chunk, bool parallel, OnConflictAction action_type, unique_ptr< Expression > on_conflict_condition, unique_ptr< Expression > do_update_condition, unordered_set< column_t > on_conflict_filter, vector< column_t > columns_to_fetch, bool update_is_del_and_insert)
 INSERT INTO.
 PhysicalInsert (PhysicalPlan &physical_plan, LogicalOperator &op, SchemaCatalogEntry &schema, unique_ptr< BoundCreateTableInfo > info, idx_t estimated_cardinality, bool parallel)
 CREATE TABLE AS.
unique_ptr< GlobalSourceState > GetGlobalSourceState (ClientContext &context) const override
SourceResultType GetDataInternal (ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const override
bool IsSource () 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
bool SinkOrderDependent () const override
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 InsertionOrderPreservingMap< string > ParamsToString () 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< OperatorState > GetOperatorState (ExecutionContext &context) const
virtual unique_ptr< GlobalOperatorState > GetGlobalOperatorState (ClientContext &context) const
virtual OperatorResultType Execute (ExecutionContext &context, DataChunk &input, DataChunk &chunk, GlobalOperatorState &gstate, OperatorState &state) const
virtual OperatorFinalizeResultType FinalExecute (ExecutionContext &context, DataChunk &chunk, GlobalOperatorState &gstate, OperatorState &state) const
virtual OperatorFinalResultType OperatorFinalize (Pipeline &pipeline, Event &event, ClientContext &context, OperatorFinalizeInput &input) const
virtual bool ParallelOperator () const
virtual bool RequiresFinalExecute () const
virtual bool RequiresOperatorFinalize () const
virtual OrderPreservationType OperatorOrder () const
 The influence the operator has on order (insertion order means no influence).
virtual unique_ptr< LocalSourceState > GetLocalSourceState (ExecutionContext &context, GlobalSourceState &gstate) 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 ParallelSource () const
virtual bool SupportsPartitioning (const OperatorPartitionInfo &partition_info) const
virtual OrderPreservationType SourceOrder () const
 The type of order emitted by the operator (as a source).
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
virtual vector< const_reference< PhysicalOperator > > GetSources () const
bool AllSourcesSupportBatchIndex () const
virtual void BuildPipelines (Pipeline &current, MetaPipeline &meta_pipeline)
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const

Static Public Member Functions

static void GetInsertInfo (const BoundCreateTableInfo &info, vector< LogicalType > &insert_types)
Static Public Member Functions inherited from duckdb::PhysicalOperator
static void SetEstimatedCardinality (InsertionOrderPreservingMap< string > &result, idx_t estimated_cardinality)
static idx_t GetMaxThreadMemory (ClientContext &context)
 The maximum amount of memory the operator should use per thread.
static OperatorCachingMode SelectOperatorCachingMode (ExecutionContext &context)
 Whether operator caching is allowed in the current execution context.

Public Attributes

optional_ptr< TableCatalogEntry > insert_table
 The table to insert into.
vector< LogicalType > insert_types
 The insert types.
vector< unique_ptr< BoundConstraint > > bound_constraints
 The bound constraints for the table.
bool return_chunk
 If the returning statement is present, return the whole chunk.
optional_ptr< SchemaCatalogEntry > schema
 Table schema, in case of CREATE TABLE AS.
unique_ptr< BoundCreateTableInfo > info
 Create table info, in case of CREATE TABLE AS.
bool parallel
OnConflictAction action_type
vector< unique_ptr< Expression > > set_expressions
vector< PhysicalIndex > set_columns
vector< LogicalType > set_types
unique_ptr< Expression > on_conflict_condition
unique_ptr< Expression > do_update_condition
unordered_set< column_t > conflict_target
bool update_is_del_and_insert
 True, if the INSERT OR REPLACE requires delete + insert.
vector< StorageIndex > columns_to_fetch
vector< LogicalType > types_to_fetch
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::INSERT
Static Public Attributes inherited from duckdb::PhysicalOperator
static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::INVALID

Protected Member Functions

void CombineExistingAndInsertTuples (DataChunk &result, DataChunk &scan_chunk, DataChunk &input_chunk, ClientContext &client) const
void CreateUpdateChunk (ExecutionContext &context, DataChunk &chunk, TableCatalogEntry &table, Vector &row_ids, DataChunk &result) const
 Returns the amount of updated tuples.
idx_t OnConflictHandling (TableCatalogEntry &table, ExecutionContext &context, InsertGlobalState &gstate, InsertLocalState &lstate, DataChunk &insert_chunk) const

Detailed Description

Physically insert a set of data into a table.

Constructor & Destructor Documentation

◆ PhysicalInsert() [1/2]

duckdb::PhysicalInsert::PhysicalInsert ( PhysicalPlan & physical_plan,
vector< LogicalType > types,
TableCatalogEntry & table,
vector< unique_ptr< BoundConstraint > > bound_constraints,
vector< unique_ptr< Expression > > set_expressions,
vector< PhysicalIndex > set_columns,
vector< LogicalType > set_types,
idx_t estimated_cardinality,
bool return_chunk,
bool parallel,
OnConflictAction action_type,
unique_ptr< Expression > on_conflict_condition,
unique_ptr< Expression > do_update_condition,
unordered_set< column_t > on_conflict_filter,
vector< column_t > columns_to_fetch,
bool update_is_del_and_insert )

INSERT INTO.

195451 : PhysicalOperator(physical_plan, PhysicalOperatorType::INSERT, std::move(types_p), estimated_cardinality),
195452 insert_table(&table), insert_types(table.GetTypes()), bound_constraints(std::move(bound_constraints_p)),
195453 return_chunk(return_chunk), parallel(parallel), action_type(action_type),
195454 set_expressions(std::move(set_expressions)), set_columns(std::move(set_columns)), set_types(std::move(set_types)),
195455 on_conflict_condition(std::move(on_conflict_condition_p)), do_update_condition(std::move(do_update_condition_p)),
195456 conflict_target(std::move(conflict_target_p)), update_is_del_and_insert(update_is_del_and_insert) {
195457 if (action_type == OnConflictAction::THROW) {
195458 return;
195459 }
195460
195461 D_ASSERT(this->set_expressions.size() == this->set_columns.size());
195462
195463 // One or more columns are referenced from the existing table,
195464 // we use the 'insert_types' to figure out which types these columns have
195465 types_to_fetch = vector<LogicalType>(columns_to_fetch_p.size(), LogicalType::SQLNULL);
195466 for (idx_t i = 0; i < columns_to_fetch_p.size(); i++) {
195467 auto &id = columns_to_fetch_p[i];
195468 D_ASSERT(id < insert_types.size());
195469 types_to_fetch[i] = insert_types[id];
195470 columns_to_fetch.emplace_back(id);
195471 }
195472}
vector< LogicalType > insert_types
The insert types.
Definition duckdb.cpp:192795
bool update_is_del_and_insert
True, if the INSERT OR REPLACE requires delete + insert.
Definition duckdb.cpp:192824
vector< unique_ptr< BoundConstraint > > bound_constraints
The bound constraints for the table.
Definition duckdb.cpp:192797
bool return_chunk
If the returning statement is present, return the whole chunk.
Definition duckdb.cpp:192799
bool parallel
Definition duckdb.cpp:192806
optional_ptr< TableCatalogEntry > insert_table
The table to insert into.
Definition duckdb.cpp:192793
idx_t estimated_cardinality
The estimated cardinality.
Definition duckdb.hpp:22154
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the call graph for this function:

◆ PhysicalInsert() [2/2]

duckdb::PhysicalInsert::PhysicalInsert ( PhysicalPlan & physical_plan,
LogicalOperator & op,
SchemaCatalogEntry & schema,
unique_ptr< BoundCreateTableInfo > info,
idx_t estimated_cardinality,
bool parallel )

CREATE TABLE AS.

195476 : PhysicalOperator(physical_plan, PhysicalOperatorType::CREATE_TABLE_AS, op.types, estimated_cardinality),
195477 insert_table(nullptr), return_chunk(false), schema(&schema), info(std::move(info_p)), parallel(parallel),
195478 action_type(OnConflictAction::THROW), update_is_del_and_insert(false) {
195479 GetInsertInfo(*info, insert_types);
195480}
optional_ptr< SchemaCatalogEntry > schema
Table schema, in case of CREATE TABLE AS.
Definition duckdb.cpp:192801
unique_ptr< BoundCreateTableInfo > info
Create table info, in case of CREATE TABLE AS.
Definition duckdb.cpp:192803

Member Function Documentation

◆ GetGlobalSourceState()

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

Reimplemented from duckdb::PhysicalOperator.

196159 {
196160 return make_uniq<InsertSourceState>(*this);
196161}

◆ GetDataInternal()

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

Reimplemented from duckdb::PhysicalOperator.

196164 {
196165 auto &state = input.global_state.Cast<InsertSourceState>();
196166 auto &insert_gstate = sink_state->Cast<InsertGlobalState>();
196167 if (!return_chunk) {
196168 chunk.SetCardinality(1);
196169 chunk.SetValue(0, 0, Value::BIGINT(NumericCast<int64_t>(insert_gstate.insert_count)));
196170 return SourceResultType::FINISHED;
196171 }
196172
196173 insert_gstate.return_collection.Scan(state.scan_state, chunk);
196174 return chunk.size() == 0 ? SourceResultType::FINISHED : SourceResultType::HAVE_MORE_OUTPUT;
196175}
unique_ptr< GlobalSinkState > sink_state
The global sink state.
Definition duckdb.hpp:22157
static DUCKDB_API Value BIGINT(int64_t value)
Create a bigint Value from a specified value.
Definition duckdb.cpp:132146

◆ IsSource()

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

Reimplemented from duckdb::PhysicalOperator.

192837 {
192838 return true;
192839 }

◆ GetGlobalSinkState()

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

Reimplemented from duckdb::PhysicalOperator.

195522 {
195523 optional_ptr<TableCatalogEntry> table;
195524 if (info) {
195525 // CREATE TABLE AS
195526 D_ASSERT(!insert_table);
195527 auto &catalog = schema->catalog;
195528 table = &catalog.CreateTable(catalog.GetCatalogTransaction(context), *schema.get_mutable(), *info)
195529 ->Cast<TableCatalogEntry>();
195530 } else {
195531 D_ASSERT(insert_table);
195532 D_ASSERT(insert_table->IsDuckTable());
195533 table = insert_table.get_mutable();
195534 }
195535 auto result = make_uniq<InsertGlobalState>(context, GetTypes(), table->Cast<DuckTableEntry>());
195536 return std::move(result);
195537}
const vector< LogicalType > & GetTypes() const
Return a vector of the types that will be returned by this operator.
Definition duckdb.hpp:22174

◆ GetLocalSinkState()

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

Reimplemented from duckdb::PhysicalOperator.

195539 {
195540 return make_uniq<InsertLocalState>(context.client, insert_types, bound_constraints);
195541}

◆ Sink()

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

196037 {
196038 auto &gstate = input.global_state.Cast<InsertGlobalState>();
196039 auto &lstate = input.local_state.Cast<InsertLocalState>();
196040
196041 auto &table = gstate.table;
196042 auto &storage = table.GetStorage();
196043 insert_chunk.Flatten();
196044
196045 if (!parallel) {
196046 idx_t updated_tuples = OnConflictHandling(table, context, gstate, lstate, insert_chunk);
196047
196048 gstate.insert_count += insert_chunk.size();
196049 gstate.insert_count += updated_tuples;
196050 if (return_chunk) {
196051 gstate.return_collection.Append(insert_chunk);
196052 }
196053 storage.LocalAppend(table, context.client, insert_chunk, bound_constraints);
196054 if (action_type == OnConflictAction::UPDATE && lstate.update_chunk.size() != 0) {
196055 (void)HandleInsertConflicts<true>(table, context, lstate, gstate, lstate.update_chunk, *this);
196056 (void)HandleInsertConflicts<false>(table, context, lstate, gstate, lstate.update_chunk, *this);
196057 // All of the tuples should have been turned into an update, leaving the chunk empty afterwards
196058 D_ASSERT(lstate.update_chunk.size() == 0);
196059 }
196060 return SinkResultType::NEED_MORE_INPUT;
196061 }
196062
196063 // Parallel append.
196064 D_ASSERT(!return_chunk);
196065 auto &data_table = gstate.table.GetStorage();
196066 if (!lstate.collection_index.IsValid()) {
196067 lock_guard<mutex> l(gstate.lock);
196068 lstate.optimistic_writer = make_uniq<OptimisticDataWriter>(context.client, data_table);
196069 // Create the local row group collection.
196070 auto optimistic_collection = lstate.optimistic_writer->CreateCollection(storage, insert_types);
196071 auto &collection = *optimistic_collection->collection;
196072 collection.InitializeEmpty();
196073 collection.InitializeAppend(lstate.local_append_state);
196074
196075 lstate.collection_index =
196076 data_table.CreateOptimisticCollection(context.client, std::move(optimistic_collection));
196077 }
196078
196079 OnConflictHandling(table, context, gstate, lstate, insert_chunk);
196080 D_ASSERT(action_type != OnConflictAction::UPDATE);
196081
196082 auto &optimistic_collection = data_table.GetOptimisticCollection(context.client, lstate.collection_index);
196083 auto &collection = *optimistic_collection.collection;
196084 auto new_row_group = collection.Append(insert_chunk, lstate.local_append_state);
196085 if (new_row_group) {
196086 lstate.optimistic_writer->WriteNewRowGroup(optimistic_collection);
196087 }
196088 return SinkResultType::NEED_MORE_INPUT;
196089}
idx_t OnConflictHandling(TableCatalogEntry &table, ExecutionContext &context, InsertGlobalState &gstate, InsertLocalState &lstate, DataChunk &insert_chunk) const
Definition duckdb.cpp:195935
Here is the call graph for this function:

◆ Combine()

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

196091 {
196092 auto &gstate = input.global_state.Cast<InsertGlobalState>();
196093 auto &lstate = input.local_state.Cast<InsertLocalState>();
196094 auto &client_profiler = QueryProfiler::Get(context.client);
196095 context.thread.profiler.Flush(*this);
196096 client_profiler.Flush(context.thread.profiler);
196097
196098 if (!parallel || !lstate.collection_index.IsValid()) {
196099 return SinkCombineResultType::FINISHED;
196100 }
196101
196102 auto &table = gstate.table;
196103 auto &storage = table.GetStorage();
196104 const idx_t row_group_size = storage.GetRowGroupSize();
196105
196106 // parallel append: finalize the append
196107 TransactionData tdata(0, 0);
196108 auto &data_table = gstate.table.GetStorage();
196109 auto &optimistic_collection = data_table.GetOptimisticCollection(context.client, lstate.collection_index);
196110 auto &collection = *optimistic_collection.collection;
196111 collection.FinalizeAppend(tdata, lstate.local_append_state);
196112
196113 auto append_count = collection.GetTotalRows();
196114
196115 lock_guard<mutex> lock(gstate.lock);
196116 gstate.insert_count += append_count;
196117 if (append_count < row_group_size) {
196118 // we have few rows - append to the local storage directly
196119 LocalAppendState append_state;
196120 storage.InitializeLocalAppend(append_state, table, context.client, bound_constraints);
196121 auto &transaction = DuckTransaction::Get(context.client, table.catalog);
196122 for (auto &insert_chunk : collection.Chunks(transaction)) {
196123 storage.LocalAppend(append_state, context.client, insert_chunk, false);
196124 }
196125 storage.FinalizeLocalAppend(append_state);
196126 } else {
196127 // we have written rows to disk optimistically - merge directly into the transaction-local storage
196128 lstate.optimistic_writer->WriteUnflushedRowGroups(optimistic_collection);
196129 lstate.optimistic_writer->FinalFlush();
196130 gstate.table.GetStorage().LocalMerge(context.client, optimistic_collection);
196131 auto &optimistic_writer = gstate.table.GetStorage().GetOptimisticWriter(context.client);
196132 optimistic_writer.Merge(*lstate.optimistic_writer);
196133 }
196134
196135 return SinkCombineResultType::FINISHED;
196136}
mutex lock
Lock for (re)setting any of the operator states.
Definition duckdb.hpp:22161
Here is the call graph for this function:

◆ Finalize()

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

196139 {
196140 return SinkFinalizeType::READY;
196141}

◆ IsSink()

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

Reimplemented from duckdb::PhysicalOperator.

192850 {
192851 return true;
192852 }

◆ ParallelSink()

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

Reimplemented from duckdb::PhysicalOperator.

192854 {
192855 return parallel;
192856 }

◆ SinkOrderDependent()

bool duckdb::PhysicalInsert::SinkOrderDependent ( ) const
inlineoverridevirtual

Whether or not the sink operator depends on the order of the input chunks If this is set to true, we cannot do things like caching intermediate vectors

Reimplemented from duckdb::PhysicalOperator.

192858 {
192859 return true;
192860 }

◆ GetInsertInfo()

void duckdb::PhysicalInsert::GetInsertInfo ( const BoundCreateTableInfo & info,
vector< LogicalType > & insert_types )
static
195482 {
195483 auto &create_info = info.base->Cast<CreateTableInfo>();
195484 for (auto &col : create_info.columns.Physical()) {
195485 insert_types.push_back(col.GetType());
195486 }
195487}

◆ OnConflictHandling()

idx_t duckdb::PhysicalInsert::OnConflictHandling ( TableCatalogEntry & table,
ExecutionContext & context,
InsertGlobalState & gstate,
InsertLocalState & lstate,
DataChunk & insert_chunk ) const
protected

See https://github.com/duckdblabs/duckdb-internal/issues/4090 for context

195936 {
195937 auto &data_table = table.GetStorage();
195938 auto &local_storage = LocalStorage::Get(context.client, data_table.db);
195939
195940 if (action_type == OnConflictAction::THROW) {
195941 auto &constraint_state = lstate.GetConstraintState(data_table, table);
195942 auto storage = local_storage.GetStorage(data_table);
195943 data_table.VerifyAppendConstraints(constraint_state, context.client, insert_chunk, storage, nullptr);
195944 return 0;
195945 }
195946
195947 ConflictInfo conflict_info(conflict_target);
195948 reference_set_t<Index> matching_indexes;
195949
195950 if (conflict_info.column_ids.empty()) {
195951 auto &global_indexes = data_table.GetDataTableInfo()->GetIndexes();
195952 // We care about every index that applies to the table if no ON CONFLICT (...) target is given
195953 for (auto &index : global_indexes.Indexes()) {
195954 if (!index.IsUnique()) {
195955 continue;
195956 }
195957 D_ASSERT(index.IsBound());
195958 if (conflict_info.ConflictTargetMatches(index)) {
195959 matching_indexes.insert(index);
195960 }
195961 }
195962 auto &local_indexes = local_storage.GetIndexes(context.client, data_table);
195963 for (auto &index : local_indexes.Indexes()) {
195964 if (!index.IsUnique()) {
195965 continue;
195966 }
195967 D_ASSERT(index.IsBound());
195968 if (conflict_info.ConflictTargetMatches(index)) {
195969 auto &bound_index = index.Cast<BoundIndex>();
195970 matching_indexes.insert(bound_index);
195971 }
195972 }
195973 }
195974
195975 auto inner_conflicts = CheckDistinctness(insert_chunk, conflict_info, matching_indexes);
195976 idx_t count = insert_chunk.size();
195977 if (!inner_conflicts.empty()) {
195978 // We have at least one inner conflict to filter out.
195979 SelectionVector sel(count);
195980 idx_t sel_count = 0;
195981
195982 ValidityMask not_a_conflict(count);
195983 set<idx_t> last_occurrences_of_conflict;
195984 for (idx_t i = 0; i < count; i++) {
195985 auto it = inner_conflicts.find(i);
195986 if (it != inner_conflicts.end()) {
195987 auto &conflicts = it->second;
195988 auto conflict_it = conflicts.begin();
195989 for (; conflict_it != conflicts.end();) {
195990 auto &idx = *conflict_it;
195991 not_a_conflict.SetInvalid(idx);
195992 conflict_it++;
195993 if (conflict_it == conflicts.end()) {
195994 last_occurrences_of_conflict.insert(idx);
195995 }
195996 }
195997 }
195998 if (not_a_conflict.RowIsValid(i)) {
195999 sel.set_index(sel_count, i);
196000 sel_count++;
196001 }
196002 }
196003 if (action_type == OnConflictAction::UPDATE) {
196004 if (do_update_condition) {
196006 throw NotImplementedException("Inner conflicts detected with a conditional DO UPDATE on-conflict "
196007 "action, not fully implemented yet");
196008 }
196009
196010 SelectionVector last_occurrences(last_occurrences_of_conflict.size());
196011 idx_t last_occurrences_count = 0;
196012 for (auto &idx : last_occurrences_of_conflict) {
196013 last_occurrences.set_index(last_occurrences_count, idx);
196014 last_occurrences_count++;
196015 }
196016
196017 lstate.update_chunk.Reference(insert_chunk);
196018 lstate.update_chunk.Slice(last_occurrences, last_occurrences_count);
196019 lstate.update_chunk.SetCardinality(last_occurrences_count);
196020 }
196021
196022 insert_chunk.Slice(sel, sel_count);
196023 insert_chunk.SetCardinality(sel_count);
196024 }
196025
196026 // Check whether any conflicts arise, and if they all meet the conflict_target + condition
196027 // If that's not the case - We throw the first error
196028 idx_t updated_tuples = 0;
196029 updated_tuples += HandleInsertConflicts<true>(table, context, lstate, gstate, insert_chunk, *this);
196030 // Also check the transaction-local storage+ART so we can detect conflicts within this transaction
196031 updated_tuples += HandleInsertConflicts<false>(table, context, lstate, gstate, insert_chunk, *this);
196032
196033 return updated_tuples;
196034}
index
static map< idx_t, vector< idx_t > > CheckDistinctness(DataChunk &input, ConflictInfo &info, reference_set_t< Index > &matched_indexes)
Definition duckdb.cpp:195776
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ parallel

bool duckdb::PhysicalInsert::parallel

Whether or not the INSERT can be executed in parallel This insert is not order preserving if executed in parallel


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