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

Public Member Functions

 RowGroupReorderer (const RowGroupOrderOptions &options_p)
optional_ptr< SegmentNode< RowGroup > > GetRootSegment (RowGroupSegmentTree &row_groups)
optional_ptr< SegmentNode< RowGroup > > GetNextRowGroup (SegmentNode< RowGroup > &row_group)

Static Public Member Functions

static Value RetrieveStat (const BaseStatistics &stats, OrderByStatistics order_by, OrderByColumnType column_type)
static OffsetPruningResult GetOffsetAfterPruning (OrderByStatistics order_by, OrderByColumnType column_type, OrderType order_type, OrderByNullType null_order, const StorageIndex &column_idx, idx_t row_offset, vector< PartitionStatistics > &stats)

Private Attributes

const RowGroupOrderOptions options
idx_t offset
bool initialized
vector< reference< SegmentNode< RowGroup > > > ordered_row_groups

Constructor & Destructor Documentation

◆ RowGroupReorderer()

duckdb::RowGroupReorderer::RowGroupReorderer ( const RowGroupOrderOptions & options_p)
explicit
436708 : options(options_p), offset(0), initialized(false) {
436709}

Member Function Documentation

◆ GetRootSegment()

optional_ptr< SegmentNode< RowGroup > > duckdb::RowGroupReorderer::GetRootSegment ( RowGroupSegmentTree & row_groups)
436821 {
436822 if (initialized) {
436823 if (ordered_row_groups.empty()) {
436824 return nullptr;
436825 }
436826 return ordered_row_groups[0].get();
436827 }
436828
436829 initialized = true;
436830
436831 vector<reference<SegmentNode<RowGroup>>> null_only_groups;
436832 vector<reference<SegmentNode<RowGroup>>> ambiguous_groups;
436833 multimap<Value, RowGroupSegmentNodeEntry> row_group_map;
436834 for (auto &row_group : row_groups.SegmentNodes()) {
436835 auto stats = row_group.GetNode().GetStatistics(options.column_idx);
436836 if (IsNullOnly(*stats)) {
436837 null_only_groups.push_back(row_group);
436838 continue;
436839 }
436840 Value comparison_value = RetrieveStat(*stats, options.order_by, options.column_type);
436841 if (comparison_value.IsNull() || (options.null_order == OrderByNullType::NULLS_FIRST && stats->CanHaveNull())) {
436842 // No trustworthy ordering statistics, or the row group might still contribute NULLs that must be scanned
436843 // before definitely non-null groups with NULLS_FIRST.
436844 ambiguous_groups.push_back(row_group);
436845 continue;
436846 }
436847 auto entry = RowGroupSegmentNodeEntry {row_group, std::move(stats)};
436848 row_group_map.emplace(comparison_value, std::move(entry));
436849 }
436850
436851 if (options.null_order == OrderByNullType::NULLS_FIRST) {
436852 AppendRowGroups(null_only_groups, options.leading_null_group_offset, ordered_row_groups);
436853 AppendRowGroups(ambiguous_groups, 0, ordered_row_groups);
436854 SetRowGroupVector(row_group_map, options.row_limit, options.row_group_offset, options.order_type,
436855 options.column_type, ordered_row_groups);
436856 } else {
436857 SetRowGroupVector(row_group_map, options.row_limit, options.row_group_offset, options.order_type,
436858 options.column_type, ordered_row_groups);
436859 AppendRowGroups(ambiguous_groups, 0, ordered_row_groups);
436860 AppendRowGroups(null_only_groups, 0, ordered_row_groups);
436861 }
436862
436863 if (ordered_row_groups.empty()) {
436864 return nullptr;
436865 }
436866
436867 return ordered_row_groups[0].get();
436868}

◆ GetNextRowGroup()

optional_ptr< SegmentNode< RowGroup > > duckdb::RowGroupReorderer::GetNextRowGroup ( SegmentNode< RowGroup > & row_group)
436711 {
436712 D_ASSERT(RefersToSameObject(ordered_row_groups[offset].get(), row_group));
436713 if (offset >= ordered_row_groups.size() - 1) {
436714 return nullptr;
436715 }
436716 return ordered_row_groups[++offset].get();
436717}
__host__ cudaTextureObject_t get() const noexcept
bool RefersToSameObject(const reference< T > &a, const reference< T > &b)
Returns whether or not two reference wrappers refer to the same object.
Definition duckdb.hpp:2191

◆ RetrieveStat()

Value duckdb::RowGroupReorderer::RetrieveStat ( const BaseStatistics & stats,
OrderByStatistics order_by,
OrderByColumnType column_type )
static
436720 {
436721 if (column_type == OrderByColumnType::NUMERIC) {
436722 if (!NumericStats::HasMinMax(stats)) {
436723 return Value();
436724 }
436725 switch (order_by) {
436726 case OrderByStatistics::MIN:
436727 return NumericStats::Min(stats);
436728 case OrderByStatistics::MAX:
436729 return NumericStats::Max(stats);
436730 default:
436731 throw InternalException("Unsupported OrderByStatistics for numeric");
436732 }
436733 }
436734 if (column_type == OrderByColumnType::STRING) {
436735 if (!stats.CanHaveNoNull()) {
436736 // No non-null values exist in this row group - stats are meaningless for ordering
436737 return Value();
436738 }
436739 switch (order_by) {
436740 case OrderByStatistics::MIN:
436741 return Value::BLOB_RAW(StringStats::Min(stats));
436742 case OrderByStatistics::MAX:
436743 return Value::BLOB_RAW(StringStats::Max(stats));
436744 default:
436745 throw InternalException("Unsupported OrderByStatistics for string");
436746 }
436747 }
436748 throw InternalException("Unsupported OrderByColumnType");
436749}
static DUCKDB_API Value Min(const BaseStatistics &stats)
Returns the min value - throws an exception if there is no min value.
Definition duckdb.cpp:424256
static DUCKDB_API Value Max(const BaseStatistics &stats)
Returns the max value - throws an exception if there is no max value.
Definition duckdb.cpp:424263
static DUCKDB_API bool HasMinMax(const BaseStatistics &stats)
Returns true if the stats has both a min and max value defined.
Definition duckdb.cpp:424237
static DUCKDB_API string Max(const BaseStatistics &stats)
Returns the max value (up to a length of StringStatsData::MAX_STRING_MINMAX_SIZE).
Definition duckdb.cpp:424588
static DUCKDB_API string Min(const BaseStatistics &stats)
Returns the min value (up to a length of StringStatsData::MAX_STRING_MINMAX_SIZE).
Definition duckdb.cpp:424584

◆ GetOffsetAfterPruning()

OffsetPruningResult duckdb::RowGroupReorderer::GetOffsetAfterPruning ( OrderByStatistics order_by,
OrderByColumnType column_type,
OrderType order_type,
OrderByNullType null_order,
const StorageIndex & column_idx,
idx_t row_offset,
vector< PartitionStatistics > & stats )
static
436756 {
436757 multimap<Value, RowGroupOffsetEntry> ordered_row_groups;
436758 idx_t new_row_offset = row_offset;
436759 idx_t leading_null_group_offset = 0;
436760 bool encountered_maybe_null_group = false;
436761
436762 for (auto &partition_stats : stats) {
436763 if (partition_stats.count_type == CountType::COUNT_APPROXIMATE || !partition_stats.partition_row_group) {
436764 return {row_offset, 0, 0};
436765 }
436766
436767 auto column_stats = partition_stats.partition_row_group->GetColumnStatistics(storage_index);
436768 if (null_order == OrderByNullType::NULLS_FIRST && IsNullOnly(*column_stats)) {
436769 if (new_row_offset < partition_stats.count) {
436770 return {new_row_offset, 0, leading_null_group_offset};
436771 }
436772 new_row_offset -= partition_stats.count;
436773 leading_null_group_offset++;
436774 continue;
436775 }
436776 Value comparison_value = RetrieveStat(*column_stats, order_by, column_type);
436777 if (comparison_value.IsNull()) {
436778 if (null_order == OrderByNullType::NULLS_LAST && IsNullOnly(*column_stats)) {
436779 // With NULLS_LAST, null-stats row groups are scanned after all non-null row groups.
436780 // They fall outside the offset range being pruned here, so skip them.
436781 continue;
436782 }
436783 // The row group might still contribute ordered values, but we cannot position it safely.
436784 if (null_order == OrderByNullType::NULLS_FIRST) {
436785 encountered_maybe_null_group = true;
436786 continue;
436787 }
436788 return {new_row_offset, 0, leading_null_group_offset};
436789 }
436790 if (null_order == OrderByNullType::NULLS_FIRST && column_stats->CanHaveNull()) {
436791 // Groups that might contain NULLs are scanned before definitely non-null groups with NULLS_FIRST.
436792 // Without exact NULL counts, they block further offset pruning into the non-null region.
436793 encountered_maybe_null_group = true;
436794 continue;
436795 }
436796 auto entry = RowGroupOffsetEntry {partition_stats.count, std::move(column_stats)};
436797 ordered_row_groups.emplace(comparison_value, std::move(entry));
436798 }
436799 if (null_order == OrderByNullType::NULLS_FIRST && encountered_maybe_null_group) {
436800 return {new_row_offset, 0, leading_null_group_offset};
436801 }
436802
436803 switch (order_type) {
436804 case OrderType::ASCENDING: {
436805 auto result = FindOffsetPrunableChunks(ordered_row_groups.begin(), ordered_row_groups.end(), order_by,
436806 column_type, new_row_offset);
436807 result.leading_null_group_offset = leading_null_group_offset;
436808 return result;
436809 }
436810 case OrderType::DESCENDING: {
436811 auto result = FindOffsetPrunableChunks(ordered_row_groups.rbegin(), ordered_row_groups.rend(), order_by,
436812 column_type, new_row_offset);
436813 result.leading_null_group_offset = leading_null_group_offset;
436814 return result;
436815 }
436816 default:
436817 throw InternalException("Unsupported order type in GetOffsetAfterPruning");
436818 }
436819}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

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