164951 {
164952 D_ASSERT(
count > 0);
164953
164954
164955 AllocateMasks();
164956 const auto begin_entry =
partition_mask.EntryCount(block_begin * STANDARD_VECTOR_SIZE);
164957 const auto end_entry =
partition_mask.EntryCount(MinValue<idx_t>(block_end * STANDARD_VECTOR_SIZE,
count));
164958
164959
164960
164961 if (begin_entry >= end_entry) {
164962 return;
164963 }
164964
164966 if (!block_begin) {
164968 }
164970 order_mask.second.SetRangeInvalid(
count, begin_entry, end_entry);
164971 if (!block_begin) {
164972 order_mask.second.SetValidUnsafe(0);
164973 }
164974 }
164975
164976
164977 const auto &wexpr =
gsink.op.select_list[
gsink.op.order_idx]->Cast<BoundWindowExpression>();
164978 auto &partitions = wexpr.partitions;
164979 if (partitions.empty() && wexpr.orders.empty()) {
164980 return;
164981 }
164982
164983
164984 const auto key_count = partitions.size();
164985
164986
164988 auto &scan_cols =
gsink.sort_strategy->sort_ids;
164989 WindowCollectionChunkScanner scanner(
collection, scan_cols, block_begin);
164990 unordered_map<idx_t, DataChunk> prefixes;
164992 D_ASSERT(order_mask.first >= key_count);
164993 auto order_type = scanner.PrefixStructType(order_mask.first, key_count);
164994 vector<LogicalType> types(2, order_type);
164995 auto &keys = prefixes[order_mask.first];
164996
164997 keys.Initialize(
collection.GetAllocator(), types);
164998 }
164999
165000 WindowDeltaScanner(
collection, block_begin, block_end, scan_cols, key_count,
165001 [&](
const idx_t row_idx, DataChunk &prev, DataChunk &curr,
const idx_t ndistinct,
165002 SelectionVector &distinct, const SelectionVector &matching) {
165003
165004 for (
idx_t i = 0; i < ndistinct; ++i) {
165005 const idx_t curr_index = row_idx + distinct.get_index(i);
165008 order_mask.second.SetValidUnsafe(curr_index);
165009 }
165010 }
165011
165012
165013 const auto count = MinValue<idx_t>(prev.size(), curr.size());
165014 const auto nmatch =
count - ndistinct;
165015 if (!nmatch) {
165016 return;
165017 }
165018
165020
165021
165022 if (partitions.size() == order_mask.first) {
165023 continue;
165024 }
165025 auto &prefix = prefixes[order_mask.first];
165026 prefix.Reset();
165027 auto &order_prev = prefix.data[0];
165028 auto &order_curr = prefix.data[1];
165029 scanner.ReferenceStructColumns(prev, order_prev, order_mask.first, partitions.size());
165030 scanner.ReferenceStructColumns(curr, order_curr, order_mask.first, partitions.size());
165031 if (ndistinct) {
165032 prefix.Slice(matching, nmatch);
165033 } else {
165034 prefix.SetCardinality(nmatch);
165035 }
165036 const auto m = VectorOperations::DistinctFrom(order_curr, order_prev, nullptr, nmatch,
165037 &distinct, nullptr);
165038 for (
idx_t i = 0; i < m; ++i) {
165039 const idx_t curr_index = row_idx + matching.get_index(distinct.get_index(i));
165040 order_mask.second.SetValidUnsafe(curr_index);
165041 }
165042 }
165043 });
165044}
HashGroupPtr rows
The hash partition data.
Definition duckdb.cpp:164566
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237