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
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
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
319681 return make_uniq<RowGroupOrderOptions>(storage_index, order_by, order_type, null_order, column_type, combined_limit,
319682 NumericCast<uint64_t>(0));
319683}