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

Public Member Functions

 RowGroup (RowGroupCollection &collection, idx_t count)
 RowGroup (RowGroupCollection &collection, RowGroupPointer pointer)
 RowGroup (RowGroupCollection &collection, PersistentRowGroupData &data)
void MoveToCollection (RowGroupCollection &collection)
RowGroupCollection & GetCollection () const
vector< idx_t > GetOrComputeExtraMetadataBlocks (bool force_compute=false)
 Returns the list of meta block pointers used by the columns.
const vector< MetaBlockPointer > & GetColumnStartPointers () const
BlockManager & GetBlockManager () const
DataTableInfo & GetTableInfo () const
unique_ptr< RowGroup > AlterType (RowGroupCollection &collection, const LogicalType &target_type, idx_t changed_idx, ExpressionExecutor &executor, CollectionScanState &scan_state, SegmentNode< RowGroup > &node, DataChunk &scan_chunk)
unique_ptr< RowGroup > AddColumn (RowGroupCollection &collection, ColumnDefinition &new_column, ExpressionExecutor &executor, Vector &intermediate)
unique_ptr< RowGroup > RemoveColumn (RowGroupCollection &collection, idx_t removed_column)
void CommitDrop ()
void CommitDropColumn (const idx_t column_index)
void InitializeEmpty (const vector< LogicalType > &types, ColumnDataType data_type)
bool HasChanges () const
bool InitializeScan (CollectionScanState &state, SegmentNode< RowGroup > &node)
 Initialize a scan over this row_group.
bool InitializeScanWithOffset (CollectionScanState &state, SegmentNode< RowGroup > &node, idx_t vector_offset)
bool CheckZonemap (ScanFilterInfo &filters)
bool CheckZonemapSegments (CollectionScanState &state)
void Scan (ScanOptions options, CollectionScanState &state, DataChunk &result)
void Scan (CollectionScanState &state, DataChunk &result, TableScanType type)
idx_t GetSelVector (ScanOptions options, idx_t vector_idx, SelectionVector &sel_vector, idx_t max_count)
bool Fetch (TransactionData transaction, idx_t row)
 For a specific row, returns true if it should be used for the transaction and false otherwise.
void FetchRow (TransactionData transaction, ColumnFetchState &state, const vector< StorageIndex > &column_ids, row_t row_id, DataChunk &result, idx_t result_idx)
 Fetch a specific row from the row_group and insert it into the result at the specified index.
void AppendVersionInfo (TransactionData transaction, idx_t count)
 Append count rows to the version info.
void CommitAppend (transaction_t commit_id, idx_t start, idx_t count)
 Commit a previous append made by RowGroup::AppendVersionInfo.
void RevertAppend (idx_t new_count)
 Revert a previous append made by RowGroup::AppendVersionInfo.
void CleanupAppend (transaction_t lowest_transaction, idx_t start, idx_t count)
 Clean up append states that can either be compressed or deleted.
idx_t Delete (TransactionData transaction, DataTable &table, row_t *row_ids, idx_t count, idx_t row_group_start)
 Delete the given set of rows in the version manager.
RowGroupWriteData WriteToDisk (RowGroupWriteInfo &info) const
idx_t GetCommittedRowCount ()
 Returns the number of committed rows (count - committed deletes).
RowGroupWriteData WriteToDisk (RowGroupWriter &writer)
RowGroupPointer Checkpoint (RowGroupWriteData write_data, RowGroupWriter &writer, TableStatistics &global_stats, idx_t row_group_start)
bool IsPersistent () const
PersistentRowGroupData SerializeRowGroupInfo (idx_t row_group_start) const
void InitializeAppend (RowGroupAppendState &append_state)
void Append (RowGroupAppendState &append_state, DataChunk &chunk, idx_t append_count)
void Update (TransactionData transaction, DataTable &data_table, DataChunk &updates, row_t *ids, idx_t offset, idx_t count, const vector< PhysicalIndex > &column_ids, idx_t row_group_start)
void UpdateColumn (TransactionData transaction, DataTable &data_table, DataChunk &updates, Vector &row_ids, idx_t offset, idx_t count, const vector< column_t > &column_path, idx_t row_group_start)
void MergeStatistics (idx_t column_idx, const BaseStatistics &other)
void MergeIntoStatistics (idx_t column_idx, BaseStatistics &other)
void MergeIntoStatistics (TableStatistics &other)
unique_ptr< BaseStatistics > GetStatistics (idx_t column_idx) const
unique_ptr< BaseStatistics > GetStatistics (const StorageIndex &column_idx) const
void GetColumnSegmentInfo (const QueryContext &context, idx_t row_group_index, vector< ColumnSegmentInfo > &result)
idx_t GetAllocationSize () const
void Verify ()
void NextVector (CollectionScanState &state)
idx_t DeleteRows (idx_t vector_idx, transaction_t transaction_id, row_t rows[], idx_t count)
RowVersionManager & GetOrCreateVersionInfo ()
idx_t GetRowGroupSize () const
idx_t GetColumnCount () const
vector< MetaBlockPointer > CheckpointDeletes (RowGroupWriter &writer)
Public Member Functions inherited from duckdb::SegmentBase< RowGroup >
 SegmentBase (idx_t count)

Static Public Member Functions

static vector< RowGroupWriteData > WriteToDisk (RowGroupWriteInfo &info, const vector< const_reference< RowGroup > > &row_groups)
static PartitionStatistics GetPartitionStats (SegmentNode< RowGroup > &row_group)
static void Serialize (RowGroupPointer &pointer, Serializer &serializer)
static RowGroupPointer Deserialize (Deserializer &deserializer)
static FilterPropagateResult CheckRowIdFilter (const TableFilter &filter, idx_t beg_row, idx_t end_row)

Private Member Functions

optional_ptr< RowVersionManager > GetVersionInfo ()
optional_ptr< RowVersionManager > GetVersionInfoIfLoaded () const
shared_ptr< RowVersionManager > GetOrCreateVersionInfoPtr ()
shared_ptr< RowVersionManager > GetOrCreateVersionInfoInternal ()
void SetVersionInfo (shared_ptr< RowVersionManager > version)
ColumnData & GetColumn (storage_t c) const
void LoadColumn (storage_t c) const
ColumnData & GetColumn (const StorageIndex &c) const
vector< shared_ptr< ColumnData > > & GetColumns ()
void LoadRowIdColumnData () const
void SetCount (idx_t count)
bool HasUnloadedDeletes () const

Private Attributes

reference< RowGroupCollection > collection
 The RowGroupCollection this row-group is a part of.
atomic< optional_ptr< RowVersionManager > > version_info
 The version info of the row_group (inserted and deleted tuple info).
shared_ptr< RowVersionManager > owned_version_info
 The owned version info of the row_group (inserted and deleted tuple info).
vector< shared_ptr< ColumnData > > columns
 The column data of the row_group (mutable because const can lazily load).
mutex row_group_lock
vector< MetaBlockPointer > column_pointers
unique_ptr< atomic< bool >[]> is_loaded
 Whether or not each column is loaded (mutable because const can lazy load).
vector< MetaBlockPointer > deletes_pointers
bool has_metadata_blocks = false
vector< idx_t > extra_metadata_blocks
atomic< bool > deletes_is_loaded
atomic< idx_t > allocation_size
unique_ptr< ColumnData > row_id_column_data
 The row id column data (mutable because const can lazy load).
atomic< bool > row_id_is_loaded
 Whether or not row_id_column_data is loaded (mutable because const can lazy load).
atomic< bool > has_changes

Friends

class ColumnData

Additional Inherited Members

Public Attributes inherited from duckdb::SegmentBase< RowGroup >
atomic< idx_t > count
 The amount of entries in this storage chunk.

Constructor & Destructor Documentation

◆ RowGroup() [1/3]

duckdb::RowGroup::RowGroup ( RowGroupCollection & collection,
idx_t count )
432988 : SegmentBase<RowGroup>(count), collection(collection_p), version_info(nullptr), deletes_is_loaded(false),
432989 allocation_size(0), row_id_is_loaded(false), has_changes(false) {
432990 Verify();
432991}
atomic< optional_ptr< RowVersionManager > > version_info
The version info of the row_group (inserted and deleted tuple info).
Definition duckdb.hpp:23242
reference< RowGroupCollection > collection
The RowGroupCollection this row-group is a part of.
Definition duckdb.hpp:23240
atomic< bool > row_id_is_loaded
Whether or not row_id_column_data is loaded (mutable because const can lazy load).
Definition duckdb.hpp:23389
atomic< idx_t > count
Definition duckdb.hpp:23007

◆ RowGroup() [2/3]

duckdb::RowGroup::RowGroup ( RowGroupCollection & collection,
RowGroupPointer pointer )
432994 : SegmentBase<RowGroup>(pointer.tuple_count), collection(collection_p), version_info(nullptr),
432995 deletes_is_loaded(false), allocation_size(0), row_id_is_loaded(false), has_changes(false) {
432996 // deserialize the columns
432997 if (pointer.data_pointers.size() != collection_p.GetTypes().size()) {
432998 throw IOException("Row group column count is unaligned with table column count. Corrupt file?");
432999 }
433000 this->column_pointers = std::move(pointer.data_pointers);
433001 this->columns.resize(column_pointers.size());
433002 this->is_loaded = unique_ptr<atomic<bool>[]>(new atomic<bool>[columns.size()]);
433003 for (idx_t c = 0; c < columns.size(); c++) {
433004 this->is_loaded[c] = false;
433005 }
433006 this->deletes_pointers = std::move(pointer.deletes_pointers);
433007 this->has_metadata_blocks = pointer.has_metadata_blocks;
433008 this->extra_metadata_blocks = std::move(pointer.extra_metadata_blocks);
433009
433010 Verify();
433011}
unique_ptr< atomic< bool >[]> is_loaded
Whether or not each column is loaded (mutable because const can lazy load).
Definition duckdb.hpp:23380
vector< shared_ptr< ColumnData > > columns
The column data of the row_group (mutable because const can lazily load).
Definition duckdb.hpp:23246
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ RowGroup() [3/3]

duckdb::RowGroup::RowGroup ( RowGroupCollection & collection,
PersistentRowGroupData & data )
433014 : SegmentBase<RowGroup>(data.count), collection(collection_p), version_info(nullptr), deletes_is_loaded(false),
433015 allocation_size(0), row_id_is_loaded(false), has_changes(false) {
433016 auto &block_manager = GetBlockManager();
433017 auto &info = GetTableInfo();
433018 auto &types = collection.get().GetTypes();
433019 columns.reserve(types.size());
433020 for (idx_t c = 0; c < types.size(); c++) {
433021 auto entry = ColumnData::CreateColumn(block_manager, info, c, types[c]);
433022 entry->InitializeColumn(data.column_data[c]);
433023 columns.push_back(std::move(entry));
433024 }
433025
433026 Verify();
433027}

◆ ~RowGroup()

duckdb::RowGroup::~RowGroup ( )
433049 {
433050}

Member Function Documentation

◆ MoveToCollection()

void duckdb::RowGroup::MoveToCollection ( RowGroupCollection & collection)
433029 {
433030 lock_guard<mutex> l(row_group_lock);
433031 // FIXME
433032 // MoveToCollection causes any_changes to be set to true because we are changing the start position of the row group
433033 // the start position is ONLY written when targeting old serialization versions - as such, we don't actually
433034 // need to do this when targeting newer serialization versions
433035 // not doing this could allow metadata reuse in these situations, which would improve vacuuming performance
433036 // especially when vacuuming from the beginning of large tables
433037 has_changes = true;
433038 this->collection = collection_p;
433039 for (idx_t c = 0; c < columns.size(); c++) {
433040 if (is_loaded && !is_loaded[c]) {
433041 // we only need to set the column start position if it is already loaded
433042 // if it is not loaded - we will set the correct start position upon loading
433043 continue;
433044 }
433045 columns[c]->SetDataType(ColumnDataType::MAIN_TABLE);
433046 }
433047}

◆ GetCollection()

RowGroupCollection & duckdb::RowGroup::GetCollection ( ) const
inline
23250 {
23251 return collection.get();
23252 }

◆ GetOrComputeExtraMetadataBlocks()

vector< idx_t > duckdb::RowGroup::GetOrComputeExtraMetadataBlocks ( bool force_compute = false)

Returns the list of meta block pointers used by the columns.

434082 {
434083 if (has_metadata_blocks && !force_compute) {
434084 return extra_metadata_blocks;
434085 }
434086 if (column_pointers.empty()) {
434087 // no pointers
434088 return {};
434089 }
434090 vector<MetaBlockPointer> read_pointers;
434091 // column_pointers stores the beginning of each column
434092 // if columns are big - they may span multiple metadata blocks
434093 // we need to figure out all blocks that this row group points to
434094 // we need to follow the linked list in the metadata blocks to allow for this
434095 auto &metadata_manager = GetCollection().GetMetadataManager();
434096 idx_t last_idx = column_pointers.size() - 1;
434097 if (column_pointers.size() > 1) {
434098 // for all but the last column pointer - we can just follow the linked list until we reach the last column
434099 MetadataReader reader(metadata_manager, column_pointers[0]);
434100 auto last_pointer = column_pointers[last_idx];
434101 read_pointers = reader.GetRemainingBlocks(last_pointer);
434102 }
434103 // for the last column we need to deserialize the column - because we don't know where it stops
434104 auto &types = GetCollection().GetTypes();
434105 MetadataReader reader(metadata_manager, column_pointers[last_idx], &read_pointers);
434106 ColumnData::Deserialize(GetBlockManager(), GetTableInfo(), last_idx, reader, types[last_idx]);
434107
434108 unordered_set<idx_t> result_as_set;
434109 for (auto &ptr : read_pointers) {
434110 result_as_set.emplace(ptr.block_pointer);
434111 }
434112 for (auto &ptr : column_pointers) {
434113 result_as_set.erase(ptr.block_pointer);
434114 }
434115 return {result_as_set.begin(), result_as_set.end()};
434116}
Here is the call graph for this function:

◆ GetColumnStartPointers()

const vector< MetaBlockPointer > & duckdb::RowGroup::GetColumnStartPointers ( ) const
434118 {
434119 return column_pointers;
434120}

◆ GetBlockManager()

BlockManager & duckdb::RowGroup::GetBlockManager ( ) const
433129 {
433130 return GetCollection().GetBlockManager();
433131}

◆ GetTableInfo()

DataTableInfo & duckdb::RowGroup::GetTableInfo ( ) const
433132 {
433133 return GetCollection().GetTableInfo();
433134}

◆ AlterType()

unique_ptr< RowGroup > duckdb::RowGroup::AlterType ( RowGroupCollection & collection,
const LogicalType & target_type,
idx_t changed_idx,
ExpressionExecutor & executor,
CollectionScanState & scan_state,
SegmentNode< RowGroup > & node,
DataChunk & scan_chunk )
433328 {
433329 Verify();
433330
433331 // construct a new column data for this type
433332 auto column_data = ColumnData::CreateColumn(GetBlockManager(), GetTableInfo(), changed_idx, target_type);
433333
433334 ColumnAppendState append_state;
433335 column_data->InitializeAppend(append_state);
433336
433337 // scan the original table, and fill the new column with the transformed value
433338 InitializeScan(scan_state, node);
433339
433340 DataChunk append_chunk;
433341 vector<LogicalType> append_types;
433342 append_types.push_back(target_type);
433343 append_chunk.Initialize(Allocator::DefaultAllocator(), append_types);
433344 auto &append_vector = append_chunk.data[0];
433345 while (true) {
433346 // scan the table
433347 scan_chunk.Reset();
433348 Scan(scan_state, scan_chunk, TableScanType::TABLE_SCAN_ALL_ROWS);
433349 if (scan_chunk.size() == 0) {
433350 break;
433351 }
433352 // execute the expression
433353 append_chunk.Reset();
433354 executor.ExecuteExpression(scan_chunk, append_vector);
433355 column_data->Append(append_state, append_vector, scan_chunk.size());
433356 }
433357
433358 // set up the row_group based on this row_group
433359 auto row_group = make_uniq<RowGroup>(new_collection, this->count);
433360 row_group->SetVersionInfo(GetOrCreateVersionInfoPtr());
433361 auto &cols = GetColumns();
433362 for (idx_t i = 0; i < cols.size(); i++) {
433363 if (i == changed_idx) {
433364 // this is the altered column: use the new column
433365 row_group->columns.push_back(std::move(column_data));
433366 column_data.reset();
433367 } else {
433368 // this column was not altered: use the data directly
433369 row_group->columns.push_back(cols[i]);
433370 }
433371 }
433372 row_group->Verify();
433373 return row_group;
433374}
DUCKDB_API void Reset()
Definition duckdb.cpp:116840
DUCKDB_API void Initialize(ClientContext &context, const vector< LogicalType > &types, idx_t capacity=STANDARD_VECTOR_SIZE)
Definition duckdb.cpp:116791
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445
bool InitializeScan(CollectionScanState &state, SegmentNode< RowGroup > &node)
Initialize a scan over this row_group.
Definition duckdb.cpp:433299
void Scan(ScanOptions options, CollectionScanState &state, DataChunk &result)
Definition duckdb.cpp:433551
int cols
@ TABLE_SCAN_ALL_ROWS
Scan all rows, including any deleted rows. Committed updates are merged in.
Definition duckdb.hpp:22673

◆ AddColumn()

unique_ptr< RowGroup > duckdb::RowGroup::AddColumn ( RowGroupCollection & collection,
ColumnDefinition & new_column,
ExpressionExecutor & executor,
Vector & intermediate )
433377 {
433378 Verify();
433379
433380 // construct a new column data for the new column
433381 auto added_column =
433382 ColumnData::CreateColumn(GetBlockManager(), GetTableInfo(), GetColumnCount(), new_column.Type());
433383
433384 idx_t rows_to_write = this->count;
433385 if (rows_to_write > 0) {
433386 DataChunk dummy_chunk;
433387
433388 ColumnAppendState state;
433389 added_column->InitializeAppend(state);
433390 for (idx_t i = 0; i < rows_to_write; i += STANDARD_VECTOR_SIZE) {
433391 idx_t rows_in_this_vector = MinValue<idx_t>(rows_to_write - i, STANDARD_VECTOR_SIZE);
433392 dummy_chunk.SetCardinality(rows_in_this_vector);
433393 executor.ExecuteExpression(dummy_chunk, result);
433394 added_column->Append(state, result, rows_in_this_vector);
433395 }
433396 }
433397
433398 // set up the row_group based on this row_group
433399 auto row_group = make_uniq<RowGroup>(new_collection, this->count);
433400 row_group->SetVersionInfo(GetOrCreateVersionInfoPtr());
433401 row_group->columns = GetColumns();
433402 // now add the new column
433403 row_group->columns.push_back(std::move(added_column));
433404
433405 row_group->Verify();
433406 return row_group;
433407}

◆ RemoveColumn()

unique_ptr< RowGroup > duckdb::RowGroup::RemoveColumn ( RowGroupCollection & collection,
idx_t removed_column )
433409 {
433410 Verify();
433411
433412 D_ASSERT(removed_column < columns.size());
433413
433414 auto row_group = make_uniq<RowGroup>(new_collection, this->count);
433415 row_group->SetVersionInfo(GetOrCreateVersionInfoPtr());
433416 // copy over all columns except for the removed one
433417 auto &cols = GetColumns();
433418 for (idx_t i = 0; i < cols.size(); i++) {
433419 if (i != removed_column) {
433420 row_group->columns.push_back(cols[i]);
433421 }
433422 }
433423
433424 row_group->Verify();
433425 return row_group;
433426}

◆ CommitDrop()

void duckdb::RowGroup::CommitDrop ( )
433428 {
433429 for (idx_t column_idx = 0; column_idx < GetColumnCount(); column_idx++) {
433430 CommitDropColumn(column_idx);
433431 }
433432}

◆ CommitDropColumn()

void duckdb::RowGroup::CommitDropColumn ( const idx_t column_index)
433445 {
433446 auto &column = GetColumn(column_index);
433447 BlockIdDropper dropper(GetBlockManager());
433448 column.VisitBlockIds(dropper);
433449}

◆ InitializeEmpty()

void duckdb::RowGroup::InitializeEmpty ( const vector< LogicalType > & types,
ColumnDataType data_type )
433136 {
433137 // set up the segment trees for the column segments
433138 D_ASSERT(columns.empty());
433139 for (idx_t i = 0; i < types.size(); i++) {
433140 auto column_data = ColumnData::CreateColumn(GetBlockManager(), GetTableInfo(), i, types[i], data_type);
433141 columns.push_back(std::move(column_data));
433142 }
433143}

◆ HasChanges()

bool duckdb::RowGroup::HasChanges ( ) const
434258 {
434259 if (has_changes) {
434260 return true;
434261 }
434262 auto version_info_loaded = version_info.load();
434263 if (version_info_loaded && version_info_loaded->HasUnserializedChanges()) {
434264 // we have deletes
434265 return true;
434266 }
434267 // check if any of the columns have changes
434268 // avoid loading unloaded columns - unloaded columns can never have changes
434269 for (idx_t c = 0; c < columns.size(); c++) {
434270 if (is_loaded && !is_loaded[c]) {
434271 continue;
434272 }
434273 if (columns[c]->HasAnyChanges()) {
434274 return true;
434275 }
434276 }
434277 return false;
434278}

◆ InitializeScan()

bool duckdb::RowGroup::InitializeScan ( CollectionScanState & state,
SegmentNode< RowGroup > & node )

Initialize a scan over this row_group.

433299 {
433300 auto &column_ids = state.GetColumnIds();
433301 auto &filters = state.GetFilterInfo();
433302 if (!CheckZonemap(filters)) {
433303 return false;
433304 }
433305 if (!RefersToSameObject(node.GetNode(), *this)) {
433306 throw InternalException("RowGroup::InitializeScan segment node mismatch");
433307 }
433308 auto row_start = node.GetRowStart();
433309 state.row_group = node;
433310 state.vector_index = 0;
433311 state.max_row_group_row = row_start > state.max_row ? 0 : MinValue<idx_t>(this->count, state.max_row - row_start);
433312 if (state.max_row_group_row == 0) {
433313 return false;
433314 }
433315 D_ASSERT(!state.column_scans.empty());
433316 for (idx_t i = 0; i < column_ids.size(); i++) {
433317 auto column = column_ids[i];
433318 auto &column_data = GetColumn(column);
433319 column_data.InitializeScan(state.column_scans[i]);
433320 state.column_scans[i].scan_options = &state.GetOptions();
433321 }
433322 return true;
433323}
bool CheckZonemap(ScanFilterInfo &filters)
Definition duckdb.cpp:433470
bool RefersToSameObject(const reference< T > &a, const reference< T > &b)
Returns whether or not two reference wrappers refer to the same object.
Definition duckdb.hpp:2191
Here is the call graph for this function:

◆ InitializeScanWithOffset()

bool duckdb::RowGroup::InitializeScanWithOffset ( CollectionScanState & state,
SegmentNode< RowGroup > & node,
idx_t vector_offset )
433270 {
433271 auto &column_ids = state.GetColumnIds();
433272 auto &filters = state.GetFilterInfo();
433273 if (!CheckZonemap(filters)) {
433274 return false;
433275 }
433276 if (!RefersToSameObject(node.GetNode(), *this)) {
433277 throw InternalException("RowGroup::InitializeScanWithOffset segment node mismatch");
433278 }
433279
433280 state.row_group = node;
433281 state.vector_index = vector_offset;
433282 auto row_start = node.GetRowStart();
433283 state.max_row_group_row = row_start > state.max_row ? 0 : MinValue<idx_t>(this->count, state.max_row - row_start);
433284 auto row_number = vector_offset * STANDARD_VECTOR_SIZE;
433285 if (state.max_row_group_row == 0) {
433286 // exceeded row groups to scan
433287 return false;
433288 }
433289 D_ASSERT(!state.column_scans.empty());
433290 for (idx_t i = 0; i < column_ids.size(); i++) {
433291 const auto &column = column_ids[i];
433292 auto &column_data = GetColumn(column);
433293 column_data.InitializeScanWithOffset(state.column_scans[i], row_number);
433294 state.column_scans[i].scan_options = &state.GetOptions();
433295 }
433296 return true;
433297}

◆ CheckZonemap()

bool duckdb::RowGroup::CheckZonemap ( ScanFilterInfo & filters)

Checks the given set of table filters against the row-group statistics. Returns false if the entire row group can be skipped.

433470 {
433471 auto &filter_list = filters.GetFilterList();
433472 // new row group - label all filters as up for grabs again
433473 filters.CheckAllFilters();
433474 for (idx_t i = 0; i < filter_list.size(); i++) {
433475 auto &entry = filter_list[i];
433476 auto &filter = entry.filter;
433477 const auto &base_column_index = entry.table_column_index;
433478
433479 auto prune_result = GetColumn(base_column_index).CheckZonemap(base_column_index, filter);
433480 if (prune_result == FilterPropagateResult::FILTER_ALWAYS_FALSE) {
433481 return false;
433482 }
433483 if (filter.filter_type == TableFilterType::OPTIONAL_FILTER) {
433484 // these are only for row group checking, set as always true so we don't check it
433485 filters.SetFilterAlwaysTrue(i);
433486 } else if (prune_result == FilterPropagateResult::FILTER_ALWAYS_TRUE) {
433487 // filter is always true - no need to check it
433488 // label the filter as always true so we don't need to check it anymore
433489 filters.SetFilterAlwaysTrue(i);
433490 }
433491 }
433492 return true;
433493}
void filter(InputArray image, InputArray kernel, OutputArray output)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckZonemapSegments()

bool duckdb::RowGroup::CheckZonemapSegments ( CollectionScanState & state)

Checks the given set of table filters against the per-segment statistics. Returns false if any segments were skipped.

433495 {
433496 auto &filters = state.GetFilterInfo();
433497 optional_idx target_vector_index_max;
433498 for (auto &entry : filters.GetFilterList()) {
433499 if (entry.IsAlwaysTrue()) {
433500 // filter is always true - avoid checking
433501 continue;
433502 }
433503 auto column_idx = entry.scan_column_index;
433504 auto base_column_idx = entry.table_column_index;
433505 auto &filter = entry.filter;
433506
433507 auto prune_result = GetColumn(base_column_idx).CheckZonemap(state.column_scans[column_idx], filter);
433508 if (prune_result != FilterPropagateResult::FILTER_ALWAYS_FALSE) {
433509 continue;
433510 }
433511
433512 // check zone map segment.
433513 auto &column_scan_state = state.column_scans[column_idx];
433514 auto current_segment = column_scan_state.current;
433515 if (!current_segment) {
433516 // no segment to skip
433517 continue;
433518 }
433519 auto row_start = current_segment->GetRowStart();
433520 idx_t target_row = row_start + current_segment->GetNode().count;
433521 if (target_row >= state.max_row) {
433522 target_row = state.max_row;
433523 }
433524 D_ASSERT(target_row >= row_start);
433525 D_ASSERT(target_row <= row_start + this->count);
433526 idx_t target_vector_index = (target_row - row_start) / STANDARD_VECTOR_SIZE;
433527
433528 if (!target_vector_index_max.IsValid() || target_vector_index_max.GetIndex() < target_vector_index) {
433529 target_vector_index_max = target_vector_index;
433530 }
433531 }
433532 if (target_vector_index_max.IsValid()) {
433533 if (state.vector_index == target_vector_index_max.GetIndex()) {
433534 // we can't skip any full vectors because this segment contains less than a full vector
433535 // for now we just bail-out
433536 // FIXME: we could check if we can ALSO skip the next segments, in which case skipping a full vector
433537 // might be possible
433538 // we don't care that much though, since a single segment that fits less than a full vector is
433539 // exceedingly rare
433540 return true;
433541 }
433542 while (state.vector_index < target_vector_index_max.GetIndex()) {
433543 NextVector(state);
433544 }
433545 return false;
433546 } else {
433547 return true;
433548 }
433549}
Here is the caller graph for this function:

◆ Scan() [1/2]

void duckdb::RowGroup::Scan ( ScanOptions options,
CollectionScanState & state,
DataChunk & result )

first check the zonemap if we have to scan this partition

first, we scan the columns with filters, fetch their data and generate a selection vector. get runtime statistics

Now we use the selection vector to fetch data for the other columns.

433551 {
433552 const auto &column_ids = state.GetColumnIds();
433553 auto &filter_info = state.GetFilterInfo();
433554 auto &transaction = options.transaction;
433555 while (true) {
433556 if (state.vector_index * STANDARD_VECTOR_SIZE >= state.max_row_group_row) {
433557 // exceeded the amount of rows to scan
433558 return;
433559 }
433560 idx_t current_row = state.vector_index * STANDARD_VECTOR_SIZE;
433561 auto max_count = MinValue<idx_t>(STANDARD_VECTOR_SIZE, state.max_row_group_row - current_row);
433562
433563 // check the sampling info if we have to sample this chunk
433564 if (state.GetSamplingInfo().do_system_sample &&
433565 state.random.NextRandom() > state.GetSamplingInfo().sample_rate) {
433566 NextVector(state);
433567 continue;
433568 }
433569
433571 if (!CheckZonemapSegments(state)) {
433572 continue;
433573 }
433574 auto &current_row_group = state.row_group->GetNode();
433575
433576 // second, scan the version chunk manager to figure out which tuples to load for this transaction
433577 idx_t count = current_row_group.GetSelVector(options, state.vector_index, state.valid_sel, max_count);
433578 if (count == 0) {
433579 // nothing to scan for this vector, skip the entire vector
433580 NextVector(state);
433581 continue;
433582 }
433583 auto &block_manager = GetBlockManager();
433584 if (block_manager.Prefetch()) {
433585 PrefetchState prefetch_state;
433586 for (idx_t i = 0; i < column_ids.size(); i++) {
433587 const auto &column = column_ids[i];
433588 GetColumn(column).InitializePrefetch(prefetch_state, state.column_scans[i], max_count);
433589 }
433590 auto &buffer_manager = block_manager.buffer_manager;
433591 buffer_manager.Prefetch(prefetch_state.blocks);
433592 }
433593
433594 bool has_filters = filter_info.HasFilters();
433595 if (count == max_count && !has_filters) {
433596 // scan all vectors completely: full scan without deletions or table filters
433597 for (idx_t i = 0; i < column_ids.size(); i++) {
433598 const auto &column = column_ids[i];
433599 auto &col_data = GetColumn(column);
433600 state.column_scans[i].update_scan_type = options.update_type;
433601 col_data.Scan(transaction, state.vector_index, state.column_scans[i], result.data[i]);
433602 }
433603 } else {
433604 // partial scan: we have deletions or table filters
433605 idx_t approved_tuple_count = count;
433606 SelectionVector sel;
433607 if (count != max_count) {
433608 sel.Initialize(state.valid_sel);
433609 } else {
433610 sel.Initialize(nullptr);
433611 }
433614 auto adaptive_filter = filter_info.GetAdaptiveFilter();
433615 auto filter_state = filter_info.BeginFilter();
433616 if (has_filters) {
433617 auto &filter_list = filter_info.GetFilterList();
433618 for (idx_t i = 0; i < filter_list.size(); i++) {
433619 auto filter_idx = adaptive_filter->permutation[i];
433620 auto &filter = filter_list[filter_idx];
433621 if (filter.IsAlwaysTrue()) {
433622 // this filter is always true - skip it
433623 continue;
433624 }
433625 auto &table_filter_state = *filter.filter_state;
433626
433627 const auto scan_idx = filter.scan_column_index;
433628 const auto column_idx = filter.table_column_index;
433629
433630 auto &result_vector = result.data[scan_idx];
433631 if (approved_tuple_count == 0) {
433632 auto &col_data = GetColumn(column_idx);
433633 col_data.Skip(state.column_scans[scan_idx]);
433634 continue;
433635 }
433636 auto &col_data = GetColumn(column_idx);
433637 col_data.Filter(transaction, state.vector_index, state.column_scans[scan_idx], result_vector, sel,
433638 approved_tuple_count, filter.filter, table_filter_state);
433639 }
433640 for (auto &table_filter : filter_list) {
433641 if (table_filter.IsAlwaysTrue()) {
433642 continue;
433643 }
433644 result.data[table_filter.scan_column_index].Slice(sel, approved_tuple_count);
433645 }
433646 }
433647 if (approved_tuple_count == 0) {
433648 // all rows were filtered out by the table filters
433649 D_ASSERT(has_filters);
433650 result.Reset();
433651 // skip this vector in all the scans that were not scanned yet
433652 for (idx_t i = 0; i < column_ids.size(); i++) {
433653 auto &col_idx = column_ids[i];
433654 if (has_filters && filter_info.ColumnHasFilters(i)) {
433655 continue;
433656 }
433657 auto &col_data = GetColumn(col_idx);
433658 col_data.Skip(state.column_scans[i]);
433659 }
433660 state.vector_index++;
433661 continue;
433662 }
433664 for (idx_t i = 0; i < column_ids.size(); i++) {
433665 if (has_filters && filter_info.ColumnHasFilters(i)) {
433666 // column has already been scanned as part of the filtering process
433667 continue;
433668 }
433669 auto &column = column_ids[i];
433670 auto &col_data = GetColumn(column);
433671 state.column_scans[i].update_scan_type = options.update_type;
433672 col_data.Select(transaction, state.vector_index, state.column_scans[i], result.data[i], sel,
433673 approved_tuple_count);
433674 }
433675 filter_info.EndFilter(filter_state);
433676
433677 D_ASSERT(approved_tuple_count > 0);
433678 count = approved_tuple_count;
433679 }
433680 result.SetCardinality(count);
433681 state.vector_index++;
433682 break;
433683 }
433684}
bool CheckZonemapSegments(CollectionScanState &state)
Definition duckdb.cpp:433495
Here is the call graph for this function:

◆ Scan() [2/2]

void duckdb::RowGroup::Scan ( CollectionScanState & state,
DataChunk & result,
TableScanType type )
433689 {
433690 auto &transaction_manager = DuckTransactionManager::Get(GetCollection().GetAttached());
433691
433692 transaction_t start_ts;
433693 transaction_t transaction_id;
433695 start_ts = transaction_manager.GetLastCommit() + 1;
433696 transaction_id = MAX_TRANSACTION_ID;
433697 } else {
433698 start_ts = transaction_manager.LowestActiveStart();
433699 transaction_id = transaction_manager.LowestActiveId();
433700 }
433701 TransactionData transaction(transaction_id, start_ts);
433702
433703 ScanOptions options(transaction);
433704 options.insert_type = InsertedScanType::ALL_ROWS;
433705 switch (type) {
433707 options.delete_type = DeletedScanType::INCLUDE_ALL_DELETED;
433708 break;
433711 options.delete_type = DeletedScanType::OMIT_COMMITTED_DELETES;
433712 options.update_type = UpdateScanType::DISALLOW_UPDATES;
433713 break;
433714 default:
433715 throw InternalException("Unrecognized table scan type");
433716 }
433717 Scan(options, state, result);
433718}
idx_t transaction_t
Type used for transaction timestamps.
Definition duckdb.hpp:253
@ TABLE_SCAN_COMMITTED_ROWS
Scan the latest committed rows.
Definition duckdb.hpp:22678
@ TABLE_SCAN_OMIT_PERMANENTLY_DELETED
Definition duckdb.hpp:22676
@ INCLUDE_ALL_DELETED
include all rows, including all deleted rows
Definition duckdb.hpp:22650
@ OMIT_COMMITTED_DELETES
omit only deleted rows that have been committed and have a commit ts lower than the transaction start
Definition duckdb.hpp:22652

◆ GetSelVector()

idx_t duckdb::RowGroup::GetSelVector ( ScanOptions options,
idx_t vector_idx,
SelectionVector & sel_vector,
idx_t max_count )
433780 {
433781 if (options.insert_type == InsertedScanType::ALL_ROWS &&
433782 options.delete_type == DeletedScanType::INCLUDE_ALL_DELETED) {
433783 return max_count;
433784 }
433785 auto vinfo = GetVersionInfo();
433786 if (!vinfo) {
433787 return max_count;
433788 }
433789 return vinfo->GetSelVector(options, vector_idx, sel_vector, max_count);
433790}

◆ Fetch()

bool duckdb::RowGroup::Fetch ( TransactionData transaction,
idx_t row )

For a specific row, returns true if it should be used for the transaction and false otherwise.

433792 {
433793 if (UnsafeNumericCast<idx_t>(row) > count) {
433794 throw InternalException("RowGroup::Fetch - row_id out of range for row group");
433795 }
433796 auto vinfo = GetVersionInfo();
433797 if (!vinfo) {
433798 return true;
433799 }
433800 return vinfo->Fetch(transaction, row);
433801}

◆ FetchRow()

void duckdb::RowGroup::FetchRow ( TransactionData transaction,
ColumnFetchState & state,
const vector< StorageIndex > & column_ids,
row_t row_id,
DataChunk & result,
idx_t result_idx )

Fetch a specific row from the row_group and insert it into the result at the specified index.

433804 {
433805 if (UnsafeNumericCast<idx_t>(row_id) > count) {
433806 throw InternalException("RowGroup::FetchRow - row_id out of range for row group");
433807 }
433808 for (idx_t col_idx = 0; col_idx < column_ids.size(); col_idx++) {
433809 auto &column = column_ids[col_idx];
433810 auto &result_vector = result.data[col_idx];
433811 D_ASSERT(result_vector.GetVectorType() == VectorType::FLAT_VECTOR);
433812 D_ASSERT(!FlatVector::IsNull(result_vector, result_idx));
433813 // regular column: fetch data from the base column
433814 auto &col_data = GetColumn(column);
433815 col_data.FetchRow(transaction, state, column, row_id, result_vector, result_idx);
433816 }
433817}

◆ AppendVersionInfo()

void duckdb::RowGroup::AppendVersionInfo ( TransactionData transaction,
idx_t count )

Append count rows to the version info.

433830 {
433831 const idx_t row_group_size = GetRowGroupSize();
433832 idx_t row_group_start = this->count.load();
433833 idx_t row_group_end = row_group_start + count;
433834 if (row_group_end > row_group_size) {
433835 row_group_end = row_group_size;
433836 }
433837 // create the version_info if it doesn't exist yet
433838 auto &vinfo = GetOrCreateVersionInfo();
433839 vinfo.AppendVersionInfo(transaction, count, row_group_start, row_group_end);
433840 SetCount(row_group_end);
433841}

◆ CommitAppend()

void duckdb::RowGroup::CommitAppend ( transaction_t commit_id,
idx_t start,
idx_t count )

Commit a previous append made by RowGroup::AppendVersionInfo.

433843 {
433844 auto &vinfo = GetOrCreateVersionInfo();
433845 vinfo.CommitAppend(commit_id, row_group_start, count);
433846}

◆ RevertAppend()

void duckdb::RowGroup::RevertAppend ( idx_t new_count)

Revert a previous append made by RowGroup::AppendVersionInfo.

433848 {
433849 if (new_count > this->count) {
433850 throw InternalException("RowGroup::RevertAppend new_count out of range");
433851 }
433852 auto &vinfo = GetOrCreateVersionInfo();
433853 vinfo.RevertAppend(new_count);
433854 for (auto &column : GetColumns()) {
433855 column->RevertAppend(UnsafeNumericCast<row_t>(new_count));
433856 }
433857 SetCount(new_count);
433858 Verify();
433859}

◆ CleanupAppend()

void duckdb::RowGroup::CleanupAppend ( transaction_t lowest_transaction,
idx_t start,
idx_t count )

Clean up append states that can either be compressed or deleted.

433884 {
433885 auto &vinfo = GetOrCreateVersionInfo();
433886 vinfo.CleanupAppend(lowest_transaction, start, count);
433887}

◆ Delete()

idx_t duckdb::RowGroup::Delete ( TransactionData transaction,
DataTable & table,
row_t * row_ids,
idx_t count,
idx_t row_group_start )

Delete the given set of rows in the version manager.

434423 {
434424 VersionDeleteState del_state(*this, transaction, table, row_group_start);
434425
434426 // obtain a write lock
434427 for (idx_t i = 0; i < count; i++) {
434428 D_ASSERT(ids[i] >= 0);
434429 D_ASSERT(idx_t(ids[i]) >= row_group_start && idx_t(ids[i]) < row_group_start + this->count);
434430 del_state.Delete(ids[i] - UnsafeNumericCast<row_t>(row_group_start));
434431 }
434432 del_state.Flush();
434433 return del_state.delete_count;
434434}

◆ WriteToDisk() [1/3]

vector< RowGroupWriteData > duckdb::RowGroup::WriteToDisk ( RowGroupWriteInfo & info,
const vector< const_reference< RowGroup > > & row_groups )
static
433994 {
433995 vector<RowGroupWriteData> result;
433996 if (row_groups.empty()) {
433997 return result;
433998 }
433999
434000 idx_t column_count = row_groups[0].get().GetColumnCount();
434001 for (auto &row_group : row_groups) {
434002 D_ASSERT(column_count == row_group.get().GetColumnCount());
434003 RowGroupWriteData write_data;
434004 write_data.states.reserve(column_count);
434005 write_data.statistics.reserve(column_count);
434006 result.push_back(std::move(write_data));
434007 }
434008
434009 // Checkpoint the row groups
434010
434011 // In order to co-locate columns across different row groups, we write column-at-a-time
434012 // i.e. we first write column #0 of all row groups, then column #1, ...
434013
434014 // Each column can have multiple segments.
434015 // (Some columns will be wider than others, and require different numbers
434016 // of blocks to encode.) Segments cannot span blocks.
434017 //
434018 // Some of these columns are composite (list, struct). The data is written
434019 // first sequentially, and the pointers are written later, so that the
434020 // pointers all end up densely packed, and thus more cache-friendly.
434021 vector<vector<shared_ptr<ColumnData>>> result_columns;
434022 result_columns.resize(row_groups.size());
434023 for (idx_t column_idx = 0; column_idx < column_count; column_idx++) {
434024 for (idx_t row_group_idx = 0; row_group_idx < row_groups.size(); row_group_idx++) {
434025 auto &row_group = row_groups[row_group_idx].get();
434026 auto &row_group_write_data = result[row_group_idx];
434027 auto &column = row_group.GetColumn(column_idx);
434028 ColumnCheckpointInfo checkpoint_info(info, column_idx);
434029 auto checkpoint_state = column.Checkpoint(row_group, checkpoint_info);
434030
434031 auto result_col = checkpoint_state->GetFinalResult();
434032 // FIXME: we should get rid of the checkpoint state statistics - and instead use the stats in the ColumnData
434033 // directly
434034 auto stats = checkpoint_state->GetStatistics();
434035 result_col->MergeStatistics(*stats);
434036
434037 result_columns[row_group_idx].push_back(std::move(result_col));
434038 row_group_write_data.statistics.push_back(stats->Copy());
434039 row_group_write_data.states.push_back(std::move(checkpoint_state));
434040 }
434041 }
434042
434043 // create the row groups
434044 for (idx_t row_group_idx = 0; row_group_idx < row_groups.size(); row_group_idx++) {
434045 auto &row_group_write_data = result[row_group_idx];
434046 auto &row_group = row_groups[row_group_idx].get();
434047 auto result_row_group = make_shared_ptr<RowGroup>(row_group.GetCollection(), row_group.count);
434048 result_row_group->columns = std::move(result_columns[row_group_idx]);
434049 result_row_group->version_info = row_group.version_info.load();
434050 result_row_group->owned_version_info = row_group.owned_version_info;
434051
434052 row_group_write_data.result_row_group = std::move(result_row_group);
434053 }
434054
434055 return result;
434056}

◆ WriteToDisk() [2/3]

RowGroupWriteData duckdb::RowGroup::WriteToDisk ( RowGroupWriteInfo & info) const

Write the data inside this RowGroup to disk and return a struct with information about the write Including the new RowGroup that contains the columns in their written-to-disk form

434058 {
434059 vector<const_reference<RowGroup>> row_groups;
434060 row_groups.push_back(*this);
434061 auto result = WriteToDisk(info, row_groups);
434062 return std::move(result[0]);
434063}

◆ GetCommittedRowCount()

idx_t duckdb::RowGroup::GetCommittedRowCount ( )

Returns the number of committed rows (count - committed deletes).

434065 {
434066 auto vinfo = GetVersionInfo();
434067 if (!vinfo) {
434068 return count;
434069 }
434070 return count - vinfo->GetCommittedDeletedCount(count);
434071}

◆ WriteToDisk() [3/3]

RowGroupWriteData duckdb::RowGroup::WriteToDisk ( RowGroupWriter & writer)
434122 {
434123 if (Settings::Get<ExperimentalMetadataReuseSetting>(writer.GetDatabase()) && !column_pointers.empty() &&
434124 !HasChanges()) {
434125 // we have existing metadata and the row group has not been changed
434126 // re-use previous metadata
434127 RowGroupWriteData result;
434128 result.reuse_existing_metadata_blocks = true;
434129 result.existing_extra_metadata_blocks = GetOrComputeExtraMetadataBlocks();
434130 return result;
434131 }
434132 auto &compression_types = writer.GetCompressionTypes();
434133 if (columns.size() != compression_types.size()) {
434134 throw InternalException("RowGroup::WriteToDisk - mismatch in column count vs compression types");
434135 }
434136 for (idx_t column_idx = 0; column_idx < GetColumnCount(); column_idx++) {
434137 auto &column = GetColumn(column_idx);
434138 if (column.count != this->count) {
434139 throw InternalException("Corrupted in-memory column - column with index %llu has misaligned count (row "
434140 "group has %llu rows, column has %llu)",
434141 column_idx, this->count.load(), column.count.load());
434142 }
434143 }
434144 RowGroupWriteInfo info(writer.GetPartialBlockManager(), compression_types, writer.GetCheckpointOptions());
434145 return WriteToDisk(info);
434146}
vector< idx_t > GetOrComputeExtraMetadataBlocks(bool force_compute=false)
Returns the list of meta block pointers used by the columns.
Definition duckdb.cpp:434082

◆ Checkpoint()

RowGroupPointer duckdb::RowGroup::Checkpoint ( RowGroupWriteData write_data,
RowGroupWriter & writer,
TableStatistics & global_stats,
idx_t row_group_start )
434158 {
434159 RowGroupPointer row_group_pointer;
434160
434161 auto metadata_manager = writer.GetMetadataManager();
434162 // construct the row group pointer and write the column meta data to disk
434163 row_group_pointer.row_start = row_group_start;
434164 row_group_pointer.tuple_count = count;
434165 if (write_data.reuse_existing_metadata_blocks) {
434166 // we are re-using the previous metadata
434167 row_group_pointer.data_pointers = column_pointers;
434168 row_group_pointer.has_metadata_blocks = true;
434169 row_group_pointer.extra_metadata_blocks = write_data.existing_extra_metadata_blocks;
434170 row_group_pointer.deletes_pointers = CheckpointDeletes(writer);
434171 if (metadata_manager) {
434172 vector<MetaBlockPointer> extra_metadata_block_pointers;
434173 extra_metadata_block_pointers.reserve(write_data.existing_extra_metadata_blocks.size());
434174 for (auto &block_pointer : write_data.existing_extra_metadata_blocks) {
434175 extra_metadata_block_pointers.emplace_back(block_pointer, 0);
434176 }
434177 metadata_manager->ClearModifiedBlocks(column_pointers);
434178 metadata_manager->ClearModifiedBlocks(extra_metadata_block_pointers);
434179 metadata_manager->ClearModifiedBlocks(deletes_pointers);
434180
434181 // remember metadata_blocks to avoid loading them on future checkpoints
434182 has_metadata_blocks = true;
434183 extra_metadata_blocks = row_group_pointer.extra_metadata_blocks;
434184 }
434185 // merge row group stats into the global stats
434186 auto lock = global_stats.GetLock();
434187 for (idx_t column_idx = 0; column_idx < GetColumnCount(); column_idx++) {
434188 if (is_loaded && !is_loaded[column_idx] &&
434189 collection.get().GetTypes()[column_idx].id() != LogicalTypeId::VARIANT) {
434190 // column is not loaded from disk - don't load just to update stats
434191 writer.SetHasUnloadedColumn(column_idx);
434192 continue;
434193 }
434194 GetColumn(column_idx).MergeIntoStatistics(global_stats.GetStats(*lock, column_idx).Statistics());
434195 }
434196 return row_group_pointer;
434197 }
434198 D_ASSERT(write_data.states.size() == columns.size());
434199 {
434200 auto lock = global_stats.GetLock();
434201 for (idx_t column_idx = 0; column_idx < GetColumnCount(); column_idx++) {
434202 global_stats.GetStats(*lock, column_idx).Statistics().Merge(write_data.statistics[column_idx]);
434203 }
434204 }
434205 vector<MetaBlockPointer> column_metadata;
434206 unordered_set<idx_t> metadata_blocks;
434207 writer.StartWritingColumns(column_metadata);
434208
434209 auto serialization_options = SerializationOptions(writer.GetAttachedDatabase());
434210
434211 for (auto &state : write_data.states) {
434212 // get the current position of the table data writer
434213 auto &data_writer = writer.GetPayloadWriter();
434214 auto pointer = writer.GetMetaBlockPointer();
434215
434216 // store the stats and the data pointers in the row group pointers
434217 row_group_pointer.data_pointers.push_back(pointer);
434218 metadata_blocks.insert(pointer.block_pointer);
434219
434220 // Write pointers to the column segments.
434221 //
434222 // Just as above, the state can refer to many other states, so this
434223 // can cascade recursively into more pointer writes.
434224 auto persistent_data = state->ToPersistentData();
434225 // increment the "start" in all data pointers by the row group start
434226 // FIXME: this is only necessary when targeting old serialization
434227 IncrementSegmentStart(persistent_data, row_group_start);
434228
434229 BinarySerializer serializer(data_writer, serialization_options);
434230 serializer.Begin();
434231 persistent_data.Serialize(serializer);
434232 serializer.End();
434233 }
434234 writer.FinishWritingColumns();
434235
434236 row_group_pointer.has_metadata_blocks = true;
434237 for (auto &column_pointer : column_metadata) {
434238 auto entry = metadata_blocks.find(column_pointer.block_pointer);
434239 if (entry != metadata_blocks.end()) {
434240 // this metadata block is already stored in "data_pointers" - no need to duplicate it
434241 continue;
434242 }
434243 // this metadata block is not stored - add it to the extra metadata blocks
434244 row_group_pointer.extra_metadata_blocks.push_back(column_pointer.block_pointer);
434245 metadata_blocks.insert(column_pointer.block_pointer);
434246 }
434247 if (metadata_manager) {
434248 row_group_pointer.deletes_pointers = CheckpointDeletes(writer);
434249 }
434250 // set up the pointers correctly within this row group for future operations
434251 column_pointers = row_group_pointer.data_pointers;
434252 has_metadata_blocks = true;
434253 extra_metadata_blocks = row_group_pointer.extra_metadata_blocks;
434254 Verify();
434255 return row_group_pointer;
434256}

◆ IsPersistent()

bool duckdb::RowGroup::IsPersistent ( ) const
434280 {
434281 for (auto &column : columns) {
434282 if (!column->IsPersistent()) {
434283 // column is not persistent
434284 return false;
434285 }
434286 }
434287 return true;
434288}

◆ SerializeRowGroupInfo()

PersistentRowGroupData duckdb::RowGroup::SerializeRowGroupInfo ( idx_t row_group_start) const
434290 {
434291 // all columns are persistent - serialize
434292 PersistentRowGroupData result;
434293 for (auto &col : columns) {
434294 result.column_data.push_back(col->Serialize());
434295 }
434296 result.start = row_group_start;
434297 result.count = count;
434298 return result;
434299}

◆ InitializeAppend()

void duckdb::RowGroup::InitializeAppend ( RowGroupAppendState & append_state)
433861 {
433862 append_state.row_group = this;
433863 append_state.offset_in_row_group = this->count;
433864 // for each column, initialize the append state
433865 append_state.states = make_unsafe_uniq_array<ColumnAppendState>(GetColumnCount());
433866 for (idx_t i = 0; i < GetColumnCount(); i++) {
433867 auto &col_data = GetColumn(i);
433868 col_data.InitializeAppend(append_state.states[i]);
433869 }
433870}

◆ Append()

void duckdb::RowGroup::Append ( RowGroupAppendState & append_state,
DataChunk & chunk,
idx_t append_count )
433872 {
433873 // append to the current row_group
433874 D_ASSERT(chunk.ColumnCount() == GetColumnCount());
433875 for (idx_t i = 0; i < GetColumnCount(); i++) {
433876 auto &col_data = GetColumn(i);
433877 auto prev_allocation_size = col_data.GetAllocationSize();
433878 col_data.Append(state.states[i], chunk.data[i], append_count);
433879 allocation_size += col_data.GetAllocationSize() - prev_allocation_size;
433880 }
433881 state.offset_in_row_group += append_count;
433882}

◆ Update()

void duckdb::RowGroup::Update ( TransactionData transaction,
DataTable & data_table,
DataChunk & updates,
row_t * ids,
idx_t offset,
idx_t count,
const vector< PhysicalIndex > & column_ids,
idx_t row_group_start )
433890 {
433891#ifdef DEBUG
433892 for (size_t i = offset; i < offset + count; i++) {
433893 D_ASSERT(ids[i] >= row_t(row_group_start) && ids[i] < row_t(row_group_start + this->count));
433894 }
433895#endif
433896 for (idx_t i = 0; i < column_ids.size(); i++) {
433897 auto column = column_ids[i];
433898 auto &col_data = GetColumn(column.index);
433899 D_ASSERT(col_data.type.id() == update_chunk.data[i].GetType().id());
433900 if (offset > 0) {
433901 Vector sliced_vector(update_chunk.data[i], offset, offset + count);
433902 sliced_vector.Flatten(count);
433903 col_data.Update(transaction, data_table, column.index, sliced_vector, ids + offset, count, row_group_start);
433904 } else {
433905 col_data.Update(transaction, data_table, column.index, update_chunk.data[i], ids, count, row_group_start);
433906 }
433907 MergeStatistics(column.index, *col_data.GetUpdateStatistics());
433908 }
433909}
int64_t row_t
The type used for row identifiers.
Definition duckdb.hpp:240

◆ UpdateColumn()

void duckdb::RowGroup::UpdateColumn ( TransactionData transaction,
DataTable & data_table,
DataChunk & updates,
Vector & row_ids,
idx_t offset,
idx_t count,
const vector< column_t > & column_path,
idx_t row_group_start )

Update a single column; corresponds to DataTable::UpdateColumn This method should only be called from the WAL

433912 {
433913 D_ASSERT(updates.ColumnCount() == 1);
433914 auto ids = FlatVector::GetData<row_t>(row_ids);
433915
433916 auto primary_column_idx = column_path[0];
433917 D_ASSERT(primary_column_idx < columns.size());
433918 auto &col_data = GetColumn(primary_column_idx);
433919 idx_t depth = 1;
433920 if (offset > 0) {
433921 Vector sliced_vector(updates.data[0], offset, offset + count);
433922 sliced_vector.Flatten(count);
433923 col_data.UpdateColumn(transaction, data_table, column_path, sliced_vector, ids + offset, count, depth,
433924 row_group_start);
433925 } else {
433926 col_data.UpdateColumn(transaction, data_table, column_path, updates.data[0], ids, count, depth,
433927 row_group_start);
433928 }
433929 MergeStatistics(primary_column_idx, *col_data.GetUpdateStatistics());
433930}
double depth(InputArray R, InputArray t, InputArray X)
Here is the call graph for this function:

◆ MergeStatistics()

void duckdb::RowGroup::MergeStatistics ( idx_t column_idx,
const BaseStatistics & other )
433946 {
433947 auto &col_data = GetColumn(column_idx);
433948 col_data.MergeStatistics(other);
433949}

◆ MergeIntoStatistics() [1/2]

void duckdb::RowGroup::MergeIntoStatistics ( idx_t column_idx,
BaseStatistics & other )
433951 {
433952 auto &col_data = GetColumn(column_idx);
433953 col_data.MergeIntoStatistics(other);
433954}

◆ MergeIntoStatistics() [2/2]

void duckdb::RowGroup::MergeIntoStatistics ( TableStatistics & other)
433956 {
433957 auto stats_lock = other.GetLock();
433958 for (idx_t i = 0; i < columns.size(); i++) {
433959 MergeIntoStatistics(i, other.GetStats(*stats_lock, i).Statistics());
433960 }
433961}

◆ GetStatistics() [1/2]

unique_ptr< BaseStatistics > duckdb::RowGroup::GetStatistics ( idx_t column_idx) const
433932 {
433933 StorageIndex storage_index(column_idx);
433934 return GetStatistics(storage_index);
433935}

◆ GetStatistics() [2/2]

unique_ptr< BaseStatistics > duckdb::RowGroup::GetStatistics ( const StorageIndex & column_idx) const
433937 {
433938 auto &col_data = GetColumn(column_idx);
433939 auto column_stats = col_data.GetStatistics();
433940 if (!column_idx.IsPushdownExtract()) {
433941 return column_stats;
433942 }
433943 return column_stats->PushdownExtract(column_idx.GetChildIndex(0));
433944}

◆ GetColumnSegmentInfo()

void duckdb::RowGroup::GetColumnSegmentInfo ( const QueryContext & context,
idx_t row_group_index,
vector< ColumnSegmentInfo > & result )
434391 {
434392 for (idx_t col_idx = 0; col_idx < GetColumnCount(); col_idx++) {
434393 auto &col_data = GetColumn(col_idx);
434394 col_data.GetColumnSegmentInfo(context, row_group_index, {col_idx}, result);
434395 }
434396}

◆ GetPartitionStats()

PartitionStatistics duckdb::RowGroup::GetPartitionStats ( SegmentNode< RowGroup > & row_group)
static
434369 {
434370 auto &row_group_ref = row_group.GetNode();
434371
434372 PartitionStatistics result;
434373 result.row_start = row_group.GetRowStart();
434374 result.count = row_group_ref.count;
434375 if (row_group_ref.HasUnloadedDeletes() || row_group_ref.GetVersionInfoIfLoaded()) {
434376 // we have version info - approx count
434377 result.count_type = CountType::COUNT_APPROXIMATE;
434378 result.partition_row_group = make_shared_ptr<DuckDBPartitionRowGroup>(row_group.ReferenceNode(), false);
434379 } else {
434380 result.count_type = CountType::COUNT_EXACT;
434381 result.partition_row_group = make_shared_ptr<DuckDBPartitionRowGroup>(row_group.ReferenceNode(), true);
434382 }
434383
434384 return result;
434385}

◆ GetAllocationSize()

idx_t duckdb::RowGroup::GetAllocationSize ( ) const
inline
23338 {
23339 return allocation_size;
23340 }

◆ Verify()

void duckdb::RowGroup::Verify ( )
434436 {
434437#ifdef DEBUG
434438 for (auto &column : GetColumns()) {
434439 column->Verify(*this);
434440 }
434441 lock_guard<mutex> guard(row_group_lock);
434442 if (row_id_is_loaded) {
434443 D_ASSERT(row_id_column_data->count == count);
434444 }
434445#endif
434446}
unique_ptr< ColumnData > row_id_column_data
The row id column data (mutable because const can lazy load).
Definition duckdb.hpp:23387

◆ NextVector()

void duckdb::RowGroup::NextVector ( CollectionScanState & state)
433451 {
433452 state.vector_index++;
433453 const auto &column_ids = state.GetColumnIds();
433454 for (idx_t i = 0; i < column_ids.size(); i++) {
433455 const auto &column = column_ids[i];
433456 GetColumn(column).Skip(state.column_scans[i]);
433457 }
433458}

◆ DeleteRows()

idx_t duckdb::RowGroup::DeleteRows ( idx_t vector_idx,
transaction_t transaction_id,
row_t rows[],
idx_t count )
434448 {
434449 return GetOrCreateVersionInfo().DeleteRows(vector_idx, transaction_id, rows, count);
434450}
int rows

◆ GetOrCreateVersionInfo()

RowVersionManager & duckdb::RowGroup::GetOrCreateVersionInfo ( )
433763 {
433764 auto vinfo = GetVersionInfo();
433765 if (vinfo) {
433766 // version info exists - return it directly
433767 return *vinfo;
433768 }
433769 return *GetOrCreateVersionInfoInternal();
433770}

◆ Serialize()

void duckdb::RowGroup::Serialize ( RowGroupPointer & pointer,
Serializer & serializer )
static
434317 {
434318 serializer.WriteProperty(100, "row_start", pointer.row_start);
434319 serializer.WriteProperty(101, "tuple_count", pointer.tuple_count);
434320 serializer.WriteProperty(102, "data_pointers", pointer.data_pointers);
434321 serializer.WriteProperty(103, "delete_pointers", pointer.deletes_pointers);
434322 if (serializer.ShouldSerialize(6)) {
434323 serializer.WriteProperty(104, "has_metadata_blocks", pointer.has_metadata_blocks);
434324 serializer.WritePropertyWithDefault(105, "extra_metadata_blocks", pointer.extra_metadata_blocks);
434325 }
434326}

◆ Deserialize()

RowGroupPointer duckdb::RowGroup::Deserialize ( Deserializer & deserializer)
static
434328 {
434329 RowGroupPointer result;
434330 result.row_start = deserializer.ReadProperty<uint64_t>(100, "row_start");
434331 result.tuple_count = deserializer.ReadProperty<uint64_t>(101, "tuple_count");
434332 result.data_pointers = deserializer.ReadProperty<vector<MetaBlockPointer>>(102, "data_pointers");
434333 result.deletes_pointers = deserializer.ReadProperty<vector<MetaBlockPointer>>(103, "delete_pointers");
434334 result.has_metadata_blocks = deserializer.ReadPropertyWithExplicitDefault<bool>(104, "has_metadata_blocks", false);
434335 result.extra_metadata_blocks = deserializer.ReadPropertyWithDefault<vector<idx_t>>(105, "extra_metadata_blocks");
434336 return result;
434337}
::uint64_t uint64_t

◆ GetRowGroupSize()

idx_t duckdb::RowGroup::GetRowGroupSize ( ) const
433064 {
433065 return collection.get().GetRowGroupSize();
433066}

◆ CheckRowIdFilter()

FilterPropagateResult duckdb::RowGroup::CheckRowIdFilter ( const TableFilter & filter,
idx_t beg_row,
idx_t end_row )
static
433460 {
433461 // RowId columns dont have a zonemap, but we can trivially create stats to check the filter against.
433462 BaseStatistics dummy_stats = NumericStats::CreateEmpty(LogicalType::ROW_TYPE);
433463 dummy_stats.SetHasNoNullFast();
433464 NumericStats::SetMin(dummy_stats, UnsafeNumericCast<row_t>(beg_row));
433465 NumericStats::SetMax(dummy_stats, UnsafeNumericCast<row_t>(end_row));
433466
433467 return filter.CheckStatistics(dummy_stats);
433468}
static DUCKDB_API BaseStatistics CreateEmpty(LogicalType type)
Empty statistics - i.e. "min = MaxValue<type>, max = MinValue<type>".
Definition duckdb.cpp:423878
static DUCKDB_API void SetMin(BaseStatistics &stats, const Value &val)
Sets the min value of the statistics.
Definition duckdb.cpp:424188
static DUCKDB_API void SetMax(BaseStatistics &stats, const Value &val)
Sets the max value of the statistics.
Definition duckdb.cpp:424193

◆ GetColumnCount()

idx_t duckdb::RowGroup::GetColumnCount ( ) const
433060 {
433061 return columns.size();
433062}

◆ CheckpointDeletes()

vector< MetaBlockPointer > duckdb::RowGroup::CheckpointDeletes ( RowGroupWriter & writer)
434301 {
434302 if (HasUnloadedDeletes()) {
434303 // deletes were not loaded so they cannot be changed
434304 // re-use them as-is
434305 auto &manager = *writer.GetMetadataManager();
434306 manager.ClearModifiedBlocks(deletes_pointers);
434307 return deletes_pointers;
434308 }
434309 auto vinfo = GetVersionInfo();
434310 if (!vinfo) {
434311 // no version information: write nothing
434312 return vector<MetaBlockPointer>();
434313 }
434314 return vinfo->Checkpoint(writer);
434315}

◆ GetVersionInfo()

optional_ptr< RowVersionManager > duckdb::RowGroup::GetVersionInfo ( )
private
433720 {
433721 if (!HasUnloadedDeletes()) {
433722 // deletes are loaded - return the version info
433723 return version_info;
433724 }
433725 lock_guard<mutex> lock(row_group_lock);
433726 // double-check after obtaining the lock whether or not deletes are still not loaded to avoid double load
433727 if (!HasUnloadedDeletes()) {
433728 return version_info;
433729 }
433730 // deletes are not loaded - reload
433731 auto root_delete = deletes_pointers[0];
433732 auto loaded_info = RowVersionManager::Deserialize(root_delete, GetBlockManager().GetMetadataManager());
433733 SetVersionInfo(std::move(loaded_info));
433734 deletes_is_loaded = true;
433735 return version_info;
433736}

◆ GetVersionInfoIfLoaded()

optional_ptr< RowVersionManager > duckdb::RowGroup::GetVersionInfoIfLoaded ( ) const
private
433772 {
433773 if (!HasUnloadedDeletes()) {
433774 // deletes are loaded - return the version info
433775 return version_info;
433776 }
433777 return nullptr;
433778}

◆ GetOrCreateVersionInfoPtr()

shared_ptr< RowVersionManager > duckdb::RowGroup::GetOrCreateVersionInfoPtr ( )
private
433754 {
433755 auto vinfo = GetVersionInfo();
433756 if (vinfo) {
433757 // version info exists - return it directly
433758 return owned_version_info;
433759 }
433760 return GetOrCreateVersionInfoInternal();
433761}
shared_ptr< RowVersionManager > owned_version_info
The owned version info of the row_group (inserted and deleted tuple info).
Definition duckdb.hpp:23244

◆ GetOrCreateVersionInfoInternal()

shared_ptr< RowVersionManager > duckdb::RowGroup::GetOrCreateVersionInfoInternal ( )
private
433743 {
433744 // version info does not exist - need to create it
433745 lock_guard<mutex> lock(row_group_lock);
433746 if (!owned_version_info) {
433747 auto &buffer_manager = GetBlockManager().GetBufferManager();
433748 auto new_info = make_shared_ptr<RowVersionManager>(buffer_manager);
433749 SetVersionInfo(std::move(new_info));
433750 }
433751 return owned_version_info;
433752}

◆ SetVersionInfo()

void duckdb::RowGroup::SetVersionInfo ( shared_ptr< RowVersionManager > version)
private
433738 {
433739 owned_version_info = std::move(version);
433741}

◆ GetColumn() [1/2]

ColumnData & duckdb::RowGroup::GetColumn ( storage_t c) const
private
433086 {
433087 LoadColumn(c);
433089}
const column_t COLUMN_IDENTIFIER_ROW_ID
Special value used to signify the ROW ID of a table.
Definition duckdb.cpp:50303

◆ LoadColumn()

void duckdb::RowGroup::LoadColumn ( storage_t c) const
private
433091 {
433092 if (c == COLUMN_IDENTIFIER_ROW_ID) {
433093 LoadRowIdColumnData();
433094 return;
433095 }
433096 D_ASSERT(c < columns.size());
433097 if (!is_loaded) {
433098 // not being lazy loaded
433099 D_ASSERT(columns[c]);
433100 return;
433101 }
433102 if (is_loaded[c]) {
433103 D_ASSERT(columns[c]);
433104 return;
433105 }
433106 lock_guard<mutex> l(row_group_lock);
433107 if (columns[c]) {
433108 // another thread loaded the column while we were waiting for the lock
433109 D_ASSERT(is_loaded[c]);
433110 return;
433111 }
433112 // load the column
433113 if (column_pointers.size() != columns.size()) {
433114 throw InternalException("Lazy loading a column but the pointer was not set");
433115 }
433116 auto &metadata_manager = GetCollection().GetMetadataManager();
433117 auto &types = GetCollection().GetTypes();
433118 auto &block_pointer = column_pointers[c];
433119 MetadataReader column_data_reader(metadata_manager, block_pointer);
433120 this->columns[c] = ColumnData::Deserialize(GetBlockManager(), GetTableInfo(), c, column_data_reader, types[c]);
433121 is_loaded[c] = true;
433122 if (this->columns[c]->count != this->count) {
433123 throw InternalException("Corrupted database - loaded column with index %llu, count %llu did "
433124 "not match count of row group %llu",
433125 c, this->columns[c]->count.load(), this->count.load());
433126 }
433127}

◆ GetColumn() [2/2]

ColumnData & duckdb::RowGroup::GetColumn ( const StorageIndex & c) const
private
433081 {
433082 auto &res = GetColumn(c.GetPrimaryIndex());
433083 return res;
433084}

◆ GetColumns()

vector< shared_ptr< ColumnData > > & duckdb::RowGroup::GetColumns ( )
private
433052 {
433053 // ensure all columns are loaded
433054 for (idx_t c = 0; c < GetColumnCount(); c++) {
433055 GetColumn(c);
433056 }
433057 return columns;
433058}

◆ LoadRowIdColumnData()

void duckdb::RowGroup::LoadRowIdColumnData ( ) const
private
433068 {
433069 if (row_id_is_loaded) {
433070 return;
433071 }
433072 lock_guard<mutex> l(row_group_lock);
433073 if (row_id_column_data) {
433074 return;
433075 }
433076 row_id_column_data = make_uniq<RowIdColumnData>(GetBlockManager(), GetTableInfo());
433077 row_id_column_data->count = count.load();
433078 row_id_is_loaded = true;
433079}

◆ SetCount()

void duckdb::RowGroup::SetCount ( idx_t count)
private
433819 {
433820 this->count = count;
433821 if (!row_id_is_loaded) {
433822 lock_guard<mutex> guard(row_group_lock);
433823 if (!row_id_is_loaded) {
433824 return;
433825 }
433826 }
433827 row_id_column_data->count = count;
433828}

◆ HasUnloadedDeletes()

bool duckdb::RowGroup::HasUnloadedDeletes ( ) const
private
434073 {
434074 if (deletes_pointers.empty()) {
434075 // no stored deletes at all
434076 return false;
434077 }
434078 // return whether or not the deletes have been loaded
434079 return !deletes_is_loaded;
434080}

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