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

Physically update data in a table. More...

Inheritance diagram for duckdb::PhysicalUpdate:
Collaboration diagram for duckdb::PhysicalUpdate:

Public Member Functions

 PhysicalUpdate (PhysicalPlan &physical_plan, vector< LogicalType > types, TableCatalogEntry &tableref, DataTable &table, vector< PhysicalIndex > columns, vector< unique_ptr< Expression > > expressions, vector< unique_ptr< Expression > > bound_defaults, vector< unique_ptr< BoundConstraint > > bound_constraints, idx_t estimated_cardinality, bool return_chunk)
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
bool IsSink () const override
bool ParallelSink () 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 SinkFinalizeType Finalize (Pipeline &pipeline, Event &event, ClientContext &context, OperatorSinkFinalizeInput &input) const
virtual SinkNextBatchType NextBatch (ExecutionContext &context, OperatorSinkNextBatchInput &input) const
virtual OperatorPartitionInfo RequiredPartitionInfo () const
virtual bool SinkOrderDependent () 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

Public Attributes

TableCatalogEntry & tableref
DataTable & table
vector< PhysicalIndex > columns
vector< unique_ptr< Expression > > expressions
vector< unique_ptr< Expression > > bound_defaults
vector< unique_ptr< BoundConstraint > > bound_constraints
bool update_is_del_and_insert
bool return_chunk
 If the returning statement is present, return the whole chunk.
bool index_update
 Set to true, if we are updating an index column.
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::UPDATE
Static Public Attributes inherited from duckdb::PhysicalOperator
static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::INVALID

Additional Inherited Members

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

Physically update data in a table.

Constructor & Destructor Documentation

◆ PhysicalUpdate()

duckdb::PhysicalUpdate::PhysicalUpdate ( PhysicalPlan & physical_plan,
vector< LogicalType > types,
TableCatalogEntry & tableref,
DataTable & table,
vector< PhysicalIndex > columns,
vector< unique_ptr< Expression > > expressions,
vector< unique_ptr< Expression > > bound_defaults,
vector< unique_ptr< BoundConstraint > > bound_constraints,
idx_t estimated_cardinality,
bool return_chunk )
196953 : PhysicalOperator(physical_plan, PhysicalOperatorType::UPDATE, std::move(types), estimated_cardinality),
196954 tableref(tableref), table(table), columns(std::move(columns)), expressions(std::move(expressions)),
196955 bound_defaults(std::move(bound_defaults)), bound_constraints(std::move(bound_constraints)),
196957 auto &indexes = table.GetDataTableInfo().get()->GetIndexes();
196958 auto index_columns = indexes.GetRequiredColumns();
196959
196960 unordered_set<column_t> update_columns;
196961 for (const auto col : this->columns) {
196962 update_columns.insert(col.index);
196963 }
196964
196965 for (const auto &col : table.Columns()) {
196966 if (index_columns.find(col.Logical().index) == index_columns.end()) {
196967 continue;
196968 }
196969 if (update_columns.find(col.Physical().index) == update_columns.end()) {
196970 continue;
196971 }
196972 index_update = true;
196973 break;
196974 }
196975}
vector< LogicalType > types
The return types.
Definition duckdb.hpp:22152
idx_t estimated_cardinality
The estimated cardinality.
Definition duckdb.hpp:22154
bool index_update
Set to true, if we are updating an index column.
Definition duckdb.cpp:196902
bool return_chunk
If the returning statement is present, return the whole chunk.
Definition duckdb.cpp:196900

Member Function Documentation

◆ GetGlobalSourceState()

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

Reimplemented from duckdb::PhysicalOperator.

197170 {
197171 return make_uniq<UpdateSourceState>(*this);
197172}

◆ GetDataInternal()

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

Reimplemented from duckdb::PhysicalOperator.

197175 {
197176 auto &state = input.global_state.Cast<UpdateSourceState>();
197177 auto &g = sink_state->Cast<UpdateGlobalState>();
197178 if (!return_chunk) {
197179 chunk.SetCardinality(1);
197180 chunk.SetValue(0, 0, Value::BIGINT(NumericCast<int64_t>(g.updated_count.load())));
197181 return SourceResultType::FINISHED;
197182 }
197183
197184 g.return_collection.Scan(state.scan_state, chunk);
197185
197186 return chunk.size() == 0 ? SourceResultType::FINISHED : SourceResultType::HAVE_MORE_OUTPUT;
197187}
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::PhysicalUpdate::IsSource ( ) const
inlineoverridevirtual

Reimplemented from duckdb::PhysicalOperator.

196910 {
196911 return true;
196912 }

◆ GetGlobalSinkState()

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

Reimplemented from duckdb::PhysicalOperator.

197138 {
197139 return make_uniq<UpdateGlobalState>(context, GetTypes());
197140}
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::PhysicalUpdate::GetLocalSinkState ( ExecutionContext & context) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

197142 {
197143 return make_uniq<UpdateLocalState>(context.client, expressions, table.GetTypes(), bound_defaults,
197144 bound_constraints);
197145}

◆ Sink()

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

197035 {
197036 auto &g_state = input.global_state.Cast<UpdateGlobalState>();
197037 auto &l_state = input.local_state.Cast<UpdateLocalState>();
197038
197039 chunk.Flatten();
197040 l_state.default_executor.SetChunk(chunk);
197041
197042 DataChunk &update_chunk = l_state.update_chunk;
197043 update_chunk.Reset();
197044 update_chunk.SetCardinality(chunk);
197045
197046 for (idx_t i = 0; i < expressions.size(); i++) {
197047 // Default expression, set to the default value of the column.
197048 if (expressions[i]->GetExpressionType() == ExpressionType::VALUE_DEFAULT) {
197049 l_state.default_executor.ExecuteExpression(columns[i].index, update_chunk.data[i]);
197050 continue;
197051 }
197052
197053 D_ASSERT(expressions[i]->GetExpressionType() == ExpressionType::BOUND_REF);
197054 auto &binding = expressions[i]->Cast<BoundReferenceExpression>();
197055 update_chunk.data[i].Reference(chunk.data[binding.index]);
197056 }
197057
197058 auto &row_ids = chunk.data[chunk.ColumnCount() - 1];
197059 DataChunk &mock_chunk = l_state.mock_chunk;
197060
197061 // Regular in-place update.
197062 if (!update_is_del_and_insert) {
197063 if (return_chunk) {
197064 mock_chunk.SetCardinality(update_chunk);
197065 for (idx_t i = 0; i < columns.size(); i++) {
197066 mock_chunk.data[columns[i].index].Reference(update_chunk.data[i]);
197067 }
197068 }
197069 auto &update_state = l_state.GetUpdateState(table, tableref, context.client);
197070 table.Update(update_state, context.client, row_ids, columns, update_chunk);
197071
197072 if (return_chunk) {
197073 lock_guard<mutex> glock(g_state.lock);
197074 g_state.return_collection.Append(mock_chunk);
197075 }
197076 g_state.updated_count += chunk.size();
197077 return SinkResultType::NEED_MORE_INPUT;
197078 }
197079
197080 // We update an index or a complex type, so we need to split the UPDATE into DELETE + INSERT.
197081
197082 // Keep track of the rows that have not yet been deleted in this UPDATE.
197083 // This is required since we might see the same row_id multiple times, e.g.,
197084 // during an UPDATE containing joins.
197085 SelectionVector sel(update_chunk.size());
197086 idx_t update_count = 0;
197087 auto row_id_data = FlatVector::GetData<row_t>(row_ids);
197088
197089 lock_guard<mutex> glock(g_state.lock);
197090 for (idx_t i = 0; i < update_chunk.size(); i++) {
197091 auto row_id = row_id_data[i];
197092 const auto is_new = g_state.updated_rows.insert(row_id).second;
197093 if (is_new) {
197094 sel.set_index(update_count++, i);
197095 }
197096 }
197097
197098 // The update chunk now contains exactly those rows that we are deleting.
197099 Vector del_row_ids(row_ids);
197100 if (update_count != update_chunk.size()) {
197101 update_chunk.Slice(sel, update_count);
197102 del_row_ids.Slice(row_ids, sel, update_count);
197103 }
197104
197105 auto &delete_chunk = index_update ? l_state.delete_chunk : l_state.mock_chunk;
197106 delete_chunk.Reset();
197107 delete_chunk.SetCardinality(update_count);
197108
197109 if (index_update) {
197110 auto &transaction = DuckTransaction::Get(context.client, table.db);
197111 vector<StorageIndex> column_ids;
197112 for (idx_t i = 0; i < table.ColumnCount(); i++) {
197113 column_ids.emplace_back(i);
197114 };
197115 // We need to fetch the previous index keys to add them to the delete index.
197116 auto fetch_state = ColumnFetchState();
197117 table.Fetch(transaction, delete_chunk, column_ids, row_ids, update_count, fetch_state);
197118 }
197119
197120 auto &delete_state = l_state.GetDeleteState(table, tableref, context.client);
197121 table.Delete(delete_state, context.client, del_row_ids, update_count);
197122
197123 // Arrange the columns in the standard table order.
197124 mock_chunk.SetCardinality(update_count);
197125 for (idx_t i = 0; i < columns.size(); i++) {
197126 mock_chunk.data[columns[i].index].Reference(update_chunk.data[i]);
197127 }
197128
197129 table.LocalAppend(tableref, context.client, mock_chunk, bound_constraints, del_row_ids, delete_chunk);
197130 if (return_chunk) {
197131 g_state.return_collection.Append(mock_chunk);
197132 }
197133
197134 g_state.updated_count += chunk.size();
197135 return SinkResultType::NEED_MORE_INPUT;
197136}
DUCKDB_API void Reset()
Definition duckdb.cpp:116840
DUCKDB_API void Flatten()
Turn all the vectors from the chunk into flat vectors.
Definition duckdb.cpp:116989
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Combine()

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

197147 {
197148 auto &client_profiler = QueryProfiler::Get(context.client);
197149 context.thread.profiler.Flush(*this);
197150 client_profiler.Flush(context.thread.profiler);
197151 return SinkCombineResultType::FINISHED;
197152}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsSink()

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

Reimplemented from duckdb::PhysicalOperator.

196921 {
196922 return true;
196923 }

◆ ParallelSink()

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

Reimplemented from duckdb::PhysicalOperator.

196924 {
196925 return true;
196926 }

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