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

Physically delete data from a table. More...

Inheritance diagram for duckdb::PhysicalDelete:
Collaboration diagram for duckdb::PhysicalDelete:

Public Member Functions

 PhysicalDelete (PhysicalPlan &physical_plan, vector< LogicalType > types, TableCatalogEntry &tableref, DataTable &table, vector< unique_ptr< BoundConstraint > > bound_constraints, idx_t row_id_index, 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
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 SinkCombineResultType Combine (ExecutionContext &context, OperatorSinkCombineInput &input) 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< unique_ptr< BoundConstraint > > bound_constraints
idx_t row_id_index
bool return_chunk
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::DELETE_OPERATOR
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 delete data from a table.

Constructor & Destructor Documentation

◆ PhysicalDelete()

duckdb::PhysicalDelete::PhysicalDelete ( PhysicalPlan & physical_plan,
vector< LogicalType > types,
TableCatalogEntry & tableref,
DataTable & table,
vector< unique_ptr< BoundConstraint > > bound_constraints,
idx_t row_id_index,
idx_t estimated_cardinality,
bool return_chunk )
194788 : PhysicalOperator(physical_plan, PhysicalOperatorType::DELETE_OPERATOR, std::move(types), estimated_cardinality),
194789 tableref(tableref), table(table), bound_constraints(std::move(bound_constraints)), row_id_index(row_id_index),
194790 return_chunk(return_chunk) {
194791}
vector< LogicalType > types
The return types.
Definition duckdb.hpp:22152
idx_t estimated_cardinality
The estimated cardinality.
Definition duckdb.hpp:22154

Member Function Documentation

◆ GetGlobalSourceState()

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

Reimplemented from duckdb::PhysicalOperator.

194968 {
194969 return make_uniq<DeleteSourceState>(*this);
194970}

◆ GetDataInternal()

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

Reimplemented from duckdb::PhysicalOperator.

194973 {
194974 auto &state = input.global_state.Cast<DeleteSourceState>();
194975 auto &g = sink_state->Cast<DeleteGlobalState>();
194976 if (!return_chunk) {
194977 chunk.SetCardinality(1);
194978 chunk.SetValue(0, 0, Value::BIGINT(NumericCast<int64_t>(g.deleted_count)));
194979 return SourceResultType::FINISHED;
194980 }
194981
194982 g.return_collection.Scan(state.scan_state, chunk);
194983 return chunk.size() == 0 ? SourceResultType::FINISHED : SourceResultType::HAVE_MORE_OUTPUT;
194984}
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::PhysicalDelete::IsSource ( ) const
inlineoverridevirtual

Reimplemented from duckdb::PhysicalOperator.

194751 {
194752 return true;
194753 }

◆ GetGlobalSinkState()

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

Reimplemented from duckdb::PhysicalOperator.

194944 {
194945 return make_uniq<DeleteGlobalState>(context, GetTypes(), tableref, bound_constraints);
194946}
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::PhysicalDelete::GetLocalSinkState ( ExecutionContext & context) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

194948 {
194949 return make_uniq<DeleteLocalState>(context.client, tableref, bound_constraints);
194950}

◆ Sink()

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

194833 {
194834 auto &g_state = input.global_state.Cast<DeleteGlobalState>();
194835 auto &l_state = input.local_state.Cast<DeleteLocalState>();
194836
194837 auto &transaction = DuckTransaction::Get(context.client, table.db);
194838 auto &row_ids = chunk.data[row_id_index];
194839
194840 lock_guard<mutex> delete_guard(g_state.delete_lock);
194841 if (!return_chunk && !g_state.has_unique_indexes) {
194842 g_state.deleted_count += table.Delete(*l_state.delete_state, context.client, row_ids, chunk.size());
194843 return SinkResultType::NEED_MORE_INPUT;
194844 }
194845
194846 auto types = table.GetTypes();
194847 auto to_be_fetched = vector<bool>(types.size(), return_chunk);
194848 vector<StorageIndex> column_ids;
194849 vector<LogicalType> column_types;
194850 if (return_chunk) {
194851 // Fetch all columns.
194852 column_types = types;
194853 for (idx_t i = 0; i < table.ColumnCount(); i++) {
194854 column_ids.emplace_back(i);
194855 }
194856
194857 } else {
194858 // Fetch only the required columns for updating the delete indexes.
194859 auto &local_storage = LocalStorage::Get(context.client, table.db);
194860 auto storage = local_storage.GetStorage(table);
194861 unordered_set<column_t> indexed_column_id_set;
194862 for (auto &index : storage->delete_indexes.Indexes()) {
194863 if (!index.IsBound() || !index.IsUnique()) {
194864 continue;
194865 }
194866 auto &set = index.GetColumnIdSet();
194867 indexed_column_id_set.insert(set.begin(), set.end());
194868 }
194869 for (auto &col : indexed_column_id_set) {
194870 column_ids.emplace_back(col);
194871 }
194872 sort(column_ids.begin(), column_ids.end());
194873 for (auto &col : column_ids) {
194874 auto i = col.GetPrimaryIndex();
194875 to_be_fetched[i] = true;
194876 column_types.push_back(types[i]);
194877 }
194878 }
194879
194880 l_state.delete_chunk.Reset();
194881 row_ids.Flatten(chunk.size());
194882
194883 // Fetch the to-be-deleted chunk.
194884 DataChunk fetch_chunk;
194885 fetch_chunk.Initialize(Allocator::Get(context.client), column_types, chunk.size());
194886 auto fetch_state = ColumnFetchState();
194887 table.Fetch(transaction, fetch_chunk, column_ids, row_ids, chunk.size(), fetch_state);
194888
194889 // Reference the necessary columns of the fetch_chunk.
194890 idx_t fetch_idx = 0;
194891 for (idx_t i = 0; i < table.ColumnCount(); i++) {
194892 if (to_be_fetched[i]) {
194893 l_state.delete_chunk.data[i].Reference(fetch_chunk.data[fetch_idx++]);
194894 continue;
194895 }
194896 l_state.delete_chunk.data[i].Reference(Value(types[i]));
194897 }
194898 l_state.delete_chunk.SetCardinality(fetch_chunk);
194899
194900 // Append the deleted row IDs to the delete indexes.
194901 if (g_state.has_unique_indexes && l_state.delete_chunk.size() != 0) {
194902 auto &local_storage = LocalStorage::Get(context.client, table.db);
194903 auto storage = local_storage.GetStorage(table);
194904 storage->AppendToDeleteIndexes(row_ids, l_state.delete_chunk);
194905 }
194906
194907 auto deleted_count = table.Delete(*l_state.delete_state, context.client, row_ids, chunk.size());
194908 g_state.deleted_count += deleted_count;
194909
194910 // Append the return_chunk to the return collection.
194911 if (return_chunk) {
194912 // Rows can be duplicated, so we get the chunk indexes for new row id values.
194913 map<row_t, idx_t> new_row_ids_deleted;
194914 auto flat_ids = FlatVector::GetData<row_t>(row_ids);
194915 for (idx_t i = 0; i < chunk.size(); i++) {
194916 // If the row has not been deleted previously
194917 // and is not a duplicate within the current chunk,
194918 // then we add it to new_row_ids_deleted.
194919 auto row_id = flat_ids[i];
194920 auto already_deleted = g_state.deleted_row_ids.find(row_id) != g_state.deleted_row_ids.end();
194921 auto newly_deleted = new_row_ids_deleted.find(row_id) != new_row_ids_deleted.end();
194922 if (!already_deleted && !newly_deleted) {
194923 new_row_ids_deleted[row_id] = i;
194924 g_state.deleted_row_ids.insert(row_id);
194925 }
194926 }
194927
194928 D_ASSERT(new_row_ids_deleted.size() == deleted_count);
194929 if (deleted_count < l_state.delete_chunk.size()) {
194930 SelectionVector delete_sel(0, deleted_count);
194931 idx_t chunk_index = 0;
194932 for (auto &row_id_to_chunk_index : new_row_ids_deleted) {
194933 delete_sel.set_index(chunk_index, row_id_to_chunk_index.second);
194934 chunk_index++;
194935 }
194936 l_state.delete_chunk.Slice(delete_sel, deleted_count);
194937 }
194938 g_state.return_collection.Append(l_state.delete_chunk);
194939 }
194940
194941 return SinkResultType::NEED_MORE_INPUT;
194942}
DUCKDB_API void Initialize(ClientContext &context, const vector< LogicalType > &types, idx_t capacity=STANDARD_VECTOR_SIZE)
Definition duckdb.cpp:116791
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445
void sort(InputArray src, OutputArray dst, int flags)
index
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the call graph for this function:

◆ IsSink()

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

Reimplemented from duckdb::PhysicalOperator.

194761 {
194762 return true;
194763 }

◆ ParallelSink()

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

Reimplemented from duckdb::PhysicalOperator.

194764 {
194765 return true;
194766 }

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