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

Public Member Functions

 LogicalUpdate (TableCatalogEntry &table)
void Serialize (Serializer &serializer) const override
idx_t EstimateCardinality (ClientContext &context) override
string GetName () const override
Public Member Functions inherited from duckdb::LogicalOperator
 LogicalOperator (LogicalOperatorType type)
 LogicalOperator (LogicalOperatorType type, vector< unique_ptr< Expression > > expressions)
virtual idx_t GetRootIndex ()
void PrintColumnBindings ()
void ResolveOperatorTypes ()
 Resolve the types of the logical operator and its children.
virtual InsertionOrderPreservingMap< string > ParamsToString () const
virtual string ToString (ExplainFormat format=ExplainFormat::DEFAULT) const
DUCKDB_API void Print ()
virtual void Verify (ClientContext &context)
 Debug method: verify that the integrity of expressions & child nodes are maintained.
void AddChild (unique_ptr< LogicalOperator > child)
void SetEstimatedCardinality (idx_t _estimated_cardinality)
void SetParamsEstimatedCardinality (InsertionOrderPreservingMap< string > &result) const
virtual unique_ptr< LogicalOperator > Copy (ClientContext &context) const
virtual bool RequireOptimizer () const
virtual bool SupportSerialization () const
 Allows LogicalOperators to opt out of serialization.
virtual bool HasProjectionMap () const
virtual vector< idx_t > GetTableIndex () const
 Returns the set of table indexes of this operator.
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const

Static Public Member Functions

static unique_ptr< LogicalOperator > Deserialize (Deserializer &deserializer)
static DUCKDB_API void BindExtraColumns (TableCatalogEntry &table, LogicalGet &get, LogicalProjection &proj, LogicalUpdate &update, physical_index_set_t &bound_columns)
static void RewriteInPlaceUpdates (LogicalOperator &update_op)
Static Public Member Functions inherited from duckdb::LogicalOperator
static string ColumnBindingsToString (const vector< ColumnBinding > &bindings)
static vector< ColumnBinding > GenerateColumnBindings (idx_t table_idx, idx_t column_count)
static vector< LogicalType > MapTypes (const vector< LogicalType > &types, const vector< idx_t > &projection_map)
static vector< ColumnBinding > MapBindings (const vector< ColumnBinding > &types, const vector< idx_t > &projection_map)
static unique_ptr< LogicalOperator > Deserialize (Deserializer &deserializer)

Public Attributes

TableCatalogEntry & table
 The base table to update.
idx_t table_index
 projection index
bool return_chunk
 if returning option is used, return the update chunk
vector< PhysicalIndex > columns
vector< unique_ptr< Expression > > bound_defaults
vector< unique_ptr< BoundConstraint > > bound_constraints
bool update_is_del_and_insert
Public Attributes inherited from duckdb::LogicalOperator
LogicalOperatorType type
 The type of the logical operator.
vector< unique_ptr< LogicalOperator > > children
 The set of children of the operator.
vector< unique_ptr< Expression > > expressions
 The set of expressions contained within the operator, if any.
vector< LogicalType > types
 The types returned by this logical operator. Set by calling LogicalOperator::ResolveTypes.
idx_t estimated_cardinality
 Estimated Cardinality.
bool has_estimated_cardinality

Static Public Attributes

static constexpr const LogicalOperatorType TYPE = LogicalOperatorType::LOGICAL_UPDATE

Protected Member Functions

vector< ColumnBinding > GetColumnBindings () override
void ResolveTypes () override
 Resolve types for this specific operator.

Private Member Functions

 LogicalUpdate (ClientContext &context, const unique_ptr< CreateInfo > &table_info)

Constructor & Destructor Documentation

◆ LogicalUpdate() [1/2]

duckdb::LogicalUpdate::LogicalUpdate ( TableCatalogEntry & table)
explicit
383210 : LogicalOperator(LogicalOperatorType::LOGICAL_UPDATE), table(table), table_index(0), return_chunk(false) {
383211}
idx_t table_index
projection index
Definition duckdb.cpp:12943
TableCatalogEntry & table
The base table to update.
Definition duckdb.cpp:12941
bool return_chunk
if returning option is used, return the update chunk
Definition duckdb.cpp:12945

◆ LogicalUpdate() [2/2]

duckdb::LogicalUpdate::LogicalUpdate ( ClientContext & context,
const unique_ptr< CreateInfo > & table_info )
private
383214 : LogicalOperator(LogicalOperatorType::LOGICAL_UPDATE),
383215 table(Catalog::GetEntry<TableCatalogEntry>(context, table_info->catalog, table_info->schema,
383216 table_info->Cast<CreateTableInfo>().table)) {
383217 auto binder = Binder::CreateBinder(context);
383218 bound_constraints = binder->BindConstraints(table);
383219}
DUCKDB_API optional_ptr< CatalogEntry > GetEntry(ClientContext &context, const string &schema, const EntryLookupInfo &lookup_info, OnEntryNotFound if_not_found)
Gets the "schema.name" entry of the specified type, if entry does not exist behavior depends on OnEnt...
Definition duckdb.cpp:8156

Member Function Documentation

◆ Serialize()

void duckdb::LogicalUpdate::Serialize ( Serializer & serializer) const
overridevirtual

Reimplemented from duckdb::LogicalOperator.

417072 {
417073 LogicalOperator::Serialize(serializer);
417074 serializer.WritePropertyWithDefault<unique_ptr<CreateInfo>>(200, "table_info", table.GetInfo());
417075 serializer.WritePropertyWithDefault<idx_t>(201, "table_index", table_index);
417076 serializer.WritePropertyWithDefault<bool>(202, "return_chunk", return_chunk);
417077 serializer.WritePropertyWithDefault<vector<unique_ptr<Expression>>>(203, "expressions", expressions);
417078 serializer.WritePropertyWithDefault<vector<PhysicalIndex>>(204, "columns", columns);
417079 serializer.WritePropertyWithDefault<vector<unique_ptr<Expression>>>(205, "bound_defaults", bound_defaults);
417080 serializer.WritePropertyWithDefault<bool>(206, "update_is_del_and_insert", update_is_del_and_insert);
417081}
vector< unique_ptr< Expression > > expressions
The set of expressions contained within the operator, if any.
Definition duckdb.hpp:21264
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ Deserialize()

unique_ptr< LogicalOperator > duckdb::LogicalUpdate::Deserialize ( Deserializer & deserializer)
static
417083 {
417084 auto table_info = deserializer.ReadPropertyWithDefault<unique_ptr<CreateInfo>>(200, "table_info");
417085 auto result = duckdb::unique_ptr<LogicalUpdate>(new LogicalUpdate(deserializer.Get<ClientContext &>(), table_info));
417086 deserializer.ReadPropertyWithDefault<idx_t>(201, "table_index", result->table_index);
417087 deserializer.ReadPropertyWithDefault<bool>(202, "return_chunk", result->return_chunk);
417088 deserializer.ReadPropertyWithDefault<vector<unique_ptr<Expression>>>(203, "expressions", result->expressions);
417089 deserializer.ReadPropertyWithDefault<vector<PhysicalIndex>>(204, "columns", result->columns);
417090 deserializer.ReadPropertyWithDefault<vector<unique_ptr<Expression>>>(205, "bound_defaults", result->bound_defaults);
417091 deserializer.ReadPropertyWithDefault<bool>(206, "update_is_del_and_insert", result->update_is_del_and_insert);
417092 return std::move(result);
417093}

◆ EstimateCardinality()

idx_t duckdb::LogicalUpdate::EstimateCardinality ( ClientContext & context)
overridevirtual

Reimplemented from duckdb::LogicalOperator.

383221 {
383222 return return_chunk ? LogicalOperator::EstimateCardinality(context) : 1;
383223}

◆ GetName()

string duckdb::LogicalUpdate::GetName ( ) const
overridevirtual

Reimplemented from duckdb::LogicalOperator.

383240 {
383241#ifdef DEBUG
383243 return LogicalOperator::GetName() + StringUtil::Format(" #%llu", table_index);
383244 }
383245#endif
383246 return LogicalOperator::GetName();
383247}
static string Format(const string fmt_str, ARGS... params)
Format a string using printf semantics.
Definition duckdb.hpp:4002
static bool debug_print_bindings
Whether to print bindings when printing the plan (debug mode only).
Definition duckdb.hpp:40040

◆ BindExtraColumns()

void duckdb::LogicalUpdate::BindExtraColumns ( TableCatalogEntry & table,
LogicalGet & get,
LogicalProjection & proj,
LogicalUpdate & update,
physical_index_set_t & bound_columns )
static
21140 {
21141 if (bound_columns.size() <= 1) {
21142 return;
21143 }
21144 idx_t found_column_count = 0;
21145 physical_index_set_t found_columns;
21146 for (idx_t i = 0; i < update.columns.size(); i++) {
21147 if (bound_columns.find(update.columns[i]) != bound_columns.end()) {
21148 // this column is referenced in the CHECK constraint
21149 found_column_count++;
21150 found_columns.insert(update.columns[i]);
21151 }
21152 }
21153 if (found_column_count != bound_columns.size()) {
21154 // columns that were required are not all part of the UPDATE
21155 // add them to the scan and update set
21156 for (auto &physical_id : bound_columns) {
21157 if (found_columns.find(physical_id) != found_columns.end()) {
21158 // column is already projected
21159 continue;
21160 }
21161 // column is not projected yet: project it by adding the clause "i=i" to the set of updated columns
21162 auto &column = table.GetColumns().GetColumn(physical_id);
21163 update.expressions.push_back(make_uniq<BoundColumnRefExpression>(
21164 column.Type(), ColumnBinding(proj.table_index, proj.expressions.size())));
21165 proj.expressions.push_back(make_uniq<BoundColumnRefExpression>(
21166 column.Type(), ColumnBinding(get.table_index, get.GetColumnIds().size())));
21167 get.AddColumnId(column.Logical().index);
21168 update.columns.push_back(physical_id);
21169 }
21170 }
21171}
__host__ cudaTextureObject_t get() const noexcept

◆ RewriteInPlaceUpdates()

void duckdb::LogicalUpdate::RewriteInPlaceUpdates ( LogicalOperator & update_op)
static
383249 {
383250 auto &update = update_op.Cast<LogicalUpdate>();
383251
383252 if (update.update_is_del_and_insert) {
383253 return;
383254 }
383255 auto needs_reinsert = false;
383256 for (auto &col_idx : update.columns) {
383257 auto &column = update.table.GetColumns().GetColumn(col_idx);
383258 if (!column.Type().SupportsRegularUpdate()) {
383259 needs_reinsert = true;
383260 break;
383261 }
383262 }
383263 if (!needs_reinsert) {
383264 return;
383265 }
383266
383267 // Okay, we are reading an old plan version that has in-place updates for a type that no longer supports it.
383268 // We need to convert the update into a delete + insert.
383269
383270 // The UPDATE operator always expects the rowid column to be the last.
383271 auto rowid_binding = update_op.children.back()->GetColumnBindings().back();
383272
383273 // We're looking for the GET operator that produces this rowid, and therefore produce this binding.
383274 // There might be projections in betweeen though, so we need to traverse through them.
383275 auto target_binding = rowid_binding;
383276 vector<reference<unique_ptr<LogicalOperator>>> stack;
383277
383278 // Collect all projections along the way, as well as the GET operator, so that we can update them later.
383279 vector<reference<unique_ptr<LogicalOperator>>> projections;
383280 unique_ptr<LogicalOperator> *get_op = nullptr;
383281
383282 stack.emplace_back(update_op.children.back());
383283
383284 auto is_done = false;
383285
383286 while (!stack.empty() && !is_done) {
383287 auto &current = stack.back().get();
383288 stack.pop_back();
383289
383290 switch (current->type) {
383291 case LogicalOperatorType::LOGICAL_PROJECTION: {
383292 // Does this projection produce the target binding?
383293 auto &proj = current->Cast<LogicalProjection>();
383294 if (target_binding.table_index == proj.table_index) {
383295 // This is the projection we're looking for!
383296 projections.emplace_back(current);
383297
383298 // Update the target binding.
383299 target_binding =
383300 proj.expressions[target_binding.column_index]->Cast<BoundColumnRefExpression>().binding;
383301
383302 // Traverse the child.
383303 stack.push_back(proj.children.back());
383304 }
383305 } break;
383306 case LogicalOperatorType::LOGICAL_GET: {
383307 // Is this the GET at the root of our projection chain?
383308
383309 auto &get = current->Cast<LogicalGet>();
383310 if (target_binding.table_index == get.table_index) {
383311 // We found the GET operator we're looking for, we can stop traversing.
383312 is_done = true;
383313 get_op = &current;
383314 break;
383315 }
383316 } break;
383317 default: {
383318 // Otherwise, this is some random operator. Traverse all children!
383319 for (auto &child : current->children) {
383320 stack.emplace_back(child);
383321 }
383322 }
383323 }
383324 }
383325
383326 // We should have found the GET operator by now, if not, this is an error in the plan.
383327 if (!is_done || !get_op) {
383328 throw InternalException("Could not find the expected GET operator in the LogicalUpdate operator children");
383329 }
383330
383331 auto &get = get_op->get()->Cast<LogicalGet>();
383332
383333 // Now, we need to update the GET operator to include ALL the other columns.
383334 physical_index_set_t all_columns;
383335 for (auto &column : update.table.GetColumns().Physical()) {
383336 all_columns.insert(column.Physical());
383337 }
383338
383339 idx_t found_column_count = 0;
383340 physical_index_set_t found_columns;
383341 for (idx_t i = 0; i < update.columns.size(); i++) {
383342 if (all_columns.find(update.columns[i]) != all_columns.end()) {
383343 // this column is referenced already
383344 found_column_count++;
383345 found_columns.insert(update.columns[i]);
383346 }
383347 }
383348
383349 if (found_column_count != all_columns.size()) {
383350 for (auto &physical_id : all_columns) {
383351 if (found_columns.find(physical_id) != found_columns.end()) {
383352 // column is already projected
383353 continue;
383354 }
383355
383356 auto &column = update.table.GetColumns().GetColumn(physical_id);
383357
383358 // Add it to the GET operator
383359 get.AddColumnId(column.Logical().index);
383360
383361 // Now, for each projection on the path from the GET to the UPDATE, we need to add this column as well.
383362 // We do this in backwards order, always adding a column reference to the previously added column,
383363 // so that we end up with a chain of column references that all point to the newly added column in the GET.
383364
383365 auto prev_col_idx = get.GetColumnIds().size() - 1;
383366 auto prev_tbl_idx = get.GetTableIndex().back();
383367
383368 for (int64_t i = UnsafeNumericCast<int64_t>(projections.size()) - 1; i >= 0; i--) {
383369 auto &proj = projections[UnsafeNumericCast<idx_t>(i)].get()->Cast<LogicalProjection>();
383370
383371 if (i == 0) {
383372 // This is the last projection, push the new columns next-to-last so that rowid remains last
383373 proj.expressions.insert(
383374 proj.expressions.end() - 1,
383375 make_uniq<BoundColumnRefExpression>(column.Type(), ColumnBinding(prev_tbl_idx, prev_col_idx)));
383376
383377 prev_col_idx = proj.expressions.size() - 2;
383378 prev_tbl_idx = proj.table_index;
383379 } else {
383380 proj.expressions.push_back(
383381 make_uniq<BoundColumnRefExpression>(column.Type(), ColumnBinding(prev_tbl_idx, prev_col_idx)));
383382
383383 prev_col_idx = proj.expressions.size() - 1;
383384 prev_tbl_idx = proj.table_index;
383385 }
383386 }
383387
383388 // Finally, add the column to the UPDATE operator too
383389 update.columns.push_back(physical_id);
383390 update.expressions.push_back(
383391 make_uniq<BoundColumnRefExpression>(column.Type(), ColumnBinding(prev_tbl_idx, prev_col_idx)));
383392 }
383393 }
383394
383395 update.update_is_del_and_insert = true;
383396 update.ResolveOperatorTypes();
383397}

◆ GetColumnBindings()

vector< ColumnBinding > duckdb::LogicalUpdate::GetColumnBindings ( )
overrideprotectedvirtual

Reimplemented from duckdb::LogicalOperator.

383225 {
383226 if (return_chunk) {
383227 return GenerateColumnBindings(table_index, table.GetTypes().size());
383228 }
383229 return {ColumnBinding(0, 0)};
383230}

◆ ResolveTypes()

void duckdb::LogicalUpdate::ResolveTypes ( )
overrideprotectedvirtual

Resolve types for this specific operator.

Implements duckdb::LogicalOperator.

383232 {
383233 if (return_chunk) {
383234 types = table.GetTypes();
383235 } else {
383236 types.emplace_back(LogicalType::BIGINT);
383237 }
383238}
vector< LogicalType > types
The types returned by this logical operator. Set by calling LogicalOperator::ResolveTypes.
Definition duckdb.hpp:21266

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