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
436780
436781 continue;
436782 }
436783
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
436792
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