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

Public Member Functions

 RowGroupPruner (ClientContext &context)
unique_ptr< LogicalOperator > Optimize (unique_ptr< LogicalOperator > op)
 Reorder and try to prune row groups in queries with LIMIT or simple aggregates.
bool TryOptimize (LogicalOperator &op) const
 Whether we can perform the optimization on this operator.

Private Member Functions

void GetLimitAndOffset (const LogicalLimit &logical_limit, optional_idx &row_limit, optional_idx &row_offset) const
optional_ptr< LogicalOrder > FindLogicalOrder (const LogicalLimit &logical_limit) const
optional_ptr< LogicalGet > FindLogicalGet (const LogicalOrder &logical_order, ColumnIndex &column_index) const
unique_ptr< RowGroupOrderOptions > CreateRowGroupReordererOptions (optional_idx row_limit, optional_idx row_offset, const BoundOrderByNode &primary_order, const LogicalGet &logical_get, const StorageIndex &storage_index, LogicalLimit &logical_limit) const

Private Attributes

ClientContext & context

Constructor & Destructor Documentation

◆ RowGroupPruner()

duckdb::RowGroupPruner::RowGroupPruner ( ClientContext & context)
explicit
319502 : context(context_p) {
319503}

Member Function Documentation

◆ Optimize()

unique_ptr< LogicalOperator > duckdb::RowGroupPruner::Optimize ( unique_ptr< LogicalOperator > op)

Reorder and try to prune row groups in queries with LIMIT or simple aggregates.

319505 {
319506 if (!TryOptimize(*op)) {
319507 for (auto &child : op->children) {
319508 child = Optimize(std::move(child));
319509 }
319510 }
319511
319512 return op;
319513}
unique_ptr< LogicalOperator > Optimize(unique_ptr< LogicalOperator > op)
Reorder and try to prune row groups in queries with LIMIT or simple aggregates.
Definition duckdb.cpp:319505
bool TryOptimize(LogicalOperator &op) const
Whether we can perform the optimization on this operator.
Definition duckdb.cpp:319515
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TryOptimize()

bool duckdb::RowGroupPruner::TryOptimize ( LogicalOperator & op) const

Whether we can perform the optimization on this operator.

319515 {
319516 optional_idx row_limit;
319517 optional_idx row_offset;
319518
319519 if (op.type != LogicalOperatorType::LOGICAL_LIMIT) {
319520 return false;
319521 }
319522
319523 auto &logical_limit = op.Cast<LogicalLimit>();
319524 GetLimitAndOffset(logical_limit, row_limit, row_offset);
319525 auto logical_order = FindLogicalOrder(logical_limit);
319526 if (!logical_order) {
319527 return false;
319528 }
319529
319530 // Only reorder row groups if there are no additional limit operators since they could modify the order
319531 reference<LogicalOperator> current_op = *logical_order;
319532 while (!current_op.get().children.empty()) {
319533 if (current_op.get().children.size() > 1) {
319534 return false;
319535 }
319536
319537 const auto op_type = current_op.get().type;
319538 if (op_type == LogicalOperatorType::LOGICAL_LIMIT) {
319539 return false;
319540 }
319541 if (op_type == LogicalOperatorType::LOGICAL_FILTER ||
319542 op_type == LogicalOperatorType::LOGICAL_AGGREGATE_AND_GROUP_BY) {
319543 row_limit.SetInvalid();
319544 row_offset.SetInvalid();
319545 }
319546 current_op = *current_op.get().children[0];
319547 }
319548
319549 ColumnIndex column_index;
319550 auto logical_get = FindLogicalGet(*logical_order, column_index);
319551 if (!logical_get) {
319552 return false;
319553 }
319554 StorageIndex storage_index;
319555 if (!logical_get->TryGetStorageIndex(column_index, storage_index)) {
319556 return false;
319557 }
319558
319559 if (!logical_get->table_filters.filters.empty()) {
319560 // If there are filters, we only order the row groups but do not prune
319561 row_limit.SetInvalid();
319562 row_offset.SetInvalid();
319563 }
319564
319565 // We can use the RowGroupReorderer!
319566 const auto &primary_order = logical_order->orders[0];
319567 auto options = CreateRowGroupReordererOptions(row_limit, row_offset, primary_order, *logical_get, storage_index,
319568 logical_limit);
319569 if (!options) {
319570 return false;
319571 }
319572 logical_get->SetScanOrder(std::move(options));
319573
319574 return true;
319575}
Here is the caller graph for this function:

◆ GetLimitAndOffset()

void duckdb::RowGroupPruner::GetLimitAndOffset ( const LogicalLimit & logical_limit,
optional_idx & row_limit,
optional_idx & row_offset ) const
private
319578 {
319579 if (logical_limit.limit_val.Type() == LimitNodeType::CONSTANT_VALUE) {
319580 row_limit = logical_limit.limit_val.GetConstantValue();
319581 } else if (logical_limit.limit_val.Type() == LimitNodeType::UNSET) {
319582 row_limit = 0;
319583 }
319584
319585 if (logical_limit.offset_val.Type() == LimitNodeType::CONSTANT_VALUE) {
319586 row_offset = logical_limit.offset_val.GetConstantValue();
319587 } else if (logical_limit.offset_val.Type() == LimitNodeType::UNSET) {
319588 row_offset = 0;
319589 }
319590}

◆ FindLogicalOrder()

optional_ptr< LogicalOrder > duckdb::RowGroupPruner::FindLogicalOrder ( const LogicalLimit & logical_limit) const
private
319592 {
319593 reference<LogicalOperator> current_op = *logical_limit.children[0];
319594 while (current_op.get().type == LogicalOperatorType::LOGICAL_PROJECTION) {
319595 current_op = *current_op.get().children[0];
319596 }
319597
319598 if (current_op.get().type != LogicalOperatorType::LOGICAL_ORDER_BY) {
319599 return nullptr;
319600 }
319601
319602 auto &logical_order = current_op.get().Cast<LogicalOrder>();
319603 auto order_column_type = logical_order.orders[0].expression->return_type;
319604 if (!order_column_type.IsNumeric() && !order_column_type.IsTemporal() &&
319605 order_column_type != LogicalType::VARCHAR) {
319606 return nullptr;
319607 }
319608
319609 if (logical_order.orders[0].expression->type != ExpressionType::BOUND_COLUMN_REF) {
319610 return nullptr;
319611 }
319612
319613 return logical_order;
319614}

◆ FindLogicalGet()

optional_ptr< LogicalGet > duckdb::RowGroupPruner::FindLogicalGet ( const LogicalOrder & logical_order,
ColumnIndex & column_index ) const
private
319617 {
319618 const auto &primary_order = logical_order.orders[0];
319619 auto &colref = primary_order.expression->Cast<BoundColumnRefExpression>();
319620
319621 vector<JoinFilterPushdownColumn> columns {JoinFilterPushdownColumn {colref.binding}};
319622 vector<PushdownFilterTarget> pushdown_targets;
319623 JoinFilterPushdownOptimizer::GetPushdownFilterTargets(*logical_order.children[0], std::move(columns),
319624 pushdown_targets);
319625
319626 if (pushdown_targets.empty()) {
319627 return nullptr;
319628 }
319629
319630 D_ASSERT(pushdown_targets.size() == 1);
319631 auto &logical_get = pushdown_targets.front().get;
319632
319633 if (!logical_get.function.set_scan_order) {
319634 return nullptr;
319635 }
319636
319637 auto col_idx = pushdown_targets[0].columns[0].probe_column_index.column_index;
319638 column_index = logical_get.GetColumnIds()[col_idx];
319639
319640 return logical_get;
319641}

◆ CreateRowGroupReordererOptions()

unique_ptr< RowGroupOrderOptions > duckdb::RowGroupPruner::CreateRowGroupReordererOptions ( optional_idx row_limit,
optional_idx row_offset,
const BoundOrderByNode & primary_order,
const LogicalGet & logical_get,
const StorageIndex & storage_index,
LogicalLimit & logical_limit ) const
private
319646 {
319647 const auto &colref = primary_order.expression->Cast<BoundColumnRefExpression>();
319648 const auto column_type =
319649 colref.return_type == LogicalType::VARCHAR ? OrderByColumnType::STRING : OrderByColumnType::NUMERIC;
319650 const auto order_type = primary_order.type;
319651 const auto null_order = primary_order.null_order;
319652 const auto order_by = order_type == OrderType::ASCENDING ? OrderByStatistics::MIN : OrderByStatistics::MAX;
319653 optional_idx combined_limit = row_limit.IsValid()
319654 ? row_limit.GetIndex() + (row_offset.IsValid() ? row_offset.GetIndex() : 0)
319655 : optional_idx();
319656
319657 if (row_offset.IsValid() && row_offset.GetIndex() > 0 && logical_get.function.get_partition_stats) {
319658 // Try to prune with offset
319659 GetPartitionStatsInput input(logical_get.function, logical_get.bind_data.get());
319660 auto partition_stats = logical_get.function.get_partition_stats(context, input);
319661
319662 if (!partition_stats.empty()) {
319663 auto offset_puning_result = RowGroupReorderer::GetOffsetAfterPruning(
319664 order_by, column_type, order_type, null_order, storage_index, row_offset.GetIndex(), partition_stats);
319665 if (offset_puning_result.pruned_row_group_count > 0 || offset_puning_result.leading_null_group_offset > 0) {
319666 // We can prune row groups and/or reduce the offset by consuming definite NULL-only groups
319667 logical_limit.offset_val =
319668 BoundLimitNode::ConstantValue(NumericCast<int64_t>(offset_puning_result.offset_remainder));
319669
319670 if (combined_limit.IsValid()) {
319671 combined_limit = row_limit.GetIndex() + offset_puning_result.offset_remainder;
319672 }
319673
319674 return make_uniq<RowGroupOrderOptions>(storage_index, order_by, order_type, null_order, column_type,
319675 combined_limit, offset_puning_result.pruned_row_group_count,
319676 offset_puning_result.leading_null_group_offset);
319677 }
319678 }
319679 }
319680 // Only sort row groups by primary order column and prune with limit if set
319681 return make_uniq<RowGroupOrderOptions>(storage_index, order_by, order_type, null_order, column_type, combined_limit,
319682 NumericCast<uint64_t>(0));
319683}

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