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

Physical index creation operator. More...

Inheritance diagram for duckdb::PhysicalCreateIndex:
Collaboration diagram for duckdb::PhysicalCreateIndex:

Public Member Functions

 PhysicalCreateIndex (PhysicalPlan &physical_plan, LogicalOperator &op, TableCatalogEntry &table, const vector< column_t > &column_ids, unique_ptr< CreateIndexInfo > info, vector< unique_ptr< Expression > > unbound_expressions, idx_t estimated_cardinality, IndexType index_type, unique_ptr< IndexBuildBindData > bind_data, unique_ptr< AlterTableInfo > alter_table_info)
SourceResultType GetDataInternal (ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const override
 Source interface, NOP for this operator.
bool IsSource () const override
unique_ptr< LocalSinkState > GetLocalSinkState (ExecutionContext &context) const override
 Sink interface, thread-local sink states. Contains an index for each state.
unique_ptr< GlobalSinkState > GetGlobalSinkState (ClientContext &context) const override
 Sink interface, global sink state. Contains the global index.
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
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
virtual unique_ptr< GlobalSourceState > GetGlobalSourceState (ClientContext &context) 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 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

DuckTableEntry & table
 The table to create the index for.
vector< column_t > storage_ids
 The list of column IDs of the index.
unique_ptr< CreateIndexInfo > info
 Index creation information.
vector< unique_ptr< Expression > > unbound_expressions
 Unbound expressions of the indexed columns.
IndexType index_type
 The index type to create.
unique_ptr< IndexBuildBindData > bind_data
 The bind data for index creation.
unique_ptr< AlterTableInfo > alter_table_info
 Alter table information for adding indexes.
vector< LogicalType > indexed_column_types
 Types of the indexed columns.
vector< column_t > indexed_columns
vector< column_t > rowid_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::CREATE_INDEX
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

Physical index creation operator.

Constructor & Destructor Documentation

◆ PhysicalCreateIndex()

duckdb::PhysicalCreateIndex::PhysicalCreateIndex ( PhysicalPlan & physical_plan,
LogicalOperator & op,
TableCatalogEntry & table,
const vector< column_t > & column_ids,
unique_ptr< CreateIndexInfo > info,
vector< unique_ptr< Expression > > unbound_expressions,
idx_t estimated_cardinality,
IndexType index_type,
unique_ptr< IndexBuildBindData > bind_data,
unique_ptr< AlterTableInfo > alter_table_info )
199604 : PhysicalOperator(physical_plan, PhysicalOperatorType::CREATE_INDEX, op.types, estimated_cardinality),
199605 table(table_p.Cast<DuckTableEntry>()), info(std::move(info)),
199606 unbound_expressions(std::move(unbound_expressions_p)), index_type(std::move(index_type)),
199607 bind_data(std::move(bind_data)), alter_table_info(std::move(alter_table_info)) {
199608 // Convert the logical column ids to physical column ids.
199609 for (auto &column_id : column_ids) {
199610 storage_ids.push_back(table.GetColumns().LogicalToPhysical(LogicalIndex(column_id)).index);
199611 }
199612
199613 for (idx_t i = 0; i < unbound_expressions.size(); ++i) {
199614 auto &expr = unbound_expressions[i];
199615 indexed_column_types.push_back(expr->return_type);
199616 indexed_columns.push_back(i);
199617 }
199618
199619 // Row id is alway last
199620 rowid_column.push_back(unbound_expressions.size());
199621}
unique_ptr< IndexBuildBindData > bind_data
The bind data for index creation.
Definition duckdb.cpp:199545
unique_ptr< AlterTableInfo > alter_table_info
Alter table information for adding indexes.
Definition duckdb.cpp:199547
DuckTableEntry & table
The table to create the index for.
Definition duckdb.cpp:199535
vector< LogicalType > indexed_column_types
Types of the indexed columns.
Definition duckdb.cpp:199550
IndexType index_type
The index type to create.
Definition duckdb.cpp:199543
vector< unique_ptr< Expression > > unbound_expressions
Unbound expressions of the indexed columns.
Definition duckdb.cpp:199541
unique_ptr< CreateIndexInfo > info
Index creation information.
Definition duckdb.cpp:199539
vector< column_t > storage_ids
The list of column IDs of the index.
Definition duckdb.cpp:199537
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

Member Function Documentation

◆ GetDataInternal()

SourceResultType duckdb::PhysicalCreateIndex::GetDataInternal ( ExecutionContext & context,
DataChunk & chunk,
OperatorSourceInput & input ) const
inlineoverridevirtual

Source interface, NOP for this operator.

Reimplemented from duckdb::PhysicalOperator.

199557 {
199558 return SourceResultType::FINISHED;
199559 };

◆ IsSource()

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

Reimplemented from duckdb::PhysicalOperator.

199561 {
199562 return true;
199563 }

◆ GetLocalSinkState()

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

Sink interface, thread-local sink states. Contains an index for each state.

Reimplemented from duckdb::PhysicalOperator.

199648 {
199649 auto lstate = make_uniq<CreateIndexLocalSinkState>();
199650
199651 IndexBuildInitLocalStateInput local_state_input {bind_data.get(), context.client, table,
199653 lstate->lstate = index_type.build_local_init(local_state_input);
199654
199655 lstate->key_chunk.InitializeEmpty(indexed_column_types);
199656 lstate->row_chunk.InitializeEmpty({LogicalType::ROW_TYPE});
199657
199658 return std::move(lstate);
199659}

◆ GetGlobalSinkState()

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

Sink interface, global sink state. Contains the global index.

Reimplemented from duckdb::PhysicalOperator.

199631 {
199632 auto gstate = make_uniq<CreateIndexGlobalSinkState>();
199633
199634 IndexBuildInitGlobalStateInput global_state_input {bind_data.get(), context, table, *info,
199636 gstate->gstate = index_type.build_global_init(global_state_input);
199637
199638 return std::move(gstate);
199639}

◆ Sink()

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

199661 {
199662 auto &gstate = input.global_state.Cast<CreateIndexGlobalSinkState>();
199663 auto &lstate = input.local_state.Cast<CreateIndexLocalSinkState>();
199664
199665 // FIXME: use unified format instead of Flatten
199666 chunk.Flatten();
199667
199668 // Reference the key columns and rowid column
199669 lstate.key_chunk.ReferenceColumns(chunk, indexed_columns);
199670 lstate.row_chunk.ReferenceColumns(chunk, rowid_column);
199671
199672 // Check for NULLs, if we are creating a PRIMARY KEY.
199673 // FIXME: Later, we want to ensure that we skip the NULL check for any non-PK alter.
199674 if (alter_table_info) {
199675 auto row_count = lstate.key_chunk.size();
199676 for (idx_t i = 0; i < lstate.key_chunk.ColumnCount(); i++) {
199677 if (VectorOperations::HasNull(lstate.key_chunk.data[i], row_count)) {
199678 throw ConstraintException("NOT NULL constraint failed: %s", info->index_name);
199679 }
199680 }
199681 }
199682
199683 // Sink into the index
199684 IndexBuildSinkInput sink_input {bind_data.get(), *gstate.gstate, *lstate.lstate, table, *info};
199685 index_type.build_sink(sink_input, lstate.key_chunk, lstate.row_chunk);
199686
199687 return SinkResultType::NEED_MORE_INPUT;
199688}
DUCKDB_API void Flatten()
Turn all the vectors from the chunk into flat vectors.
Definition duckdb.cpp:116989
Here is the call graph for this function:

◆ Combine()

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

199690 {
199691 auto &gstate = input.global_state.Cast<CreateIndexGlobalSinkState>();
199692 auto &lstate = input.local_state.Cast<CreateIndexLocalSinkState>();
199693
199694 IndexBuildCombineInput combine_input {bind_data.get(), *gstate.gstate, *lstate.lstate, table, *info};
199695 index_type.build_combine(combine_input);
199696
199697 return SinkCombineResultType::FINISHED;
199698}

◆ Finalize()

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

199701 {
199702 auto &gstate = input.global_state.Cast<CreateIndexGlobalSinkState>();
199703
199704 // Finalize the index
199705 IndexBuildFinalizeInput finalize_input {*gstate.gstate};
199706 auto bound_index = index_type.build_finalize(finalize_input);
199707
199708 // Vacuum excess memory and verify.
199709 bound_index->Vacuum();
199710
199711 bound_index->Verify();
199712
199713 D_ASSERT(!bound_index->ToString(true).empty());
199714
199715 bound_index->VerifyAllocations();
199716
199717 auto &storage = table.GetStorage();
199718 if (!storage.IsMainTable()) {
199719 throw TransactionException(
199720 "Transaction conflict: cannot add an index to a table that has been altered or dropped");
199721 }
199722
199723 auto &schema = table.schema;
199724 info->column_ids = storage_ids;
199725
199726 if (!alter_table_info) {
199727 // Ensure that the index does not yet exist in the catalog.
199728 auto entry = schema.GetEntry(schema.GetCatalogTransaction(context), CatalogType::INDEX_ENTRY, info->index_name);
199729 if (entry) {
199730 if (info->on_conflict != OnCreateConflict::IGNORE_ON_CONFLICT) {
199731 throw CatalogException("Index with name \"%s\" already exists!", info->index_name);
199732 }
199733 // IF NOT EXISTS on existing index. We are done.
199734 return SinkFinalizeType::READY;
199735 }
199736
199737 auto index_entry = schema.CreateIndex(schema.GetCatalogTransaction(context), *info, table).get();
199738 D_ASSERT(index_entry);
199739 auto &index = index_entry->Cast<DuckIndexEntry>();
199740 index.initial_index_size = bound_index->GetInMemorySize();
199741
199742 } else {
199743 // Ensure that there are no other indexes with that name on this table.
199744 auto &indexes = storage.GetDataTableInfo()->GetIndexes();
199745 for (auto &index : indexes.Indexes()) {
199746 if (index.GetIndexName() == info->index_name) {
199747 throw CatalogException("an index with that name already exists for this table: %s", info->index_name);
199748 }
199749 }
199750
199751 auto &catalog = Catalog::GetCatalog(context, info->catalog);
199752 catalog.Alter(context, *alter_table_info);
199753 }
199754
199755 // Add the index to the storage.
199756 storage.AddIndex(std::move(bound_index));
199757
199758 return SinkFinalizeType::READY;
199759}
static DUCKDB_API Catalog & GetCatalog(ClientContext &context, const string &catalog_name)
Get the specified Catalog from the ClientContext.
Definition duckdb.cpp:7211
index
Here is the call graph for this function:

◆ IsSink()

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

Reimplemented from duckdb::PhysicalOperator.

199575 {
199576 return true;
199577 }

◆ ParallelSink()

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

Reimplemented from duckdb::PhysicalOperator.

199578 {
199579 return true;
199580 }

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