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

Public Member Functions

 TupleDataCollection (BufferManager &buffer_manager, shared_ptr< TupleDataLayout > layout_ptr, MemoryTag tag, shared_ptr< ArenaAllocator > stl_allocator=nullptr)
 Constructs a TupleDataCollection with the specified layout.
 TupleDataCollection (ClientContext &context, shared_ptr< TupleDataLayout > layout_ptr, MemoryTag tag, shared_ptr< ArenaAllocator > stl_allocator=nullptr)
unique_ptr< TupleDataCollection > CreateUnique () const
 Create a TupleDataCollection with the same layout.
shared_ptr< TupleDataLayout > GetLayoutPtr () const
 Get the layout (shared pointer) of the rows.
const TupleDataLayout & GetLayout () const
 The layout of the stored rows.
idx_t TuplesPerBlock () const
 How many tuples fit per block.
const idx_t & Count () const
 The number of rows stored in the tuple data collection.
idx_t ChunkCount () const
 The number of chunks stored in the tuple data collection.
idx_t SizeInBytes () const
 The size (in bytes) of the blocks held by this tuple data collection.
void Unpin ()
 Unpins all held pins.
void SetPartitionIndex (idx_t index)
 Sets the partition index of this tuple data collection.
vector< data_ptr_t > GetRowBlockPointers () const
 Gets the pointers to the start of every block.
void DestroyChunks (idx_t chunk_idx_begin, idx_t chunk_idx_end)
 Destroy the blocks corresponding to the chunk indices.
void InitializeAppend (TupleDataAppendState &append_state, TupleDataPinProperties properties=TupleDataPinProperties::UNPIN_AFTER_DONE)
 Initializes an Append state - useful for optimizing many appends made to the same tuple data collection.
void InitializeAppend (TupleDataAppendState &append_state, vector< column_t > column_ids, TupleDataPinProperties properties=TupleDataPinProperties::UNPIN_AFTER_DONE)
 Initializes an Append state - useful for optimizing many appends made to the same tuple data collection.
void InitializeAppend (TupleDataPinState &pin_state, TupleDataPinProperties=TupleDataPinProperties::UNPIN_AFTER_DONE)
void InitializeChunkState (TupleDataChunkState &chunk_state, vector< column_t > column_ids={})
void Append (DataChunk &new_chunk, const SelectionVector &append_sel= *FlatVector::IncrementalSelectionVector(), idx_t append_count=DConstants::INVALID_INDEX)
 Append a DataChunk directly to this TupleDataCollection - calls InitializeAppend and Append internally.
void Append (DataChunk &new_chunk, vector< column_t > column_ids, const SelectionVector &append_sel= *FlatVector::IncrementalSelectionVector(), const idx_t append_count=DConstants::INVALID_INDEX)
 Append a DataChunk directly to this TupleDataCollection - calls InitializeAppend and Append internally.
void Append (TupleDataAppendState &append_state, DataChunk &new_chunk, const SelectionVector &append_sel= *FlatVector::IncrementalSelectionVector(), const idx_t append_count=DConstants::INVALID_INDEX)
 Append a DataChunk to this TupleDataCollection using the specified Append state.
void Append (TupleDataPinState &pin_state, TupleDataChunkState &chunk_state, DataChunk &new_chunk, const SelectionVector &append_sel= *FlatVector::IncrementalSelectionVector(), const idx_t append_count=DConstants::INVALID_INDEX)
 Append a DataChunk to this TupleDataCollection using the specified pin and Chunk states.
void AppendUnified (TupleDataPinState &pin_state, TupleDataChunkState &chunk_state, DataChunk &new_chunk, const SelectionVector &append_sel= *FlatVector::IncrementalSelectionVector(), const idx_t append_count=DConstants::INVALID_INDEX)
void Build (TupleDataPinState &pin_state, TupleDataChunkState &chunk_state, const idx_t append_offset, const idx_t append_count)
 Builds out the buffer space for the specified Chunk state.
void Scatter (TupleDataChunkState &chunk_state, const DataChunk &new_chunk, const SelectionVector &append_sel, const idx_t append_count) const
 Scatters the given DataChunk to the rows in the specified Chunk state.
void Scatter (TupleDataChunkState &chunk_state, const Vector &source, const column_t column_id, const SelectionVector &append_sel, const idx_t append_count) const
 Scatters the given Vector to the given column id to the rows in the specified Chunk state.
void CopyRows (TupleDataChunkState &chunk_state, TupleDataChunkState &input, const SelectionVector &append_sel, const idx_t append_count) const
 Copy rows from input to the built Chunk state.
void FindHeapPointers (TupleDataChunkState &chunk_state, const idx_t chunk_count) const
 Finds the heap pointers of the rows in the given Chunk state.
void FinalizePinState (TupleDataPinState &pin_state, TupleDataSegment &segment)
 Finalizes the Pin state, releasing or storing blocks.
void FinalizePinState (TupleDataPinState &pin_state)
 Finalizes the Pin state, releasing or storing blocks.
void Combine (TupleDataCollection &other)
 Appends the other TupleDataCollection to this, destroying the other data collection.
void Combine (unique_ptr< TupleDataCollection > other)
 Appends the other TupleDataCollection to this, destroying the other data collection.
void Reset ()
 Resets the TupleDataCollection, clearing all data.
void InitializeChunk (DataChunk &chunk) const
 Initializes a chunk with the correct types that can be used to call Append/Scan.
void InitializeChunk (DataChunk &chunk, const vector< column_t > &columns) const
 Initializes a chunk with the correct types that can be used to call Append/Scan for the given columns.
void InitializeScanChunk (const TupleDataScanState &state, DataChunk &chunk) const
 Initializes a chunk with the correct types for a given scan state.
void InitializeScan (TupleDataScanState &state, TupleDataPinProperties properties=TupleDataPinProperties::UNPIN_AFTER_DONE) const
 Initializes a Scan state for scanning all columns.
void InitializeScan (TupleDataScanState &state, vector< column_t > column_ids, TupleDataPinProperties properties=TupleDataPinProperties::UNPIN_AFTER_DONE) const
 Initializes a Scan state for scanning a subset of the columns.
void InitializeScan (TupleDataParallelScanState &state, TupleDataPinProperties properties=TupleDataPinProperties::UNPIN_AFTER_DONE) const
 Initialize a parallel scan over the tuple data collection over all columns.
void InitializeScan (TupleDataParallelScanState &gstate, vector< column_t > column_ids, TupleDataPinProperties properties=TupleDataPinProperties::UNPIN_AFTER_DONE) const
 Initialize a parallel scan over the tuple data collection over a subset of the columns.
idx_t FetchChunk (TupleDataScanState &state, idx_t chunk_idx, bool init_heap, optional_ptr< SortKeyPayloadState > sort_key_payload_state=nullptr)
 Grab the chunk state for the given chunk index, returns the count of the chunk.
bool Scan (TupleDataScanState &state, DataChunk &result)
 Scans a DataChunk from the TupleDataCollection.
bool Scan (TupleDataParallelScanState &gstate, TupleDataLocalScanState &lstate, DataChunk &result)
 Scans a DataChunk from the TupleDataCollection.
bool ScanComplete (const TupleDataScanState &state) const
 Whether the last scan has been completed on this TupleDataCollection.
idx_t Seek (TupleDataScanState &state, const idx_t target_chunk)
 Seeks to the specified chunk index, returning the total row count before it.
void Gather (Vector &row_locations, const SelectionVector &scan_sel, const idx_t scan_count, DataChunk &result, const SelectionVector &target_sel, vector< unique_ptr< Vector > > &cached_cast_vectors) const
 Gathers a DataChunk from the TupleDataCollection, given the specific row locations (requires full pin).
void Gather (Vector &row_locations, const SelectionVector &scan_sel, const idx_t scan_count, const vector< column_t > &column_ids, DataChunk &result, const SelectionVector &target_sel, vector< unique_ptr< Vector > > &cached_cast_vectors) const
void Gather (Vector &row_locations, const SelectionVector &sel, const idx_t scan_count, const column_t column_id, Vector &result, const SelectionVector &target_sel, optional_ptr< Vector > cached_cast_vector) const
string ToString ()
 Converts this TupleDataCollection to a string representation.
void Print ()
 Prints the string representation of this TupleDataCollection.
void VerifyEverythingPinned () const
 Verify that all blocks are pinned.

Static Public Member Functions

static TupleDataScatterFunction GetScatterFunction (const LogicalType &type, bool within_collection=false)
 Gets the scatter function for the given type.
static TupleDataGatherFunction GetGatherFunction (const LogicalType &type)
 Gets the gather function for the given type.
static TupleDataScatterFunction GetSortKeyScatterFunction (const LogicalType &type, SortKeyType sort_key_type)
 Gets the scatter function for the given sort key type.
static TupleDataGatherFunction GetSortKeyGatherFunction (const LogicalType &type, SortKeyType sort_key_type)
 Gets the gather function for the given sort key type.
static void InitializeChunkState (TupleDataChunkState &chunk_state, const vector< LogicalType > &types, vector< column_t > column_ids={})
static void ToUnifiedFormat (TupleDataChunkState &chunk_state, DataChunk &new_chunk)
 Creates a UnifiedVectorFormat in the given Chunk state for the given DataChunk.
static void GetVectorData (const TupleDataChunkState &chunk_state, UnifiedVectorFormat result[])
 Gets the UnifiedVectorFormat from the Chunk state as an array.
static void ResetCachedCastVectors (TupleDataChunkState &chunk_state, const vector< column_t > &column_ids)
 Resets the cached cache vectors (used for ARRAY/LIST casts).
static void ComputeHeapSizes (TupleDataChunkState &chunk_state, const DataChunk &new_chunk, const SelectionVector &append_sel, const idx_t append_count)
 Computes the heap sizes for the new DataChunk that will be appended.
static void SortKeyComputeHeapSizes (TupleDataChunkState &chunk_state, const DataChunk &new_chunk, const SelectionVector &append_sel, const idx_t append_count, const SortKeyType sort_key_type)
 Computes the heap sizes for a SortKey layout.

Private Member Functions

void Initialize ()
 Initializes the TupleDataCollection (called by the constructor).
void GetAllColumnIDs (vector< column_t > &column_ids)
 Gets all column ids.
void AddSegment (unsafe_arena_ptr< TupleDataSegment > segment)
 Adds a segment to this TupleDataCollection.
bool NextScanIndex (TupleDataScanState &scan_state, idx_t &segment_index, idx_t &chunk_index)
 Get the next segment/chunk index for the scan.
void ScanAtIndex (TupleDataPinState &pin_state, TupleDataChunkState &chunk_state, const vector< column_t > &column_ids, idx_t segment_index, idx_t chunk_index, DataChunk &result)
 Scans the chunk at the given segment/chunk indices.
void Verify () const
 Verify count/data size of this collection.

Static Private Member Functions

static void ComputeHeapSizes (Vector &heap_sizes_v, const Vector &source_v, TupleDataVectorFormat &source, const SelectionVector &append_sel, const idx_t append_count)
 Computes the heap sizes for the specific Vector that will be appended.
static void WithinCollectionComputeHeapSizes (Vector &heap_sizes_v, const Vector &source_v, TupleDataVectorFormat &source_format, const SelectionVector &append_sel, const idx_t append_count, const UnifiedVectorFormat &list_data)
 Computes the heap sizes for the specific Vector that will be appended (within a list).
static void ComputeFixedWithinCollectionHeapSizes (Vector &heap_sizes_v, const Vector &source_v, TupleDataVectorFormat &source_format, const SelectionVector &append_sel, const idx_t append_count, const UnifiedVectorFormat &list_data)
 Computes the heap sizes for the fixed-size type Vector that will be appended (within a list).
static void StringWithinCollectionComputeHeapSizes (Vector &heap_sizes_v, const Vector &source_v, TupleDataVectorFormat &source_format, const SelectionVector &append_sel, const idx_t append_count, const UnifiedVectorFormat &list_data)
 Computes the heap sizes for the string Vector that will be appended (within a list).
static void StructWithinCollectionComputeHeapSizes (Vector &heap_sizes_v, const Vector &source_v, TupleDataVectorFormat &source_format, const SelectionVector &append_sel, const idx_t append_count, const UnifiedVectorFormat &list_data)
 Computes the heap sizes for the struct Vector that will be appended (within a list).
static void CollectionWithinCollectionComputeHeapSizes (Vector &heap_sizes_v, const Vector &source_v, TupleDataVectorFormat &source_format, const SelectionVector &append_sel, const idx_t append_count, const UnifiedVectorFormat &list_data)
 Computes the heap sizes for the list Vector that will be appended (within a list).

Private Attributes

TaskScheduler & scheduler
 Task scheduler for parallel destruction.
shared_ptr< ArenaAllocator > stl_allocator
 Shared allocator for STL allocations.
shared_ptr< TupleDataLayout > layout_ptr
 The layout of the TupleDataCollection.
const TupleDataLayout & layout
const MemoryTag tag
 Memory tag (for keeping track what the allocated memory belongs to).
shared_ptr< TupleDataAllocator > allocator
 The TupleDataAllocator.
idx_t count
 The number of entries stored in the TupleDataCollection.
idx_t data_size
 The size (in bytes) of this TupleDataCollection.
unsafe_arena_vector< unsafe_arena_ptr< TupleDataSegment > > segments
 The data segments of the TupleDataCollection.
unsafe_arena_vector< TupleDataScatterFunction > scatter_functions
 The set of scatter functions.
unsafe_arena_vector< TupleDataGatherFunction > gather_functions
 The set of gather functions.
optional_idx partition_index
 Partition index (optional, if partitioned).

Friends

class TupleDataChunkIterator
class PartitionedTupleData

Detailed Description

TupleDataCollection represents a set of buffer-managed data stored in row format FIXME: rename to RowDataCollection after we phase it out

Constructor & Destructor Documentation

◆ TupleDataCollection() [1/2]

duckdb::TupleDataCollection::TupleDataCollection ( BufferManager & buffer_manager,
shared_ptr< TupleDataLayout > layout_ptr,
MemoryTag tag,
shared_ptr< ArenaAllocator > stl_allocator = nullptr )

Constructs a TupleDataCollection with the specified layout.

125663 : scheduler(TaskScheduler::GetScheduler(buffer_manager.GetDatabase())),
125664 stl_allocator(stl_allocator_p ? std::move(stl_allocator_p)
125665 : make_shared_ptr<ArenaAllocator>(buffer_manager.GetBufferAllocator())),
125666 layout_ptr(std::move(layout_ptr_p)), layout(*layout_ptr), tag(tag_p),
125667 allocator(make_shared_ptr<TupleDataAllocator>(buffer_manager, layout_ptr, tag, stl_allocator)),
125669 Initialize();
125670}
shared_ptr< TupleDataLayout > layout_ptr
The layout of the TupleDataCollection.
Definition duckdb.cpp:56998
unsafe_arena_vector< TupleDataGatherFunction > gather_functions
The set of gather functions.
Definition duckdb.cpp:57013
shared_ptr< TupleDataAllocator > allocator
The TupleDataAllocator.
Definition duckdb.cpp:57003
const MemoryTag tag
Memory tag (for keeping track what the allocated memory belongs to).
Definition duckdb.cpp:57001
shared_ptr< ArenaAllocator > stl_allocator
Shared allocator for STL allocations.
Definition duckdb.cpp:56996
TaskScheduler & scheduler
Task scheduler for parallel destruction.
Definition duckdb.cpp:56994
unsafe_arena_vector< unsafe_arena_ptr< TupleDataSegment > > segments
The data segments of the TupleDataCollection.
Definition duckdb.cpp:57009
void Initialize()
Initializes the TupleDataCollection (called by the constructor).
Definition duckdb.cpp:125685
unsafe_arena_vector< TupleDataScatterFunction > scatter_functions
The set of scatter functions.
Definition duckdb.cpp:57011
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TupleDataCollection() [2/2]

duckdb::TupleDataCollection::TupleDataCollection ( ClientContext & context,
shared_ptr< TupleDataLayout > layout_ptr,
MemoryTag tag,
shared_ptr< ArenaAllocator > stl_allocator = nullptr )
125674 : TupleDataCollection(BufferManager::GetBufferManager(context), std::move(layout_ptr), tag,
125675 std::move(stl_allocator)) {
125676}
TupleDataCollection(BufferManager &buffer_manager, shared_ptr< TupleDataLayout > layout_ptr, MemoryTag tag, shared_ptr< ArenaAllocator > stl_allocator=nullptr)
Constructs a TupleDataCollection with the specified layout.
Definition duckdb.cpp:125661

◆ ~TupleDataCollection()

duckdb::TupleDataCollection::~TupleDataCollection ( )
125678 {
125679 static constexpr idx_t PARALLEL_DESTROY_THRESHOLD = 1048576;
125680 if (count > PARALLEL_DESTROY_THRESHOLD) {
125681 ParallelDestroyTask<decltype(segments)>::Schedule(scheduler, segments);
125682 }
125683}
idx_t count
The number of entries stored in the TupleDataCollection.
Definition duckdb.cpp:57005
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

Member Function Documentation

◆ CreateUnique()

unique_ptr< TupleDataCollection > duckdb::TupleDataCollection::CreateUnique ( ) const

Create a TupleDataCollection with the same layout.

125707 {
125708 return make_uniq<TupleDataCollection>(allocator->GetBufferManager(), layout_ptr, tag);
125709}

◆ GetLayoutPtr()

shared_ptr< TupleDataLayout > duckdb::TupleDataCollection::GetLayoutPtr ( ) const

Get the layout (shared pointer) of the rows.

125722 {
125723 return layout_ptr;
125724}

◆ GetLayout()

const TupleDataLayout & duckdb::TupleDataCollection::GetLayout ( ) const

The layout of the stored rows.

125726 {
125727 return layout;
125728}
Here is the caller graph for this function:

◆ TuplesPerBlock()

idx_t duckdb::TupleDataCollection::TuplesPerBlock ( ) const

How many tuples fit per block.

125730 {
125731 return allocator->GetBufferManager().GetBlockSize() / layout.GetRowWidth();
125732}
Here is the caller graph for this function:

◆ Count()

const idx_t & duckdb::TupleDataCollection::Count ( ) const

The number of rows stored in the tuple data collection.

125734 {
125735 return count;
125736}
Here is the caller graph for this function:

◆ ChunkCount()

idx_t duckdb::TupleDataCollection::ChunkCount ( ) const

The number of chunks stored in the tuple data collection.

125738 {
125739 idx_t total_chunk_count = 0;
125740 for (const auto &segment : segments) {
125741 total_chunk_count += segment->ChunkCount();
125742 }
125743 return total_chunk_count;
125744}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SizeInBytes()

idx_t duckdb::TupleDataCollection::SizeInBytes ( ) const

The size (in bytes) of the blocks held by this tuple data collection.

125746 {
125747 return data_size + stl_allocator->AllocationSize();
125748}
idx_t data_size
The size (in bytes) of this TupleDataCollection.
Definition duckdb.cpp:57007

◆ Unpin()

void duckdb::TupleDataCollection::Unpin ( )

Unpins all held pins.

125750 {
125751 for (auto &segment : segments) {
125752 segment->Unpin();
125753 }
125754}
Here is the call graph for this function:

◆ SetPartitionIndex()

void duckdb::TupleDataCollection::SetPartitionIndex ( idx_t index)

Sets the partition index of this tuple data collection.

125756 {
125757 D_ASSERT(!partition_index.IsValid());
125758 D_ASSERT(Count() == 0);
125760 allocator->SetPartitionIndex(index);
125761}
optional_idx partition_index
Partition index (optional, if partitioned).
Definition duckdb.cpp:57015
const idx_t & Count() const
The number of rows stored in the tuple data collection.
Definition duckdb.cpp:125734
index
Here is the call graph for this function:

◆ GetRowBlockPointers()

vector< data_ptr_t > duckdb::TupleDataCollection::GetRowBlockPointers ( ) const

Gets the pointers to the start of every block.

125763 {
125764 D_ASSERT(segments.size() == 1);
125765 const auto &segment = *segments[0];
125766 vector<data_ptr_t> result;
125767 result.reserve(segment.pinned_row_handles.size());
125768 for (const auto &pinned_row_handle : segment.pinned_row_handles) {
125769 result.emplace_back(pinned_row_handle.Ptr());
125770 }
125771 return result;
125772}

◆ DestroyChunks()

void duckdb::TupleDataCollection::DestroyChunks ( idx_t chunk_idx_begin,
idx_t chunk_idx_end )

Destroy the blocks corresponding to the chunk indices.

125774 {
125775 D_ASSERT(segments.size() == 1); // Assume 1 segment for now (multi-segment destroys can be implemented if needed)
125776 D_ASSERT(chunk_idx_begin <= chunk_idx_end && chunk_idx_end <= ChunkCount());
125777 auto &segment = *segments[0];
125778 auto &chunk_begin = *segment.chunks[chunk_idx_begin];
125779
125780 const auto row_block_begin = chunk_begin.row_block_ids.Start();
125781 if (chunk_idx_end == ChunkCount()) {
125782 segment.allocator->DestroyRowBlocks(row_block_begin, segment.allocator->RowBlockCount());
125783 } else {
125784 auto &chunk_end = *segment.chunks[chunk_idx_end];
125785 const auto row_block_end = chunk_end.row_block_ids.Start();
125786 segment.allocator->DestroyRowBlocks(row_block_begin, row_block_end);
125787 }
125788
125789 if (!layout.AllConstant()) {
125790 if (chunk_begin.heap_block_ids.Empty()) {
125791 return;
125792 }
125793 const auto heap_block_begin = chunk_begin.heap_block_ids.Start();
125794 if (chunk_idx_end == ChunkCount()) {
125795 segment.allocator->DestroyHeapBlocks(heap_block_begin, segment.allocator->HeapBlockCount());
125796 } else {
125797 auto &chunk_end = *segment.chunks[chunk_idx_end];
125798 if (chunk_end.heap_block_ids.Empty()) {
125799 return;
125800 }
125801 const auto heap_block_end = chunk_end.heap_block_ids.Start();
125802 segment.allocator->DestroyHeapBlocks(heap_block_begin, heap_block_end);
125803 }
125804 }
125805}
idx_t ChunkCount() const
The number of chunks stored in the tuple data collection.
Definition duckdb.cpp:125738
Here is the call graph for this function:

◆ GetScatterFunction()

TupleDataScatterFunction duckdb::TupleDataCollection::GetScatterFunction ( const LogicalType & type,
bool within_collection = false )
static

Gets the scatter function for the given type.

127967 {
127968 TupleDataScatterFunction result;
127969 switch (type.InternalType()) {
127970 case PhysicalType::BOOL:
127971 result.function = TupleDataGetScatterFunction<bool>(within_collection);
127972 break;
127973 case PhysicalType::INT8:
127974 result.function = TupleDataGetScatterFunction<int8_t>(within_collection);
127975 break;
127976 case PhysicalType::INT16:
127977 result.function = TupleDataGetScatterFunction<int16_t>(within_collection);
127978 break;
127979 case PhysicalType::INT32:
127980 result.function = TupleDataGetScatterFunction<int32_t>(within_collection);
127981 break;
127982 case PhysicalType::INT64:
127983 result.function = TupleDataGetScatterFunction<int64_t>(within_collection);
127984 break;
127985 case PhysicalType::INT128:
127986 result.function = TupleDataGetScatterFunction<hugeint_t>(within_collection);
127987 break;
127988 case PhysicalType::UINT8:
127989 result.function = TupleDataGetScatterFunction<uint8_t>(within_collection);
127990 break;
127992 result.function = TupleDataGetScatterFunction<uint16_t>(within_collection);
127993 break;
127995 result.function = TupleDataGetScatterFunction<uint32_t>(within_collection);
127996 break;
127998 result.function = TupleDataGetScatterFunction<uint64_t>(within_collection);
127999 break;
128000 case PhysicalType::UINT128:
128001 result.function = TupleDataGetScatterFunction<uhugeint_t>(within_collection);
128002 break;
128003 case PhysicalType::FLOAT:
128004 result.function = TupleDataGetScatterFunction<float>(within_collection);
128005 break;
128007 result.function = TupleDataGetScatterFunction<double>(within_collection);
128008 break;
128010 result.function = TupleDataGetScatterFunction<interval_t>(within_collection);
128011 break;
128013 result.function = TupleDataGetScatterFunction<string_t>(within_collection);
128014 break;
128015 case PhysicalType::STRUCT: {
128016 result.function = within_collection ? TupleDataStructWithinCollectionScatter : TupleDataStructScatter;
128017 for (const auto &child_type : StructType::GetChildTypes(type)) {
128018 result.child_functions.push_back(GetScatterFunction(child_type.second, within_collection));
128019 }
128020 break;
128021 }
128022 case PhysicalType::LIST:
128023 result.function =
128024 within_collection ? TupleDataCollectionWithinCollectionScatter<ListVector> : TupleDataListScatter;
128025 result.child_functions.emplace_back(GetScatterFunction(ListType::GetChildType(type), true));
128026 break;
128027 case PhysicalType::ARRAY:
128028 result.function =
128029 within_collection ? TupleDataCollectionWithinCollectionScatter<ArrayVector> : TupleDataArrayScatter;
128030 result.child_functions.emplace_back(GetScatterFunction(ArrayType::GetChildType(type), true));
128031 break;
128032 default:
128033 throw InternalException("Unsupported type for TupleDataCollection::GetScatterFunction");
128034 }
128035 return result;
128036}
static TupleDataScatterFunction GetScatterFunction(const LogicalType &type, bool within_collection=false)
Gets the scatter function for the given type.
Definition duckdb.cpp:127967
@ UINT32
Unsigned 32-bit little-endian integer.
Definition duckdb.hpp:2758
@ INTERVAL
YEAR_MONTH or DAY_TIME interval in SQL style.
Definition duckdb.hpp:2806
@ LIST
A list of some logical data type.
Definition duckdb.hpp:2813
@ UINT16
Unsigned 16-bit little-endian integer.
Definition duckdb.hpp:2752
@ INT64
Signed 64-bit little-endian integer.
Definition duckdb.hpp:2767
@ INT16
Signed 16-bit little-endian integer.
Definition duckdb.hpp:2755
@ INT32
Signed 32-bit little-endian integer.
Definition duckdb.hpp:2761
@ UINT64
Unsigned 64-bit little-endian integer.
Definition duckdb.hpp:2764
@ BOOL
Boolean as 8 bit "bool" value.
Definition duckdb.hpp:2743
@ STRUCT
Struct of logical types.
Definition duckdb.hpp:2816
@ VARCHAR
DuckDB Extensions.
Definition duckdb.hpp:2847
@ FLOAT
4-byte floating point value
Definition duckdb.hpp:2773
@ UINT8
Unsigned 8-bit little-endian integer.
Definition duckdb.hpp:2746
@ INT8
Signed 8-bit little-endian integer.
Definition duckdb.hpp:2749
@ DOUBLE
8-byte floating point value
Definition duckdb.hpp:2776
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetGatherFunction()

TupleDataGatherFunction duckdb::TupleDataCollection::GetGatherFunction ( const LogicalType & type)
static

Gets the gather function for the given type.

128642 {
128643 if (!type.IsNested()) {
128644 return TupleDataGetGatherFunctionInternal(type, false);
128645 }
128646
128647 if (TypeVisitor::Contains(type, LogicalTypeId::ARRAY)) {
128648 // Special case: we cant handle arrays yet, so we need to replace them with lists when gathering
128649 const auto new_type = ArrayType::ConvertToList(type);
128650 TupleDataGatherFunction result;
128651 // Theres only two cases: Either the array is within a struct, or it is within a list (or has now become a list)
128652 switch (new_type.InternalType()) {
128653 case PhysicalType::LIST:
128654 result.function = TupleDataCastToArrayListGather;
128655 result.child_functions.push_back(
128656 TupleDataGetGatherFunctionInternal(ListType::GetChildType(new_type), true));
128657 return result;
128659 result.function = TupleDataCastToArrayStructGather;
128660 for (const auto &child_type : StructType::GetChildTypes(new_type)) {
128661 result.child_functions.push_back(TupleDataGetGatherFunctionInternal(child_type.second, false));
128662 }
128663 return result;
128664 default:
128665 throw InternalException("Unsupported type for TupleDataCollection::GetGatherFunction");
128666 }
128667 }
128668 return TupleDataGetGatherFunctionInternal(type, false);
128669}
static DUCKDB_API LogicalType ConvertToList(const LogicalType &type)
Recursively replace all ARRAY types to LIST types within the given type.
Definition duckdb.cpp:140824
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetSortKeyScatterFunction()

TupleDataScatterFunction duckdb::TupleDataCollection::GetSortKeyScatterFunction ( const LogicalType & type,
SortKeyType sort_key_type )
static

Gets the scatter function for the given sort key type.

128076 {
128077 switch (type.id()) {
128078 case LogicalTypeId::BIGINT:
128079 return GetSortKeyScatterFunctionInternal<int64_t>(sort_key_type);
128080 case LogicalTypeId::BLOB:
128081 return GetSortKeyScatterFunctionInternal<string_t>(sort_key_type);
128082 default:
128083 throw NotImplementedException("TupleDataCollection::GetSortKeyScatterFunction for %s", type.ToString());
128084 }
128085}
Here is the caller graph for this function:

◆ GetSortKeyGatherFunction()

TupleDataGatherFunction duckdb::TupleDataCollection::GetSortKeyGatherFunction ( const LogicalType & type,
SortKeyType sort_key_type )
static

Gets the gather function for the given sort key type.

128709 {
128710 switch (type.id()) {
128711 case LogicalTypeId::BIGINT:
128712 return GetSortKeyGatherFunctionInternal<int64_t>(sort_key_type);
128713 case LogicalTypeId::BLOB:
128714 return GetSortKeyGatherFunctionInternal<string_t>(sort_key_type);
128715 default:
128716 throw NotImplementedException("TupleDataCollection::GetSortKeyGatherFunction for %s", type.ToString());
128717 }
128718}
Here is the caller graph for this function:

◆ InitializeAppend() [1/3]

void duckdb::TupleDataCollection::InitializeAppend ( TupleDataAppendState & append_state,
TupleDataPinProperties properties = TupleDataPinProperties::UNPIN_AFTER_DONE )

Initializes an Append state - useful for optimizing many appends made to the same tuple data collection.

125832 {
125833 vector<column_t> column_ids;
125834 GetAllColumnIDs(column_ids);
125835 InitializeAppend(append_state, std::move(column_ids), properties);
125836}
void InitializeAppend(TupleDataAppendState &append_state, TupleDataPinProperties properties=TupleDataPinProperties::UNPIN_AFTER_DONE)
Initializes an Append state - useful for optimizing many appends made to the same tuple data collecti...
Definition duckdb.cpp:125832
void GetAllColumnIDs(vector< column_t > &column_ids)
Gets all column ids.
Definition duckdb.cpp:125718
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeAppend() [2/3]

void duckdb::TupleDataCollection::InitializeAppend ( TupleDataAppendState & append_state,
vector< column_t > column_ids,
TupleDataPinProperties properties = TupleDataPinProperties::UNPIN_AFTER_DONE )

Initializes an Append state - useful for optimizing many appends made to the same tuple data collection.

125839 {
125840 VerifyAppendColumns(layout, column_ids);
125841 InitializeAppend(append_state.pin_state, properties);
125842 InitializeChunkState(append_state.chunk_state, std::move(column_ids));
125843}
void InitializeChunkState(TupleDataChunkState &chunk_state, vector< column_t > column_ids={})
Definition duckdb.cpp:125879
Here is the call graph for this function:

◆ InitializeAppend() [3/3]

void duckdb::TupleDataCollection::InitializeAppend ( TupleDataPinState & pin_state,
TupleDataPinProperties properties = TupleDataPinProperties::UNPIN_AFTER_DONE )

Initializes the Pin state of an Append state

  • Useful for optimizing many appends made to the same tuple data collection
125845 {
125846 pin_state.properties = properties;
125847 if (segments.empty()) {
125848 segments.emplace_back(stl_allocator->MakeUnsafePtr<TupleDataSegment>(allocator));
125849 }
125850}

◆ InitializeChunkState() [1/2]

void duckdb::TupleDataCollection::InitializeChunkState ( TupleDataChunkState & chunk_state,
vector< column_t > column_ids = {} )

Initializes the Chunk state of an Append state

  • Useful for optimizing many appends made to the same tuple data collection
125879 {
125880 TupleDataCollection::InitializeChunkState(chunk_state, layout.GetTypes(), std::move(column_ids));
125881}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeChunkState() [2/2]

void duckdb::TupleDataCollection::InitializeChunkState ( TupleDataChunkState & chunk_state,
const vector< LogicalType > & types,
vector< column_t > column_ids = {} )
static

Initializes the Chunk state of an Append state

  • Useful for optimizing many appends made to the same tuple data collection
125884 {
125885 if (column_ids.empty()) {
125886 GetAllColumnIDsInternal(column_ids, types.size());
125887 }
125888 InitializeVectorFormat(chunk_state.vector_data, types);
125889
125890 chunk_state.cached_cast_vectors.clear();
125891 chunk_state.cached_cast_vector_cache.clear();
125892 for (auto &col : column_ids) {
125893 auto &type = types[col];
125894 if (TypeVisitor::Contains(type, LogicalTypeId::ARRAY)) {
125895 auto cast_type = ArrayType::ConvertToList(type);
125896 chunk_state.cached_cast_vector_cache.push_back(
125897 make_uniq<VectorCache>(Allocator::DefaultAllocator(), cast_type));
125898 chunk_state.cached_cast_vectors.push_back(make_uniq<Vector>(*chunk_state.cached_cast_vector_cache.back()));
125899 } else {
125900 chunk_state.cached_cast_vectors.emplace_back();
125901 chunk_state.cached_cast_vector_cache.emplace_back();
125902 }
125903 }
125904
125905 chunk_state.column_ids = std::move(column_ids);
125906}
Here is the call graph for this function:

◆ Append() [1/4]

void duckdb::TupleDataCollection::Append ( DataChunk & new_chunk,
const SelectionVector & append_sel = *FlatVector::IncrementalSelectionVector(),
idx_t append_count = DConstants::INVALID_INDEX )

Append a DataChunk directly to this TupleDataCollection - calls InitializeAppend and Append internally.

125908 {
125909 TupleDataAppendState append_state;
125910 InitializeAppend(append_state);
125911 Append(append_state, new_chunk, append_sel, append_count);
125912}
void Append(DataChunk &new_chunk, const SelectionVector &append_sel= *FlatVector::IncrementalSelectionVector(), idx_t append_count=DConstants::INVALID_INDEX)
Append a DataChunk directly to this TupleDataCollection - calls InitializeAppend and Append internall...
Definition duckdb.cpp:125908
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Append() [2/4]

void duckdb::TupleDataCollection::Append ( DataChunk & new_chunk,
vector< column_t > column_ids,
const SelectionVector & append_sel = *FlatVector::IncrementalSelectionVector(),
const idx_t append_count = DConstants::INVALID_INDEX )

Append a DataChunk directly to this TupleDataCollection - calls InitializeAppend and Append internally.

125915 {
125916 TupleDataAppendState append_state;
125917 InitializeAppend(append_state, std::move(column_ids));
125918 Append(append_state, new_chunk, append_sel, append_count);
125919}
Here is the call graph for this function:

◆ Append() [3/4]

void duckdb::TupleDataCollection::Append ( TupleDataAppendState & append_state,
DataChunk & new_chunk,
const SelectionVector & append_sel = *FlatVector::IncrementalSelectionVector(),
const idx_t append_count = DConstants::INVALID_INDEX )

Append a DataChunk to this TupleDataCollection using the specified Append state.

125922 {
125923 Append(append_state.pin_state, append_state.chunk_state, new_chunk, append_sel, append_count);
125924}
Here is the call graph for this function:

◆ Append() [4/4]

void duckdb::TupleDataCollection::Append ( TupleDataPinState & pin_state,
TupleDataChunkState & chunk_state,
DataChunk & new_chunk,
const SelectionVector & append_sel = *FlatVector::IncrementalSelectionVector(),
const idx_t append_count = DConstants::INVALID_INDEX )

Append a DataChunk to this TupleDataCollection using the specified pin and Chunk states.

125927 {
125928 TupleDataCollection::ToUnifiedFormat(chunk_state, new_chunk);
125929 AppendUnified(pin_state, chunk_state, new_chunk, append_sel, append_count);
125930}
void AppendUnified(TupleDataPinState &pin_state, TupleDataChunkState &chunk_state, DataChunk &new_chunk, const SelectionVector &append_sel= *FlatVector::IncrementalSelectionVector(), const idx_t append_count=DConstants::INVALID_INDEX)
Definition duckdb.cpp:125932
static void ToUnifiedFormat(TupleDataChunkState &chunk_state, DataChunk &new_chunk)
Creates a UnifiedVectorFormat in the given Chunk state for the given DataChunk.
Definition duckdb.cpp:125999
Here is the call graph for this function:

◆ AppendUnified()

void duckdb::TupleDataCollection::AppendUnified ( TupleDataPinState & pin_state,
TupleDataChunkState & chunk_state,
DataChunk & new_chunk,
const SelectionVector & append_sel = *FlatVector::IncrementalSelectionVector(),
const idx_t append_count = DConstants::INVALID_INDEX )

Append a DataChunk to this TupleDataCollection using the specified pin and Chunk states

  • ToUnifiedFormat has already been called
125934 {
125935 const idx_t actual_append_count = append_count == DConstants::INVALID_INDEX ? new_chunk.size() : append_count;
125936 if (actual_append_count == 0) {
125937 return;
125938 }
125939
125940 if (!layout.AllConstant()) {
125941 if (layout.IsSortKeyLayout()) {
125942 TupleDataCollection::SortKeyComputeHeapSizes(chunk_state, new_chunk, append_sel, actual_append_count,
125943 layout.GetSortKeyType());
125944 } else {
125945 TupleDataCollection::ComputeHeapSizes(chunk_state, new_chunk, append_sel, actual_append_count);
125946 }
125947 }
125948
125949 Build(pin_state, chunk_state, 0, actual_append_count);
125950 Scatter(chunk_state, new_chunk, append_sel, actual_append_count);
125951}
void Build(TupleDataPinState &pin_state, TupleDataChunkState &chunk_state, const idx_t append_offset, const idx_t append_count)
Builds out the buffer space for the specified Chunk state.
Definition duckdb.cpp:126017
static void SortKeyComputeHeapSizes(TupleDataChunkState &chunk_state, const DataChunk &new_chunk, const SelectionVector &append_sel, const idx_t append_count, const SortKeyType sort_key_type)
Computes the heap sizes for a SortKey layout.
Definition duckdb.cpp:127011
static void ComputeHeapSizes(TupleDataChunkState &chunk_state, const DataChunk &new_chunk, const SelectionVector &append_sel, const idx_t append_count)
Computes the heap sizes for the new DataChunk that will be appended.
Definition duckdb.cpp:126857
void Scatter(TupleDataChunkState &chunk_state, const DataChunk &new_chunk, const SelectionVector &append_sel, const idx_t append_count) const
Scatters the given DataChunk to the rows in the specified Chunk state.
Definition duckdb.cpp:127402
static constexpr const idx_t INVALID_INDEX
The value used to signify an invalid index entry.
Definition duckdb.hpp:1117
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ToUnifiedFormat()

void duckdb::TupleDataCollection::ToUnifiedFormat ( TupleDataChunkState & chunk_state,
DataChunk & new_chunk )
static

Creates a UnifiedVectorFormat in the given Chunk state for the given DataChunk.

125999 {
126000 D_ASSERT(chunk_state.vector_data.size() >= chunk_state.column_ids.size()); // Needs InitializeAppend
126001 for (const auto &col_idx : chunk_state.column_ids) {
126002 ToUnifiedFormatInternal(chunk_state.vector_data[col_idx], new_chunk.data[col_idx], new_chunk.size());
126003 }
126004}
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445
Here is the caller graph for this function:

◆ GetVectorData()

void duckdb::TupleDataCollection::GetVectorData ( const TupleDataChunkState & chunk_state,
UnifiedVectorFormat result[] )
static

Gets the UnifiedVectorFormat from the Chunk state as an array.

126006 {
126007 const auto &vector_data = chunk_state.vector_data;
126008 for (idx_t i = 0; i < vector_data.size(); i++) {
126009 const auto &source = vector_data[i].unified;
126010 auto &target = result[i];
126011 target.sel = source.sel;
126012 target.data = source.data;
126013 target.validity = source.validity;
126014 }
126015}

◆ ResetCachedCastVectors()

void duckdb::TupleDataCollection::ResetCachedCastVectors ( TupleDataChunkState & chunk_state,
const vector< column_t > & column_ids )
static

Resets the cached cache vectors (used for ARRAY/LIST casts).

126370 {
126371 for (idx_t i = 0; i < column_ids.size(); i++) {
126372 if (chunk_state.cached_cast_vectors[i]) {
126373 chunk_state.cached_cast_vectors[i]->ResetFromCache(*chunk_state.cached_cast_vector_cache[i]);
126374 }
126375 }
126376}
Here is the caller graph for this function:

◆ ComputeHeapSizes() [1/2]

void duckdb::TupleDataCollection::ComputeHeapSizes ( TupleDataChunkState & chunk_state,
const DataChunk & new_chunk,
const SelectionVector & append_sel,
const idx_t append_count )
static

Computes the heap sizes for the new DataChunk that will be appended.

126858 {
126859 ResetCombinedListData(chunk_state.vector_data);
126860
126861 auto heap_sizes = FlatVector::GetData<idx_t>(chunk_state.heap_sizes);
126862 std::fill_n(heap_sizes, append_count, 0);
126863
126864 for (idx_t col_idx = 0; col_idx < new_chunk.ColumnCount(); col_idx++) {
126865 auto &source_v = new_chunk.data[col_idx];
126866 auto &source_format = chunk_state.vector_data[col_idx];
126867 ComputeHeapSizes(chunk_state.heap_sizes, source_v, source_format, append_sel, append_count);
126868 }
126869}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SortKeyComputeHeapSizes()

void duckdb::TupleDataCollection::SortKeyComputeHeapSizes ( TupleDataChunkState & chunk_state,
const DataChunk & new_chunk,
const SelectionVector & append_sel,
const idx_t append_count,
const SortKeyType sort_key_type )
static

Computes the heap sizes for a SortKey layout.

127013 {
127014 D_ASSERT(sort_key_type != SortKeyType::INVALID);
127015 D_ASSERT(!SortKeyUtils::IsConstantSize(sort_key_type));
127016 D_ASSERT(new_chunk.ColumnCount() == 1);
127017 if (new_chunk.data[0].GetType().id() != LogicalTypeId::BLOB) {
127018 return;
127019 }
127020
127021 const auto heap_sizes = FlatVector::GetData<idx_t>(chunk_state.heap_sizes);
127022
127023 const auto &source_vector_data = chunk_state.vector_data[0].unified;
127024 const auto &source_sel = *source_vector_data.sel;
127025 const auto &source_validity = source_vector_data.validity;
127026 const auto source_data = UnifiedVectorFormat::GetData<string_t>(source_vector_data);
127027
127028 const auto inlined_size = SortKeyUtils::GetInlineLength(sort_key_type);
127029 for (idx_t i = 0; i < append_count; i++) {
127030 const auto source_idx = source_sel.get_index(append_sel.get_index(i));
127031 const auto &string_size = source_data[source_idx].GetSize();
127032 // If valid, and string cannot be inlined, we need to allocate heap space
127033 heap_sizes[i] = (source_validity.RowIsValid(source_idx) & (string_size > inlined_size)) * string_size;
127034 }
127035}
Here is the caller graph for this function:

◆ Build()

void duckdb::TupleDataCollection::Build ( TupleDataPinState & pin_state,
TupleDataChunkState & chunk_state,
const idx_t append_offset,
const idx_t append_count )

Builds out the buffer space for the specified Chunk state.

126018 {
126019 auto &segment = *segments.back();
126020 const auto size_before = segment.SizeInBytes();
126021 segment.allocator->Build(segment, pin_state, chunk_state, append_offset, append_count);
126022 data_size += segment.SizeInBytes() - size_before;
126023 count += append_count;
126024 Verify();
126025}
void Verify() const
Verify count/data size of this collection.
Definition duckdb.cpp:126404
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Scatter() [1/2]

void duckdb::TupleDataCollection::Scatter ( TupleDataChunkState & chunk_state,
const DataChunk & new_chunk,
const SelectionVector & append_sel,
const idx_t append_count ) const

Scatters the given DataChunk to the rows in the specified Chunk state.

127403 {
127404#ifdef DEBUG
127405 Vector heap_locations_copy(LogicalType::POINTER);
127406 if (!layout.AllConstant()) {
127407 const auto heap_locations = FlatVector::GetData<data_ptr_t>(chunk_state.heap_locations);
127408 const auto copied_heap_locations = FlatVector::GetData<data_ptr_t>(heap_locations_copy);
127409 for (idx_t i = 0; i < append_count; i++) {
127410 copied_heap_locations[i] = heap_locations[i];
127411 }
127412 }
127413#endif
127414
127415 if (layout.IsSortKeyLayout()) {
127416 const auto &scatter_function = scatter_functions[0];
127417 scatter_function.function(new_chunk.data[0], chunk_state.vector_data[0], append_sel, append_count, layout,
127418 chunk_state.row_locations, chunk_state.heap_locations, 0,
127419 chunk_state.vector_data[0].unified, scatter_function.child_functions);
127420 } else {
127421 const auto row_locations = FlatVector::GetData<data_ptr_t>(chunk_state.row_locations);
127422
127423 // Set the validity mask for each row before inserting data
127424 if (!layout.AllValid()) {
127425 InitializeValidityMask(row_locations, append_count, ValidityBytes::SizeInBytes(layout.ColumnCount()));
127426 }
127427
127428 if (!layout.AllConstant()) {
127429 // Set the heap size for each row
127430 const auto heap_size_offset = layout.GetHeapSizeOffset();
127431 const auto heap_sizes = FlatVector::GetData<idx_t>(chunk_state.heap_sizes);
127432 for (idx_t i = 0; i < append_count; i++) {
127433 Store<idx_t>(heap_sizes[i], row_locations[i] + heap_size_offset);
127434 }
127435 }
127436
127437 // Write the data
127438 for (const auto &col_idx : chunk_state.column_ids) {
127439 Scatter(chunk_state, new_chunk.data[col_idx], col_idx, append_sel, append_count);
127440 }
127441 }
127442
127443#ifdef DEBUG
127444 // Verify that the size of the data written to the heap is the same as the size we computed it would be
127445 if (!layout.AllConstant()) {
127446 const auto original_heap_locations = FlatVector::GetData<data_ptr_t>(heap_locations_copy);
127447 const auto heap_sizes = FlatVector::GetData<idx_t>(chunk_state.heap_sizes);
127448 const auto offset_heap_locations = FlatVector::GetData<data_ptr_t>(chunk_state.heap_locations);
127449 for (idx_t i = 0; i < append_count; i++) {
127450 if (heap_sizes[i] != 0) {
127451 D_ASSERT(offset_heap_locations[i] == original_heap_locations[i] + heap_sizes[i]);
127452 }
127453 }
127454 }
127455#endif
127456}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Scatter() [2/2]

void duckdb::TupleDataCollection::Scatter ( TupleDataChunkState & chunk_state,
const Vector & source,
const column_t column_id,
const SelectionVector & append_sel,
const idx_t append_count ) const

Scatters the given Vector to the given column id to the rows in the specified Chunk state.

127459 {
127460 const auto &scatter_function = scatter_functions[column_id];
127461 scatter_function.function(source, chunk_state.vector_data[column_id], append_sel, append_count, layout,
127462 chunk_state.row_locations, chunk_state.heap_locations, column_id,
127463 chunk_state.vector_data[column_id].unified, scatter_function.child_functions);
127464}

◆ CopyRows()

void duckdb::TupleDataCollection::CopyRows ( TupleDataChunkState & chunk_state,
TupleDataChunkState & input,
const SelectionVector & append_sel,
const idx_t append_count ) const

Copy rows from input to the built Chunk state.

126041 {
126042 const auto source_locations = FlatVector::GetData<data_ptr_t>(input.row_locations);
126043 const auto target_locations = FlatVector::GetData<data_ptr_t>(chunk_state.row_locations);
126044
126045 // Copy rows
126046 const auto row_width = layout.GetRowWidth();
126047 if (append_sel.IsSet()) {
126048 for (idx_t i = 0; i < append_count; i++) {
126049 const auto idx = append_sel[i];
126050 FastMemcpy(target_locations[i], source_locations[idx], row_width);
126051 }
126052 } else {
126053 for (idx_t i = 0; i < append_count; i++) {
126054 FastMemcpy(target_locations[i], source_locations[i], row_width);
126055 }
126056 }
126057
126058 // Copy heap if we need to
126059 if (!layout.AllConstant()) {
126060 const auto source_heap_locations = FlatVector::GetData<data_ptr_t>(input.heap_locations);
126061 const auto target_heap_locations = FlatVector::GetData<data_ptr_t>(chunk_state.heap_locations);
126062 const auto heap_sizes = FlatVector::GetData<idx_t>(input.heap_sizes);
126063 VerifyHeapSizes(source_locations, heap_sizes, append_sel, append_count, layout.GetHeapSizeOffset());
126064
126065 // Check if we need to copy anything at all
126066 idx_t total_heap_size = 0;
126067 if (!append_sel.IsSet()) {
126068 // Fast path
126069 for (idx_t i = 0; i < append_count; i++) {
126070 total_heap_size += heap_sizes[i];
126071 }
126072 } else {
126073 for (idx_t i = 0; i < append_count; i++) {
126074 auto idx = append_sel.get_index(i);
126075 total_heap_size += heap_sizes[idx];
126076 }
126077 }
126078 if (total_heap_size == 0) {
126079 return;
126080 }
126081
126082 // Copy heap
126083 if (!append_sel.IsSet()) {
126084 // Fast path
126085 for (idx_t i = 0; i < append_count; i++) {
126086 FastMemcpy(target_heap_locations[i], source_heap_locations[i], heap_sizes[i]);
126087 }
126088 } else {
126089 for (idx_t i = 0; i < append_count; i++) {
126090 auto idx = append_sel.get_index(i);
126091 FastMemcpy(target_heap_locations[i], source_heap_locations[idx], heap_sizes[idx]);
126092 }
126093 }
126094
126095 // Recompute pointers after copying the data
126096 TupleDataAllocator::RecomputeHeapPointers(input.heap_locations, append_sel, target_locations,
126097 chunk_state.heap_locations, 0, append_count, layout, 0);
126098 }
126099}
void FastMemcpy(void *dest, const void *src, const size_t size)
Definition duckdb.cpp:35899
Here is the call graph for this function:

◆ FindHeapPointers()

void duckdb::TupleDataCollection::FindHeapPointers ( TupleDataChunkState & chunk_state,
const idx_t chunk_count ) const

Finds the heap pointers of the rows in the given Chunk state.

126101 {
126102 D_ASSERT(!layout.AllConstant());
126103 const auto row_locations = FlatVector::GetData<data_ptr_t>(chunk_state.row_locations);
126104 const auto heap_sizes = FlatVector::GetData<idx_t>(chunk_state.heap_sizes);
126105
126106 auto &not_found = chunk_state.utility;
126107 idx_t not_found_count = 0;
126108
126109 const auto &heap_size_offset = layout.GetHeapSizeOffset();
126110 for (idx_t i = 0; i < chunk_count; i++) {
126111 const auto &row_location = row_locations[i];
126112 auto &heap_size = heap_sizes[i];
126113
126114 heap_size = Load<idx_t>(row_location + heap_size_offset);
126115 if (heap_size != 0) {
126116 not_found.set_index(not_found_count++, i);
126117 }
126118 }
126119
126120 TupleDataAllocator::FindHeapPointers(chunk_state, not_found, not_found_count, layout, 0);
126121}

◆ FinalizePinState() [1/2]

void duckdb::TupleDataCollection::FinalizePinState ( TupleDataPinState & pin_state,
TupleDataSegment & segment )

Finalizes the Pin state, releasing or storing blocks.

126328 {
126329 segment.allocator->ReleaseOrStoreHandles(pin_state, segment);
126330}
Here is the caller graph for this function:

◆ FinalizePinState() [2/2]

void duckdb::TupleDataCollection::FinalizePinState ( TupleDataPinState & pin_state)

Finalizes the Pin state, releasing or storing blocks.

126332 {
126333 D_ASSERT(!segments.empty());
126334 FinalizePinState(pin_state, *segments.back());
126335}
void FinalizePinState(TupleDataPinState &pin_state, TupleDataSegment &segment)
Finalizes the Pin state, releasing or storing blocks.
Definition duckdb.cpp:126328
Here is the call graph for this function:

◆ Combine() [1/2]

void duckdb::TupleDataCollection::Combine ( TupleDataCollection & other)

Appends the other TupleDataCollection to this, destroying the other data collection.

126123 {
126124 if (other.count == 0) {
126125 return;
126126 }
126127 if (this->layout.GetTypes() != other.GetLayout().GetTypes()) {
126128 throw InternalException("Attempting to combine TupleDataCollection with mismatching types");
126129 }
126130 this->segments.reserve(this->segments.size() + other.segments.size());
126131 for (auto &other_seg : other.segments) {
126132 AddSegment(std::move(other_seg));
126133 }
126134 other.Reset();
126135}
void AddSegment(unsafe_arena_ptr< TupleDataSegment > segment)
Adds a segment to this TupleDataCollection.
Definition duckdb.cpp:126137
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Combine() [2/2]

void duckdb::TupleDataCollection::Combine ( unique_ptr< TupleDataCollection > other)

Appends the other TupleDataCollection to this, destroying the other data collection.

126144 {
126145 Combine(*other);
126146}
void Combine(TupleDataCollection &other)
Appends the other TupleDataCollection to this, destroying the other data collection.
Definition duckdb.cpp:126123
Here is the call graph for this function:

◆ Reset()

void duckdb::TupleDataCollection::Reset ( )

Resets the TupleDataCollection, clearing all data.

126148 {
126149 count = 0;
126150 data_size = 0;
126151 segments.clear();
126152
126153 // Refreshes the TupleDataAllocator to prevent holding on to allocated data unnecessarily
126154 allocator = make_shared_ptr<TupleDataAllocator>(*allocator);
126155}
Here is the caller graph for this function:

◆ InitializeChunk() [1/2]

void duckdb::TupleDataCollection::InitializeChunk ( DataChunk & chunk) const

Initializes a chunk with the correct types that can be used to call Append/Scan.

126157 {
126158 chunk.Initialize(allocator->GetAllocator(), layout.GetTypes());
126159}
DUCKDB_API void Initialize(ClientContext &context, const vector< LogicalType > &types, idx_t capacity=STANDARD_VECTOR_SIZE)
Definition duckdb.cpp:116791
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeChunk() [2/2]

void duckdb::TupleDataCollection::InitializeChunk ( DataChunk & chunk,
const vector< column_t > & columns ) const

Initializes a chunk with the correct types that can be used to call Append/Scan for the given columns.

126161 {
126162 vector<LogicalType> chunk_types(columns.size());
126163 // keep the order of the columns
126164 for (idx_t i = 0; i < columns.size(); i++) {
126165 auto column_idx = columns[i];
126166 D_ASSERT(column_idx < layout.ColumnCount());
126167 chunk_types[i] = layout.GetTypes()[column_idx];
126168 }
126169 chunk.Initialize(allocator->GetAllocator(), chunk_types);
126170}
Here is the call graph for this function:

◆ InitializeScanChunk()

void duckdb::TupleDataCollection::InitializeScanChunk ( const TupleDataScanState & state,
DataChunk & chunk ) const

Initializes a chunk with the correct types for a given scan state.

126172 {
126173 auto &column_ids = state.chunk_state.column_ids;
126174 D_ASSERT(!column_ids.empty());
126175 vector<LogicalType> chunk_types;
126176 chunk_types.reserve(column_ids.size());
126177 for (idx_t i = 0; i < column_ids.size(); i++) {
126178 auto column_idx = column_ids[i];
126179 D_ASSERT(column_idx < layout.ColumnCount());
126180 chunk_types.push_back(layout.GetTypes()[column_idx]);
126181 }
126182 chunk.Initialize(allocator->GetAllocator(), chunk_types);
126183}
Here is the call graph for this function:

◆ InitializeScan() [1/4]

void duckdb::TupleDataCollection::InitializeScan ( TupleDataScanState & state,
TupleDataPinProperties properties = TupleDataPinProperties::UNPIN_AFTER_DONE ) const

Initializes a Scan state for scanning all columns.

126185 {
126186 vector<column_t> column_ids;
126187 column_ids.reserve(layout.ColumnCount());
126188 for (idx_t i = 0; i < layout.ColumnCount(); i++) {
126189 column_ids.push_back(i);
126190 }
126191 InitializeScan(state, std::move(column_ids), properties);
126192}
void InitializeScan(TupleDataScanState &state, TupleDataPinProperties properties=TupleDataPinProperties::UNPIN_AFTER_DONE) const
Initializes a Scan state for scanning all columns.
Definition duckdb.cpp:126185
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeScan() [2/4]

void duckdb::TupleDataCollection::InitializeScan ( TupleDataScanState & state,
vector< column_t > column_ids,
TupleDataPinProperties properties = TupleDataPinProperties::UNPIN_AFTER_DONE ) const

Initializes a Scan state for scanning a subset of the columns.

126195 {
126196 state.pin_state.row_handles.clear();
126197 state.pin_state.heap_handles.clear();
126198 state.pin_state.properties = properties;
126199 state.segment_index = 0;
126200 state.chunk_index = 0;
126201
126202 auto &chunk_state = state.chunk_state;
126203
126204 for (auto &col : column_ids) {
126205 auto &type = layout.GetTypes()[col];
126206
126207 if (TypeVisitor::Contains(type, LogicalTypeId::ARRAY)) {
126208 auto cast_type = ArrayType::ConvertToList(type);
126209 chunk_state.cached_cast_vector_cache.push_back(
126210 make_uniq<VectorCache>(Allocator::DefaultAllocator(), cast_type));
126211 chunk_state.cached_cast_vectors.push_back(make_uniq<Vector>(*chunk_state.cached_cast_vector_cache.back()));
126212 } else {
126213 chunk_state.cached_cast_vectors.emplace_back();
126214 chunk_state.cached_cast_vector_cache.emplace_back();
126215 }
126216 }
126217
126218 state.chunk_state.column_ids = std::move(column_ids);
126219}
Here is the call graph for this function:

◆ InitializeScan() [3/4]

void duckdb::TupleDataCollection::InitializeScan ( TupleDataParallelScanState & state,
TupleDataPinProperties properties = TupleDataPinProperties::UNPIN_AFTER_DONE ) const

Initialize a parallel scan over the tuple data collection over all columns.

126221 {
126222 InitializeScan(gstate.scan_state, properties);
126223}
Here is the call graph for this function:

◆ InitializeScan() [4/4]

void duckdb::TupleDataCollection::InitializeScan ( TupleDataParallelScanState & gstate,
vector< column_t > column_ids,
TupleDataPinProperties properties = TupleDataPinProperties::UNPIN_AFTER_DONE ) const

Initialize a parallel scan over the tuple data collection over a subset of the columns.

126226 {
126227 InitializeScan(state.scan_state, std::move(column_ids), properties);
126228}
Here is the call graph for this function:

◆ FetchChunk()

idx_t duckdb::TupleDataCollection::FetchChunk ( TupleDataScanState & state,
idx_t chunk_idx,
bool init_heap,
optional_ptr< SortKeyPayloadState > sort_key_payload_state = nullptr )

Grab the chunk state for the given chunk index, returns the count of the chunk.

126231 {
126232 for (idx_t segment_idx = 0; segment_idx < segments.size(); segment_idx++) {
126233 auto &segment = *segments[segment_idx];
126234 if (chunk_idx < segment.ChunkCount()) {
126235 segment.allocator->InitializeChunkState(segment, state.pin_state, state.chunk_state, chunk_idx, init_heap,
126236 sort_key_payload_state);
126237 return segment.chunks[chunk_idx]->count;
126238 }
126239 chunk_idx -= segment.ChunkCount();
126240 }
126241 throw InternalException("Chunk index out of in TupleDataCollection::FetchChunk");
126242}
Here is the call graph for this function:

◆ Scan() [1/2]

bool duckdb::TupleDataCollection::Scan ( TupleDataScanState & state,
DataChunk & result )

Scans a DataChunk from the TupleDataCollection.

126244 {
126245 const auto segment_index_before = state.segment_index;
126246 idx_t segment_index;
126247 idx_t chunk_index;
126248 if (!NextScanIndex(state, segment_index, chunk_index)) {
126249 if (!segments.empty()) {
126250 FinalizePinState(state.pin_state, *segments[segment_index_before]);
126251 }
126252 result.SetCardinality(0);
126253 return false;
126254 }
126255 if (segment_index_before != DConstants::INVALID_INDEX && segment_index != segment_index_before) {
126256 FinalizePinState(state.pin_state, *segments[segment_index_before]);
126257 }
126258 ScanAtIndex(state.pin_state, state.chunk_state, state.chunk_state.column_ids, segment_index, chunk_index, result);
126259 return true;
126260}
bool NextScanIndex(TupleDataScanState &scan_state, idx_t &segment_index, idx_t &chunk_index)
Get the next segment/chunk index for the scan.
Definition duckdb.cpp:126337
void ScanAtIndex(TupleDataPinState &pin_state, TupleDataChunkState &chunk_state, const vector< column_t > &column_ids, idx_t segment_index, idx_t chunk_index, DataChunk &result)
Scans the chunk at the given segment/chunk indices.
Definition duckdb.cpp:126356
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Scan() [2/2]

bool duckdb::TupleDataCollection::Scan ( TupleDataParallelScanState & gstate,
TupleDataLocalScanState & lstate,
DataChunk & result )

Scans a DataChunk from the TupleDataCollection.

126262 {
126263 lstate.pin_state.properties = gstate.scan_state.pin_state.properties;
126264
126265 const auto segment_index_before = lstate.segment_index;
126266 {
126267 lock_guard<mutex> guard(gstate.lock);
126268 if (!NextScanIndex(gstate.scan_state, lstate.segment_index, lstate.chunk_index)) {
126269 if (!segments.empty()) {
126270 FinalizePinState(lstate.pin_state, *segments[segment_index_before]);
126271 }
126272 result.SetCardinality(0);
126273 return false;
126274 }
126275 }
126276 if (segment_index_before != DConstants::INVALID_INDEX && segment_index_before != lstate.segment_index) {
126277 FinalizePinState(lstate.pin_state, *segments[lstate.segment_index]);
126278 }
126279 ScanAtIndex(lstate.pin_state, lstate.chunk_state, gstate.scan_state.chunk_state.column_ids, lstate.segment_index,
126280 lstate.chunk_index, result);
126281 return true;
126282}
Here is the call graph for this function:

◆ ScanComplete()

bool duckdb::TupleDataCollection::ScanComplete ( const TupleDataScanState & state) const

Whether the last scan has been completed on this TupleDataCollection.

126321 {
126322 if (Count() == 0) {
126323 return true;
126324 }
126325 return state.segment_index == segments.size() - 1 && state.chunk_index == segments.back()->ChunkCount();
126326}
Here is the call graph for this function:

◆ Seek()

idx_t duckdb::TupleDataCollection::Seek ( TupleDataScanState & state,
const idx_t target_chunk )

Seeks to the specified chunk index, returning the total row count before it.

126284 {
126285 D_ASSERT(state.pin_state.properties == TupleDataPinProperties::UNPIN_AFTER_DONE);
126286 state.pin_state.row_handles.clear();
126287 state.pin_state.heap_handles.clear();
126288
126289 // early return for empty collection
126290 if (segments.empty()) {
126291 return 0;
126292 }
126293
126294 idx_t current_chunk = 0;
126295 idx_t total_rows = 0;
126296 for (idx_t seg_idx = 0; seg_idx < segments.size(); seg_idx++) {
126297 auto &segment = segments[seg_idx];
126298 idx_t chunk_count = segment->ChunkCount();
126299
126300 if (current_chunk + chunk_count <= target_chunk) {
126301 total_rows += segment->count;
126302 current_chunk += chunk_count;
126303 } else {
126304 idx_t chunk_idx_in_segment = target_chunk - current_chunk;
126305 for (idx_t chunk_idx = 0; chunk_idx < chunk_idx_in_segment; chunk_idx++) {
126306 total_rows += segment->chunks[chunk_idx]->count;
126307 }
126308 current_chunk += chunk_count;
126309
126310 // reset scan state to target segment
126311 state.segment_index = seg_idx;
126312 state.chunk_index = chunk_idx_in_segment;
126313 break;
126314 }
126315 }
126316
126317 D_ASSERT(target_chunk < current_chunk);
126318 return total_rows;
126319}
@ UNPIN_AFTER_DONE
Unpins blocks after they are done (for both reading/writing).
Definition duckdb.cpp:56601
Here is the call graph for this function:

◆ Gather() [1/3]

void duckdb::TupleDataCollection::Gather ( Vector & row_locations,
const SelectionVector & scan_sel,
const idx_t scan_count,
DataChunk & result,
const SelectionVector & target_sel,
vector< unique_ptr< Vector > > & cached_cast_vectors ) const

Gathers a DataChunk from the TupleDataCollection, given the specific row locations (requires full pin).

128092 {
128093 D_ASSERT(result.ColumnCount() == layout.ColumnCount());
128094 vector<column_t> column_ids;
128095 column_ids.reserve(layout.ColumnCount());
128096 for (idx_t col_idx = 0; col_idx < layout.ColumnCount(); col_idx++) {
128097 column_ids.emplace_back(col_idx);
128098 }
128099 Gather(row_locations, scan_sel, scan_count, column_ids, result, target_sel, cached_cast_vectors);
128100}
void Gather(Vector &row_locations, const SelectionVector &scan_sel, const idx_t scan_count, DataChunk &result, const SelectionVector &target_sel, vector< unique_ptr< Vector > > &cached_cast_vectors) const
Gathers a DataChunk from the TupleDataCollection, given the specific row locations (requires full pin...
Definition duckdb.cpp:128090
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Gather() [2/3]

void duckdb::TupleDataCollection::Gather ( Vector & row_locations,
const SelectionVector & scan_sel,
const idx_t scan_count,
const vector< column_t > & column_ids,
DataChunk & result,
const SelectionVector & target_sel,
vector< unique_ptr< Vector > > & cached_cast_vectors ) const

Gathers a DataChunk (only the columns given by column_ids) from the TupleDataCollection, given the specific row locations (requires full pin)

128105 {
128106 for (idx_t col_idx = 0; col_idx < column_ids.size(); col_idx++) {
128107 Gather(row_locations, scan_sel, scan_count, column_ids[col_idx], result.data[col_idx], target_sel,
128108 cached_cast_vectors[col_idx].get());
128109 }
128110}
Here is the call graph for this function:

◆ Gather() [3/3]

void duckdb::TupleDataCollection::Gather ( Vector & row_locations,
const SelectionVector & sel,
const idx_t scan_count,
const column_t column_id,
Vector & result,
const SelectionVector & target_sel,
optional_ptr< Vector > cached_cast_vector ) const

Gathers a Vector (from the given column id) from the TupleDataCollection given the specific row locations (requires full pin)

128114 {
128115 D_ASSERT(!cached_cast_vector || FlatVector::Validity(*cached_cast_vector).AllValid()); // ResetCachedCastVectors
128116 const auto &gather_function = gather_functions[column_id];
128117 gather_function.function(layout, row_locations, column_id, scan_sel, scan_count, result, target_sel,
128118 cached_cast_vector, gather_function.child_functions);
128119 Vector::Verify(result, target_sel, scan_count);
128120}
DUCKDB_API void Verify(idx_t count)
Definition duckdb.cpp:137589
Here is the call graph for this function:

◆ ToString()

string duckdb::TupleDataCollection::ToString ( )

Converts this TupleDataCollection to a string representation.

126379 {
126380 DataChunk chunk;
126381 InitializeChunk(chunk);
126382
126383 TupleDataScanState scan_state;
126384 InitializeScan(scan_state);
126385
126386 string result = StringUtil::Format("TupleDataCollection - [%llu Chunks, %llu Rows]\n", ChunkCount(), Count());
126387 idx_t chunk_idx = 0;
126388 idx_t row_count = 0;
126389 while (Scan(scan_state, chunk)) {
126390 result +=
126391 StringUtil::Format("Chunk %llu - [Rows %llu - %llu]\n", chunk_idx, row_count, row_count + chunk.size()) +
126392 chunk.ToString();
126393 chunk_idx++;
126394 row_count += chunk.size();
126395 }
126396
126397 return result;
126398}
DUCKDB_API string ToString() const
Converts this DataChunk to a printable string representation.
Definition duckdb.cpp:117003
static string Format(const string fmt_str, ARGS... params)
Format a string using printf semantics.
Definition duckdb.hpp:4002
void InitializeChunk(DataChunk &chunk) const
Initializes a chunk with the correct types that can be used to call Append/Scan.
Definition duckdb.cpp:126157
bool Scan(TupleDataScanState &state, DataChunk &result)
Scans a DataChunk from the TupleDataCollection.
Definition duckdb.cpp:126244
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Print()

void duckdb::TupleDataCollection::Print ( )

Prints the string representation of this TupleDataCollection.

126400 {
126402}
static DUCKDB_API void Print(OutputStream stream, const string &str)
Print the object to the stream.
Definition duckdb.cpp:92556
string ToString()
Converts this TupleDataCollection to a string representation.
Definition duckdb.cpp:126379
Here is the call graph for this function:

◆ VerifyEverythingPinned()

void duckdb::TupleDataCollection::VerifyEverythingPinned ( ) const

Verify that all blocks are pinned.

126418 {
126419#ifdef D_ASSERT_IS_ENABLED
126420 for (const auto &segment : segments) {
126421 segment->VerifyEverythingPinned();
126422 }
126423#endif
126424}
Here is the call graph for this function:

◆ Initialize()

void duckdb::TupleDataCollection::Initialize ( )
private

Initializes the TupleDataCollection (called by the constructor).

125685 {
125686 D_ASSERT(!layout.GetTypes().empty());
125687 if (TuplesPerBlock() == 0) {
125688 throw NotImplementedException("Too many columns: tuple width exceeds block size of %llu",
125689 allocator->GetBufferManager().GetBlockSize());
125690 }
125691 this->count = 0;
125692 this->data_size = 0;
125693 if (layout.IsSortKeyLayout()) {
125694 scatter_functions.emplace_back(GetSortKeyScatterFunction(layout.GetTypes()[0], layout.GetSortKeyType()));
125695 gather_functions.emplace_back(GetSortKeyGatherFunction(layout.GetTypes()[0], layout.GetSortKeyType()));
125696 } else {
125697 scatter_functions.reserve(layout.ColumnCount());
125698 gather_functions.reserve(layout.ColumnCount());
125699 for (idx_t col_idx = 0; col_idx < layout.ColumnCount(); col_idx++) {
125700 auto &type = layout.GetTypes()[col_idx];
125701 scatter_functions.emplace_back(GetScatterFunction(type));
125702 gather_functions.emplace_back(GetGatherFunction(type));
125703 }
125704 }
125705}
static TupleDataGatherFunction GetSortKeyGatherFunction(const LogicalType &type, SortKeyType sort_key_type)
Gets the gather function for the given sort key type.
Definition duckdb.cpp:128708
static TupleDataScatterFunction GetSortKeyScatterFunction(const LogicalType &type, SortKeyType sort_key_type)
Gets the scatter function for the given sort key type.
Definition duckdb.cpp:128075
static TupleDataGatherFunction GetGatherFunction(const LogicalType &type)
Gets the gather function for the given type.
Definition duckdb.cpp:128642
idx_t TuplesPerBlock() const
How many tuples fit per block.
Definition duckdb.cpp:125730
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetAllColumnIDs()

void duckdb::TupleDataCollection::GetAllColumnIDs ( vector< column_t > & column_ids)
private

Gets all column ids.

125718 {
125719 GetAllColumnIDsInternal(column_ids, layout.ColumnCount());
125720}
Here is the caller graph for this function:

◆ AddSegment()

void duckdb::TupleDataCollection::AddSegment ( unsafe_arena_ptr< TupleDataSegment > segment)
private

Adds a segment to this TupleDataCollection.

126137 {
126138 count += segment->count;
126139 data_size += segment->data_size;
126140 segments.emplace_back(std::move(segment));
126141 Verify();
126142}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ComputeHeapSizes() [2/2]

void duckdb::TupleDataCollection::ComputeHeapSizes ( Vector & heap_sizes_v,
const Vector & source_v,
TupleDataVectorFormat & source,
const SelectionVector & append_sel,
const idx_t append_count )
staticprivate

Computes the heap sizes for the specific Vector that will be appended.

126902 {
126903 const auto type = source_v.GetType().InternalType();
126904 if (type != PhysicalType::VARCHAR && type != PhysicalType::STRUCT && type != PhysicalType::LIST &&
126905 type != PhysicalType::ARRAY) {
126906 return;
126907 }
126908
126909 const auto heap_sizes = FlatVector::GetData<idx_t>(heap_sizes_v);
126910
126911 // Source
126912 const auto &source_vector_data = source_format.unified;
126913 const auto &source_sel = *source_vector_data.sel;
126914 const auto &source_validity = source_vector_data.validity;
126915
126916 switch (type) {
126917 case PhysicalType::VARCHAR: {
126918 // Only non-inlined strings are stored in the heap
126919#ifdef DUCKDB_SMALLER_BINARY
126920 ComputeStringHeapSizesInternal(heap_sizes, source_vector_data, append_sel, append_count);
126921#else
126922 if (source_validity.AllValid()) {
126923 if (append_sel.IsSet()) {
126924 if (source_sel.IsSet()) {
126925 ComputeStringHeapSizesInternal<true, true, true>(heap_sizes, source_vector_data, append_sel,
126926 append_count);
126927 } else {
126928 ComputeStringHeapSizesInternal<true, true, false>(heap_sizes, source_vector_data, append_sel,
126929 append_count);
126930 }
126931 } else {
126932 if (source_sel.IsSet()) {
126933 ComputeStringHeapSizesInternal<true, false, true>(heap_sizes, source_vector_data, append_sel,
126934 append_count);
126935 } else {
126936 ComputeStringHeapSizesInternal<true, false, false>(heap_sizes, source_vector_data, append_sel,
126937 append_count);
126938 }
126939 }
126940 } else {
126941 if (append_sel.IsSet()) {
126942 if (source_sel.IsSet()) {
126943 ComputeStringHeapSizesInternal<false, true, true>(heap_sizes, source_vector_data, append_sel,
126944 append_count);
126945 } else {
126946 ComputeStringHeapSizesInternal<false, true, false>(heap_sizes, source_vector_data, append_sel,
126947 append_count);
126948 }
126949 } else {
126950 if (source_sel.IsSet()) {
126951 ComputeStringHeapSizesInternal<false, false, true>(heap_sizes, source_vector_data, append_sel,
126952 append_count);
126953 } else {
126954 ComputeStringHeapSizesInternal<false, false, false>(heap_sizes, source_vector_data, append_sel,
126955 append_count);
126956 }
126957 }
126958 }
126959#endif
126960 break;
126961 }
126962 case PhysicalType::STRUCT: {
126963 // Recurse through the struct children
126964 auto &struct_sources = StructVector::GetEntries(source_v);
126965 for (idx_t struct_col_idx = 0; struct_col_idx < struct_sources.size(); struct_col_idx++) {
126966 const auto &struct_source = struct_sources[struct_col_idx];
126967 auto &struct_format = source_format.children[struct_col_idx];
126968 ComputeHeapSizes(heap_sizes_v, *struct_source, struct_format, append_sel, append_count);
126969 }
126970 break;
126971 }
126972 case PhysicalType::LIST: {
126973 // Lists are stored entirely in the heap
126974 for (idx_t i = 0; i < append_count; i++) {
126975 auto source_idx = source_sel.get_index(append_sel.get_index(i));
126976 if (source_validity.RowIsValid(source_idx)) {
126977 heap_sizes[i] += sizeof(uint64_t); // Size of the list
126978 }
126979 }
126980
126981 // Recurse
126982 D_ASSERT(source_format.children.size() == 1);
126983 auto &child_source_v = ListVector::GetEntry(source_v);
126984 auto &child_format = source_format.children[0];
126985 WithinCollectionComputeHeapSizes(heap_sizes_v, child_source_v, child_format, append_sel, append_count,
126986 source_vector_data);
126987 break;
126988 }
126989 case PhysicalType::ARRAY: {
126990 // Arrays are stored entirely in the heap
126991 for (idx_t i = 0; i < append_count; i++) {
126992 auto source_idx = source_sel.get_index(append_sel.get_index(i));
126993 if (source_validity.RowIsValid(source_idx)) {
126994 heap_sizes[i] += sizeof(uint64_t); // Size of the list
126995 }
126996 }
126997
126998 // Recurse
126999 D_ASSERT(source_format.children.size() == 1);
127000 auto &child_source_v = ArrayVector::GetEntry(source_v);
127001 auto &child_format = source_format.children[0];
127002 WithinCollectionComputeHeapSizes(heap_sizes_v, child_source_v, child_format, append_sel, append_count,
127003 source_vector_data);
127004 break;
127005 }
127006 default:
127007 throw NotImplementedException("ComputeHeapSizes for %s", EnumUtil::ToString(source_v.GetType().id()));
127008 }
127009}
static void WithinCollectionComputeHeapSizes(Vector &heap_sizes_v, const Vector &source_v, TupleDataVectorFormat &source_format, const SelectionVector &append_sel, const idx_t append_count, const UnifiedVectorFormat &list_data)
Computes the heap sizes for the specific Vector that will be appended (within a list).
Definition duckdb.cpp:127037
::uint64_t uint64_t
static DUCKDB_API const Vector & GetEntry(const Vector &vector)
Gets a reference to the underlying child-vector of an array.
Definition duckdb.cpp:138574
static DUCKDB_API const Vector & GetEntry(const Vector &vector)
Gets a reference to the underlying child-vector of a list.
Definition duckdb.cpp:138203
Here is the call graph for this function:

◆ WithinCollectionComputeHeapSizes()

void duckdb::TupleDataCollection::WithinCollectionComputeHeapSizes ( Vector & heap_sizes_v,
const Vector & source_v,
TupleDataVectorFormat & source_format,
const SelectionVector & append_sel,
const idx_t append_count,
const UnifiedVectorFormat & list_data )
staticprivate

Computes the heap sizes for the specific Vector that will be appended (within a list).

127040 {
127041 auto type = source_v.GetType().InternalType();
127042 if (TypeIsConstantSize(type)) {
127043 ComputeFixedWithinCollectionHeapSizes(heap_sizes_v, source_v, source_format, append_sel, append_count,
127044 list_data);
127045 return;
127046 }
127047 switch (type) {
127049 StringWithinCollectionComputeHeapSizes(heap_sizes_v, source_v, source_format, append_sel, append_count,
127050 list_data);
127051 break;
127053 StructWithinCollectionComputeHeapSizes(heap_sizes_v, source_v, source_format, append_sel, append_count,
127054 list_data);
127055 break;
127056 case PhysicalType::LIST:
127057 CollectionWithinCollectionComputeHeapSizes(heap_sizes_v, source_v, source_format, append_sel, append_count,
127058 list_data);
127059 break;
127060 case PhysicalType::ARRAY:
127061 CollectionWithinCollectionComputeHeapSizes(heap_sizes_v, source_v, source_format, append_sel, append_count,
127062 list_data);
127063 break;
127064 default:
127065 throw NotImplementedException("WithinListHeapComputeSizes for %s", EnumUtil::ToString(source_v.GetType().id()));
127066 }
127067}
static void StructWithinCollectionComputeHeapSizes(Vector &heap_sizes_v, const Vector &source_v, TupleDataVectorFormat &source_format, const SelectionVector &append_sel, const idx_t append_count, const UnifiedVectorFormat &list_data)
Computes the heap sizes for the struct Vector that will be appended (within a list).
Definition duckdb.cpp:127151
static void StringWithinCollectionComputeHeapSizes(Vector &heap_sizes_v, const Vector &source_v, TupleDataVectorFormat &source_format, const SelectionVector &append_sel, const idx_t append_count, const UnifiedVectorFormat &list_data)
Computes the heap sizes for the string Vector that will be appended (within a list).
Definition duckdb.cpp:127103
static void ComputeFixedWithinCollectionHeapSizes(Vector &heap_sizes_v, const Vector &source_v, TupleDataVectorFormat &source_format, const SelectionVector &append_sel, const idx_t append_count, const UnifiedVectorFormat &list_data)
Computes the heap sizes for the fixed-size type Vector that will be appended (within a list).
Definition duckdb.cpp:127069
static void CollectionWithinCollectionComputeHeapSizes(Vector &heap_sizes_v, const Vector &source_v, TupleDataVectorFormat &source_format, const SelectionVector &append_sel, const idx_t append_count, const UnifiedVectorFormat &list_data)
Computes the heap sizes for the list Vector that will be appended (within a list).
Definition duckdb.cpp:127217
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ComputeFixedWithinCollectionHeapSizes()

void duckdb::TupleDataCollection::ComputeFixedWithinCollectionHeapSizes ( Vector & heap_sizes_v,
const Vector & source_v,
TupleDataVectorFormat & source_format,
const SelectionVector & append_sel,
const idx_t append_count,
const UnifiedVectorFormat & list_data )
staticprivate

Computes the heap sizes for the fixed-size type Vector that will be appended (within a list).

127073 {
127074 // Parent list data
127075 const auto list_sel = *list_data.sel;
127076 const auto list_entries = UnifiedVectorFormat::GetDataUnsafe<list_entry_t>(list_data);
127077 const auto &list_validity = list_data.validity;
127078
127079 // Target
127080 auto heap_sizes = FlatVector::GetData<idx_t>(heap_sizes_v);
127081
127082 D_ASSERT(TypeIsConstantSize(source_v.GetType().InternalType()));
127083 const auto type_size = GetTypeIdSize(source_v.GetType().InternalType());
127084 for (idx_t i = 0; i < append_count; i++) {
127085 const auto list_idx = list_sel.get_index(append_sel.get_index(i));
127086 if (!list_validity.RowIsValid(list_idx)) {
127087 continue; // Original list entry is invalid - no need to serialize the child
127088 }
127089
127090 // Get the current list length
127091 const auto &list_length = list_entries[list_idx].length;
127092 if (list_length == 0) {
127093 continue;
127094 }
127095
127096 // Size is validity mask and all values
127097 auto &heap_size = heap_sizes[i];
127098 heap_size += ValidityBytes::SizeInBytes(list_length);
127099 heap_size += list_length * type_size;
127100 }
127101}
Here is the caller graph for this function:

◆ StringWithinCollectionComputeHeapSizes()

void duckdb::TupleDataCollection::StringWithinCollectionComputeHeapSizes ( Vector & heap_sizes_v,
const Vector & source_v,
TupleDataVectorFormat & source_format,
const SelectionVector & append_sel,
const idx_t append_count,
const UnifiedVectorFormat & list_data )
staticprivate

Computes the heap sizes for the string Vector that will be appended (within a list).

127107 {
127108 // Parent list data
127109 const auto list_sel = *list_data.sel;
127110 const auto list_entries = UnifiedVectorFormat::GetDataUnsafe<list_entry_t>(list_data);
127111 const auto &list_validity = list_data.validity;
127112
127113 // Source
127114 const auto &source_data = source_format.unified;
127115 const auto &source_sel = *source_data.sel;
127116 const auto data = UnifiedVectorFormat::GetData<string_t>(source_data);
127117 const auto &source_validity = source_data.validity;
127118
127119 // Target
127120 auto heap_sizes = FlatVector::GetData<idx_t>(heap_sizes_v);
127121
127122 for (idx_t i = 0; i < append_count; i++) {
127123 const auto list_idx = list_sel.get_index(append_sel.get_index(i));
127124 if (!list_validity.RowIsValid(list_idx)) {
127125 continue; // Original list entry is invalid - no need to serialize the child
127126 }
127127
127128 // Get the current list entry
127129 const auto &list_entry = list_entries[list_idx];
127130 const auto &list_offset = list_entry.offset;
127131 const auto &list_length = list_entry.length;
127132 if (list_length == 0) {
127133 continue;
127134 }
127135
127136 // Size is validity mask and all string sizes
127137 auto &heap_size = heap_sizes[i];
127138 heap_size += ValidityBytes::SizeInBytes(list_length);
127139 heap_size += list_length * TupleDataWithinListFixedSize<string_t>();
127140
127141 // Plus all the actual strings
127142 for (idx_t child_i = 0; child_i < list_length; child_i++) {
127143 const auto child_source_idx = source_sel.get_index(list_offset + child_i);
127144 if (source_validity.RowIsValid(child_source_idx)) {
127145 heap_size += data[child_source_idx].GetSize();
127146 }
127147 }
127148 }
127149}
Here is the caller graph for this function:

◆ StructWithinCollectionComputeHeapSizes()

void duckdb::TupleDataCollection::StructWithinCollectionComputeHeapSizes ( Vector & heap_sizes_v,
const Vector & source_v,
TupleDataVectorFormat & source_format,
const SelectionVector & append_sel,
const idx_t append_count,
const UnifiedVectorFormat & list_data )
staticprivate

Computes the heap sizes for the struct Vector that will be appended (within a list).

127155 {
127156 // Parent list data
127157 const auto list_sel = *list_data.sel;
127158 const auto list_entries = UnifiedVectorFormat::GetDataUnsafe<list_entry_t>(list_data);
127159 const auto &list_validity = list_data.validity;
127160
127161 // Target
127162 auto heap_sizes = FlatVector::GetData<idx_t>(heap_sizes_v);
127163
127164 for (idx_t i = 0; i < append_count; i++) {
127165 const auto list_idx = list_sel.get_index(append_sel.get_index(i));
127166 if (!list_validity.RowIsValid(list_idx)) {
127167 continue; // Original list entry is invalid - no need to serialize the child
127168 }
127169
127170 // Get the current list length
127171 const auto &list_length = list_entries[list_idx].length;
127172 if (list_length == 0) {
127173 continue;
127174 }
127175
127176 // Size is just the validity mask
127177 heap_sizes[i] += ValidityBytes::SizeInBytes(list_length);
127178 }
127179
127180 // Recurse
127181 auto &struct_sources = StructVector::GetEntries(source_v);
127182 for (idx_t struct_col_idx = 0; struct_col_idx < struct_sources.size(); struct_col_idx++) {
127183 auto &struct_source = *struct_sources[struct_col_idx];
127184
127185 auto &struct_format = source_format.children[struct_col_idx];
127186 WithinCollectionComputeHeapSizes(heap_sizes_v, struct_source, struct_format, append_sel, append_count,
127187 list_data);
127188 }
127189}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CollectionWithinCollectionComputeHeapSizes()

void duckdb::TupleDataCollection::CollectionWithinCollectionComputeHeapSizes ( Vector & heap_sizes_v,
const Vector & source_v,
TupleDataVectorFormat & source_format,
const SelectionVector & append_sel,
const idx_t append_count,
const UnifiedVectorFormat & list_data )
staticprivate

Computes the heap sizes for the list Vector that will be appended (within a list).

127221 {
127222 // Parent list data
127223 const auto list_sel = *list_data.sel;
127224 const auto list_entries = UnifiedVectorFormat::GetDataUnsafe<list_entry_t>(list_data);
127225 const auto &list_validity = list_data.validity;
127226
127227 // Source
127228 const auto &child_list_data = source_format.unified;
127229 const auto child_list_sel = *child_list_data.sel;
127230 const auto child_list_entries = UnifiedVectorFormat::GetDataUnsafe<list_entry_t>(child_list_data);
127231 const auto &child_list_validity = child_list_data.validity;
127232
127233 // Target
127234 auto heap_sizes = FlatVector::GetData<idx_t>(heap_sizes_v);
127235
127236 // Figure out actual child list size (can differ from ListVector::GetListSize if dict/const vector),
127237 // and we cannot use ConstantVector::ZeroSelectionVector because it may need to be longer than STANDARD_VECTOR_SIZE
127238 idx_t sum_of_sizes = 0;
127239 for (idx_t i = 0; i < append_count; i++) {
127240 const auto list_idx = list_sel.get_index(append_sel.get_index(i));
127241 if (!list_validity.RowIsValid(list_idx)) {
127242 continue;
127243 }
127244
127245 // Get the current list entry
127246 const auto &list_entry = list_entries[list_idx];
127247 const auto &list_offset = list_entry.offset;
127248 const auto &list_length = list_entry.length;
127249 if (list_length == 0) {
127250 continue;
127251 }
127252
127253 for (idx_t child_i = 0; child_i < list_length; child_i++) {
127254 const auto child_list_idx = child_list_sel.get_index(list_offset + child_i);
127255 if (!child_list_validity.RowIsValid(child_list_idx)) {
127256 continue;
127257 }
127258
127259 const auto &child_list_entry = child_list_entries[child_list_idx];
127260 const auto &child_list_length = child_list_entry.length;
127261
127262 sum_of_sizes += child_list_length;
127263 }
127264 }
127265
127266 const auto child_list_child_count = MaxValue<idx_t>(
127267 sum_of_sizes, source_v.GetType().InternalType() == PhysicalType::LIST ? ListVector::GetListSize(source_v)
127268 : ArrayVector::GetTotalSize(source_v));
127269
127270 D_ASSERT(source_format.children.size() == 1);
127271 auto &child_format = source_format.children[0];
127272#ifdef D_ASSERT_IS_ENABLED
127273 // Should be deleted by ResetCombinedListData if assertions are enabled
127274 D_ASSERT(!child_format.combined_list_data);
127275#endif
127276 if (!child_format.combined_list_data) {
127277 child_format.combined_list_data = make_uniq<CombinedListData>();
127278 }
127279 auto &combined_list_data = *child_format.combined_list_data;
127280
127281 // Construct combined list entries and a selection/validity vector for the child list child
127282 SelectionVector combined_sel(child_list_child_count);
127283 for (idx_t i = 0; i < child_list_child_count; i++) {
127284 combined_sel.set_index(i, 0);
127285 }
127286 auto &combined_list_entries = combined_list_data.combined_list_entries;
127287 auto &combined_validity = combined_list_data.combined_validity;
127288 combined_validity.SetAllValid(STANDARD_VECTOR_SIZE);
127289
127290 idx_t combined_list_offset = 0;
127291 for (idx_t i = 0; i < append_count; i++) {
127292 const auto append_idx = append_sel.get_index(i);
127293 const auto list_idx = list_sel.get_index(append_idx);
127294 if (!list_validity.RowIsValid(list_idx)) {
127295 combined_validity.SetInvalidUnsafe(append_idx);
127296 continue; // Original list entry is invalid - no need to serialize the child list
127297 }
127298
127299 // Get the current list entry
127300 const auto &list_entry = list_entries[list_idx];
127301 const auto &list_offset = list_entry.offset;
127302 const auto &list_length = list_entry.length;
127303
127304 // Size is the validity mask and the list sizes
127305 auto &heap_size = heap_sizes[i];
127306 heap_size += ValidityBytes::SizeInBytes(list_length);
127307 heap_size += list_length * sizeof(uint64_t);
127308
127309 idx_t child_list_size = 0;
127310 for (idx_t child_i = 0; child_i < list_length; child_i++) {
127311 const auto child_list_idx = child_list_sel.get_index(list_offset + child_i);
127312 if (child_list_validity.RowIsValid(child_list_idx)) {
127313 const auto &child_list_entry = child_list_entries[child_list_idx];
127314 const auto &child_list_offset = child_list_entry.offset;
127315 const auto &child_list_length = child_list_entry.length;
127316 if (child_list_length == 0) {
127317 continue;
127318 }
127319
127320 // Add this child's list entries to the combined selection vector
127321 for (idx_t child_value_i = 0; child_value_i < child_list_length; child_value_i++) {
127322 auto idx = combined_list_offset + child_list_size + child_value_i;
127323 auto loc = child_list_offset + child_value_i;
127324 combined_sel.set_index(idx, loc);
127325 }
127326
127327 child_list_size += child_list_length;
127328 }
127329 }
127330
127331 // Combine the child list entries into one
127332 auto &combined_list_entry = combined_list_entries[append_idx];
127333 combined_list_entry.offset = combined_list_offset;
127334 combined_list_entry.length = child_list_size;
127335 combined_list_offset += child_list_size;
127336 }
127337
127338 // TODO: Template this?
127339 auto &child_source = source_v.GetType().InternalType() == PhysicalType::LIST ? ListVector::GetEntry(source_v)
127340 : ArrayVector::GetEntry(source_v);
127341 ApplySliceRecursive(child_source, child_format, combined_sel, child_list_child_count);
127342
127343 // Create a combined child_list_data to be used as list_data in the recursion
127344 auto &combined_child_list_data = combined_list_data.combined_data;
127345 combined_child_list_data.sel = FlatVector::IncrementalSelectionVector();
127346 combined_child_list_data.data = data_ptr_cast(combined_list_entries);
127347 combined_child_list_data.validity.Initialize(combined_validity);
127348
127349 // Recurse
127350 WithinCollectionComputeHeapSizes(heap_sizes_v, child_source, child_format, append_sel, append_count,
127351 combined_child_list_data);
127352}
static DUCKDB_API idx_t GetTotalSize(const Vector &vector)
Gets the total size of the underlying child-vector of an array.
Definition duckdb.cpp:138582
static DUCKDB_API idx_t GetListSize(const Vector &vector)
Gets the total size of the underlying child-vector of a list.
Definition duckdb.cpp:138221
Here is the call graph for this function:
Here is the caller graph for this function:

◆ NextScanIndex()

bool duckdb::TupleDataCollection::NextScanIndex ( TupleDataScanState & scan_state,
idx_t & segment_index,
idx_t & chunk_index )
private

Get the next segment/chunk index for the scan.

126337 {
126338 // Check if we still have segments to scan
126339 if (state.segment_index >= segments.size()) {
126340 // No more data left in the scan
126341 return false;
126342 }
126343 // Check within the current segment if we still have chunks to scan
126344 while (state.chunk_index >= segments[state.segment_index]->ChunkCount()) {
126345 // Exhausted all chunks for this segment: Move to the next one
126346 state.segment_index++;
126347 state.chunk_index = 0;
126348 if (state.segment_index >= segments.size()) {
126349 return false;
126350 }
126351 }
126352 segment_index = state.segment_index;
126353 chunk_index = state.chunk_index++;
126354 return true;
126355}
Here is the caller graph for this function:

◆ ScanAtIndex()

void duckdb::TupleDataCollection::ScanAtIndex ( TupleDataPinState & pin_state,
TupleDataChunkState & chunk_state,
const vector< column_t > & column_ids,
idx_t segment_index,
idx_t chunk_index,
DataChunk & result )
private

Scans the chunk at the given segment/chunk indices.

126358 {
126359 auto &segment = *segments[segment_index];
126360 const auto &chunk = *segment.chunks[chunk_index];
126361 segment.allocator->InitializeChunkState(segment, pin_state, chunk_state, chunk_index, false);
126362 result.Reset();
126363
126364 ResetCachedCastVectors(chunk_state, column_ids);
126365 Gather(chunk_state.row_locations, *FlatVector::IncrementalSelectionVector(), chunk.count, column_ids, result,
126366 *FlatVector::IncrementalSelectionVector(), chunk_state.cached_cast_vectors);
126367 result.SetCardinality(chunk.count);
126368}
static void ResetCachedCastVectors(TupleDataChunkState &chunk_state, const vector< column_t > &column_ids)
Resets the cached cache vectors (used for ARRAY/LIST casts).
Definition duckdb.cpp:126370
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Verify()

void duckdb::TupleDataCollection::Verify ( ) const
private

Verify count/data size of this collection.

126404 {
126405#ifdef D_ASSERT_IS_ENABLED
126406 idx_t total_count = 0;
126407 idx_t total_size = 0;
126408 for (const auto &segment : segments) {
126409 segment->Verify();
126410 total_count += segment->count;
126411 total_size += segment->data_size;
126412 }
126413 D_ASSERT(total_count == this->count);
126414 D_ASSERT(total_size == this->data_size);
126415#endif
126416}
Here is the call graph for this function:
Here is the caller graph for this function:

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