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

Protected Member Functions

void VisitExpression (unique_ptr< Expression > *expression) override
unique_ptr< Expression > VisitReplace (BoundColumnRefExpression &expr, unique_ptr< Expression > *expr_ptr) override
unique_ptr< Expression > VisitReplace (BoundReferenceExpression &expr, unique_ptr< Expression > *expr_ptr) override
void AddBinding (BoundColumnRefExpression &col)
 Add a reference to the column in its entirey.
void AddBinding (BoundColumnRefExpression &col, ColumnIndex child_column)
 Add a reference to a sub-section of the column.
void AddBinding (BoundColumnRefExpression &col, ColumnIndex child_column, const vector< ReferencedExtractComponent > &parent)
 Add a reference to a sub-section of the column used in a struct extract, with the parent expression.
idx_t ReplaceBinding (ColumnBinding current_binding, ColumnBinding new_binding)
bool HandleExtractExpression (unique_ptr< Expression > *expression, optional_ptr< unique_ptr< Expression > > cast_expression=nullptr)
bool HandleStructExtract (unique_ptr< Expression > &expr, optional_ptr< BoundColumnRefExpression > &colref, reference< ColumnIndex > &path_ref, vector< ReferencedExtractComponent > &expressions)
bool HandleVariantExtract (unique_ptr< Expression > &expr, optional_ptr< BoundColumnRefExpression > &colref, reference< ColumnIndex > &path_ref, vector< ReferencedExtractComponent > &expressions)
bool HandleExtractRecursive (unique_ptr< Expression > &expr, optional_ptr< BoundColumnRefExpression > &colref, reference< ColumnIndex > &path_ref, vector< ReferencedExtractComponent > &expressions)
void SetMode (BaseColumnPrunerMode mode)
BaseColumnPrunerMode GetMode () const
Protected Member Functions inherited from duckdb::LogicalOperatorVisitor
void VisitOperatorChildren (LogicalOperator &op)
void VisitOperatorExpressions (LogicalOperator &op)
void VisitOperatorWithProjectionMapChildren (LogicalOperator &op)
 Alternatives for VisitOperatorChildren for operators that have a projection map.
void VisitChildOfOperatorWithProjectionMap (LogicalOperator &child, vector< idx_t > &projection_map)
virtual void VisitExpressionChildren (Expression &expression)
virtual unique_ptr< Expression > VisitReplace (BoundAggregateExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundBetweenExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundCaseExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundCastExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundComparisonExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundConjunctionExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundConstantExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundDefaultExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundFunctionExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundOperatorExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundSubqueryExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundParameterExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundWindowExpression &expr, unique_ptr< Expression > *expr_ptr)
virtual unique_ptr< Expression > VisitReplace (BoundUnnestExpression &expr, unique_ptr< Expression > *expr_ptr)

Protected Attributes

column_binding_map_t< ReferencedColumn > column_references
 The map of column references.

Private Member Functions

void MergeChildColumns (vector< ColumnIndex > &current_child_columns, ColumnIndex &new_child_column)

Private Attributes

BaseColumnPrunerMode mode = BaseColumnPrunerMode::DEFAULT
 The current mode of the pruner, enables/disables certain behaviors.

Additional Inherited Members

Public Member Functions inherited from duckdb::LogicalOperatorVisitor
virtual void VisitOperator (LogicalOperator &op)
Static Public Member Functions inherited from duckdb::LogicalOperatorVisitor
static void EnumerateExpressions (LogicalOperator &op, const std::function< void(unique_ptr< Expression > *child)> &callback)

Member Function Documentation

◆ VisitExpression()

void duckdb::BaseColumnPruner::VisitExpression ( unique_ptr< Expression > * expression)
overrideprotectedvirtual

Check if this is a struct extract wrapped in a cast

Check if this is a struct extract

Reimplemented from duckdb::LogicalOperatorVisitor.

319455 {
319457 optional_ptr<unique_ptr<Expression>> cast_child;
319458 if (TryGetCastChild(*expression, cast_child)) {
319459 if (HandleExtractExpression(cast_child.get(), expression)) {
319460 // already handled
319461 return;
319462 }
319463 }
319464
319466 if (HandleExtractExpression(expression)) {
319467 // already handled
319468 return;
319469 }
319470 // recurse
319471 LogicalOperatorVisitor::VisitExpression(expression);
319472}
Here is the caller graph for this function:

◆ VisitReplace() [1/2]

unique_ptr< Expression > duckdb::BaseColumnPruner::VisitReplace ( BoundColumnRefExpression & expr,
unique_ptr< Expression > * expr_ptr )
overrideprotectedvirtual

Reimplemented from duckdb::LogicalOperatorVisitor.

319475 {
319476 // add a reference to the entire column
319477 AddBinding(expr);
319478 return nullptr;
319479}
void AddBinding(BoundColumnRefExpression &col)
Add a reference to the column in its entirey.
Definition duckdb.cpp:319428

◆ VisitReplace() [2/2]

unique_ptr< Expression > duckdb::BaseColumnPruner::VisitReplace ( BoundReferenceExpression & expr,
unique_ptr< Expression > * expr_ptr )
overrideprotectedvirtual

Reimplemented from duckdb::LogicalOperatorVisitor.

319482 {
319483 // BoundReferenceExpression should not be used here yet, they only belong in the physical plan
319484 throw InternalException("BoundReferenceExpression should not be used here yet!");
319485}

◆ AddBinding() [1/3]

void duckdb::BaseColumnPruner::AddBinding ( BoundColumnRefExpression & col)
protected

Add a reference to the column in its entirey.

319428 {
319429 auto entry = column_references.find(col.binding);
319430 if (entry == column_references.end()) {
319431 // column not referenced yet - add a binding to it entirely
319432 column_references[col.binding].bindings.push_back(col);
319433 } else {
319434 // column reference already exists - add the binding and clear any sub-references
319435 auto &column = entry->second;
319436 column.bindings.push_back(col);
319437 column.child_columns.clear();
319438 }
319439}
column_binding_map_t< ReferencedColumn > column_references
The map of column references.
Definition duckdb.cpp:60560
Here is the caller graph for this function:

◆ AddBinding() [2/3]

void duckdb::BaseColumnPruner::AddBinding ( BoundColumnRefExpression & col,
ColumnIndex child_column )
protected

Add a reference to a sub-section of the column.

Any child referenced after this mode is set disables PUSHDOWN_EXTRACT

319359 {
319360 auto entry = column_references.find(col.binding);
319361 if (entry == column_references.end()) {
319362 // column not referenced yet - add a binding to it entirely
319363 ReferencedColumn column;
319364 column.bindings.push_back(col);
319365 column.child_columns.push_back(std::move(child_column));
319366 entry = column_references.emplace(make_pair(col.binding, std::move(column))).first;
319367 } else {
319368 // column reference already exists - check add the binding
319369 auto &column = entry->second;
319370 column.bindings.push_back(col);
319371
319372 MergeChildColumns(column.child_columns, child_column);
319373 }
319376 entry->second.supports_pushdown_extract = PushdownExtractSupport::DISABLED;
319377 }
319378}
BaseColumnPrunerMode mode
The current mode of the pruner, enables/disables certain behaviors.
Definition duckdb.cpp:60564
@ DISABLE_PUSHDOWN_EXTRACT
Any child reference disables PUSHDOWN_EXTRACT for the parent column.
Definition duckdb.cpp:60512

◆ AddBinding() [3/3]

void duckdb::BaseColumnPruner::AddBinding ( BoundColumnRefExpression & col,
ColumnIndex child_column,
const vector< ReferencedExtractComponent > & parent )
protected

Add a reference to a sub-section of the column used in a struct extract, with the parent expression.

Save a reference to the top-level struct extract, so we can potentially replace it later

NOTE: this path does not contain the column index of the root, i.e 's.a' will just be a ColumnIndex with the index of 'a', without children

319411 {
319412 AddBinding(col, child_column);
319413 auto entry = column_references.find(col.binding);
319414 if (entry == column_references.end()) {
319415 throw InternalException("ColumnBinding for the col was somehow not added by the previous step?");
319416 }
319417 auto &referenced_column = entry->second;
319419 D_ASSERT(!referenced_column.bindings.empty());
319420
319423 referenced_column.AddPath(child_column);
319424 referenced_column.struct_extracts.emplace_back(parent, referenced_column.bindings.size() - 1,
319425 std::move(child_column));
319426}
Here is the call graph for this function:

◆ ReplaceBinding()

idx_t duckdb::BaseColumnPruner::ReplaceBinding ( ColumnBinding current_binding,
ColumnBinding new_binding )
protected

Perform a replacement of the ColumnBinding, iterating over all the currently found column references and replacing the bindings ret: The amount of bindings created

Pushdown extract is supported, so we are potentially creating multiple bindings, 1 for each unique extract path

No pushdown extract, just rewrite the existing bindings

318358 {
318359 auto colrefs = column_references.find(current_binding);
318360 if (colrefs == column_references.end()) {
318361 return 1;
318362 }
318363
318364 auto &col = colrefs->second;
318365 idx_t created_bindings;
318366 if (!col.child_columns.empty() && col.supports_pushdown_extract == PushdownExtractSupport::ENABLED) {
318367 D_ASSERT(!col.unique_paths.empty());
318370 created_bindings = col.unique_paths.size();
318371 } else {
318373 for (auto &colref_p : col.bindings) {
318374 auto &colref = colref_p.get();
318375 D_ASSERT(colref.binding == current_binding);
318376 colref.binding = new_binding;
318377 }
318378 created_bindings = 1;
318379 }
318380 return created_bindings;
318381}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the caller graph for this function:

◆ HandleExtractExpression()

bool duckdb::BaseColumnPruner::HandleExtractExpression ( unique_ptr< Expression > * expression,
optional_ptr< unique_ptr< Expression > > cast_expression = nullptr )
protected
319300 {
319301 optional_ptr<BoundColumnRefExpression> colref;
319302 vector<ReferencedExtractComponent> expressions;
319303
319304 ColumnIndex path(0);
319305 reference<ColumnIndex> path_ref(path);
319306 if (!HandleExtractRecursive(*expression, colref, path_ref, expressions)) {
319307 return false;
319308 }
319309 if (cast_expression) {
319310 auto &top_level = expressions.back();
319311 top_level.cast = cast_expression;
319312 path_ref.get().SetType((*cast_expression)->return_type);
319313 }
319314
319315 AddBinding(*colref, path.GetChildIndex(0), expressions);
319316 return true;
319317}

◆ HandleStructExtract()

bool duckdb::BaseColumnPruner::HandleStructExtract ( unique_ptr< Expression > & expr,
optional_ptr< BoundColumnRefExpression > & colref,
reference< ColumnIndex > & path_ref,
vector< ReferencedExtractComponent > & expressions )
protected
319199 {
319200 auto &function = expr_p->Cast<BoundFunctionExpression>();
319201 auto &child = function.children[0];
319202 D_ASSERT(child->return_type.id() == LogicalTypeId::STRUCT);
319203 auto &bind_data = function.bind_info->Cast<StructExtractBindData>();
319204 // struct extract, check if left child is a bound column ref
319205 if (child->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF) {
319206 // column reference - check if it is a struct
319207 auto &ref = child->Cast<BoundColumnRefExpression>();
319208 if (ref.return_type.id() != LogicalTypeId::STRUCT) {
319209 return false;
319210 }
319211 colref = &ref;
319212 auto &path = path_ref.get();
319213 path.AddChildIndex(ColumnIndex(bind_data.index));
319214 path_ref = path.GetChildIndex(0);
319215 expressions.emplace_back(expr_p);
319216 return true;
319217 }
319218 // not a column reference - try to handle this recursively
319219 if (!HandleExtractRecursive(child, colref, path_ref, expressions)) {
319220 return false;
319221 }
319222 auto &path = path_ref.get();
319223 path.AddChildIndex(ColumnIndex(bind_data.index));
319224 path_ref = path.GetChildIndex(0);
319225
319226 expressions.emplace_back(expr_p);
319227 return true;
319228}

◆ HandleVariantExtract()

bool duckdb::BaseColumnPruner::HandleVariantExtract ( unique_ptr< Expression > & expr,
optional_ptr< BoundColumnRefExpression > & colref,
reference< ColumnIndex > & path_ref,
vector< ReferencedExtractComponent > & expressions )
protected

We don't push down variant extract on ARRAY values

319233 {
319234 auto &function = expr_p->Cast<BoundFunctionExpression>();
319235 auto &child = function.children[0];
319236 D_ASSERT(child->return_type.id() == LogicalTypeId::VARIANT);
319237 auto &bind_data = function.bind_info->Cast<VariantExtractBindData>();
319238 if (bind_data.component.lookup_mode != VariantChildLookupMode::BY_KEY) {
319240 return false;
319241 }
319242 // variant extract, check if left child is a bound column ref
319243 if (child->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF) {
319244 // column reference - check if it is a variant
319245 auto &ref = child->Cast<BoundColumnRefExpression>();
319246 if (ref.return_type.id() != LogicalTypeId::VARIANT) {
319247 return false;
319248 }
319249 colref = &ref;
319250
319251 auto &path = path_ref.get();
319252 path.AddChildIndex(ColumnIndex(bind_data.component.key));
319253 path_ref = path.GetChildIndex(0);
319254
319255 expressions.emplace_back(expr_p);
319256 return true;
319257 }
319258 // not a column reference - try to handle this recursively
319259 if (!HandleExtractRecursive(child, colref, path_ref, expressions)) {
319260 return false;
319261 }
319262
319263 auto &path = path_ref.get();
319264 path.AddChildIndex(ColumnIndex(bind_data.component.key));
319265 path_ref = path.GetChildIndex(0);
319266
319267 expressions.emplace_back(expr_p);
319268 return true;
319269}
Here is the call graph for this function:

◆ HandleExtractRecursive()

bool duckdb::BaseColumnPruner::HandleExtractRecursive ( unique_ptr< Expression > & expr,
optional_ptr< BoundColumnRefExpression > & colref,
reference< ColumnIndex > & path_ref,
vector< ReferencedExtractComponent > & expressions )
protected
319274 {
319275 auto &expr = *expr_p;
319276 if (expr.GetExpressionClass() != ExpressionClass::BOUND_FUNCTION) {
319277 return false;
319278 }
319279 auto &function = expr.Cast<BoundFunctionExpression>();
319280 if (function.function.name != "struct_extract_at" && function.function.name != "struct_extract" &&
319281 function.function.name != "array_extract" && function.function.name != "variant_extract") {
319282 return false;
319283 }
319284 if (!function.bind_info) {
319285 return false;
319286 }
319287 auto &child = function.children[0];
319288 auto child_type = child->return_type.id();
319289 switch (child_type) {
319290 case LogicalTypeId::STRUCT:
319291 return HandleStructExtract(expr_p, colref, path_ref, expressions);
319292 case LogicalTypeId::VARIANT:
319293 return HandleVariantExtract(expr_p, colref, path_ref, expressions);
319294 default:
319295 return false;
319296 }
319297}
bool HandleVariantExtract(unique_ptr< Expression > &expr, optional_ptr< BoundColumnRefExpression > &colref, reference< ColumnIndex > &path_ref, vector< ReferencedExtractComponent > &expressions)
Definition duckdb.cpp:319230

◆ SetMode()

void duckdb::BaseColumnPruner::SetMode ( BaseColumnPrunerMode mode)
protected
319188 {
319189 this->mode = mode;
319190}

◆ GetMode()

BaseColumnPrunerMode duckdb::BaseColumnPruner::GetMode ( ) const
protected
319192 {
319193 return mode;
319194}

◆ MergeChildColumns()

void duckdb::BaseColumnPruner::MergeChildColumns ( vector< ColumnIndex > & current_child_columns,
ColumnIndex & new_child_column )
private
319319 {
319320 if (current_child_columns.empty()) {
319321 // there's already a reference to the full column - we can't extract only a subfield
319322 // skip struct projection pushdown
319323 return;
319324 }
319325 // if we are already extract sub-fields, add it (if it is not there yet)
319326 for (auto &binding : current_child_columns) {
319327 if (binding.HasPrimaryIndex()) {
319328 if (!new_child_column.HasPrimaryIndex()) {
319329 continue;
319330 }
319331 if (binding.GetPrimaryIndex() != new_child_column.GetPrimaryIndex()) {
319332 continue;
319333 }
319334 } else {
319335 if (new_child_column.HasPrimaryIndex()) {
319336 continue;
319337 }
319338 if (binding.GetFieldName() != new_child_column.GetFieldName()) {
319339 continue;
319340 }
319341 }
319342 // found a match: sub-field is already projected
319343 // check if we have child columns
319344 auto &nested_child_columns = binding.GetChildIndexesMutable();
319345 if (!new_child_column.HasChildren()) {
319346 // new child is a reference to a full column - clear any existing bindings (if any)
319347 nested_child_columns.clear();
319348 } else {
319349 // new child has a sub-reference - merge recursively
319350 D_ASSERT(new_child_column.ChildIndexCount() == 1);
319351 MergeChildColumns(nested_child_columns, new_child_column.GetChildIndex(0));
319352 }
319353 return;
319354 }
319355 // this child column is not projected yet - add it in
319356 current_child_columns.push_back(std::move(new_child_column));
319357}

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