Repository: duckdb/duckdb
File: src/include/duckdb/storage/table/row_group_collection.hpp (C++)

Code before:

	void InitializeVacuumState(CollectionCheckpointState &checkpoint_state, VacuumState &state);
	bool ScheduleVacuumTasks(CollectionCheckpointState &checkpoint_state, VacuumState &state, idx_t segment_idx,
	                         bool schedule_vacuum);
	unique_ptr<CheckpointTask> GetCheckpointTask(CollectionCheckpointState &checkpoint_state, idx_t segment_idx);

	void CommitDropColumn(const idx_t column_index);
	void CommitDropTable();

	vector<PartitionStatistics> GetPartitionStats() const;
	vector<ColumnSegmentInfo> GetColumnSegmentInfo(const QueryContext &context);
	const vector<LogicalType> &GetTypes() const;

	shared_ptr<RowGroupCollection> AddColumn(ClientContext &context, ColumnDefinition &new_column,
	                                         ExpressionExecutor &default_executor);
	shared_ptr<RowGroupCollection> RemoveColumn(idx_t col_idx);
	shared_ptr<RowGroupCollection> AlterType(ClientContext &context, idx_t changed_idx, const LogicalType &target_type,
	                                         vector<StorageIndex> bound_columns, Expression &cast_expr);
	void VerifyNewConstraint(const QueryContext &context, DataTable &parent, const BoundConstraint &constraint);

	void CopyStats(TableStatistics &stats);
	unique_ptr<BaseStatistics> CopyStats(column_t column_id);
	unique_ptr<BlockingSample> GetSample();
	void SetDistinct(column_t column_id, unique_ptr<DistinctStatistics> distinct_stats);

	TableStatistics &Stats() {
		return stats;
	}
	AttachedDatabase &GetAttached();
	BlockManager &GetBlockManager() {
		return block_manager;
	}
	MetadataManager &GetMetadataManager();
	DataTableInfo &GetTableInfo() {
		return *info;
	}

	idx_t GetAllocationSize() const {
		return allocation_size;
	}

	idx_t GetRowGroupSize() const {
		return row_group_size;
	}
	void SetAppendRequiresNewRowGroup();

private:
	optional_ptr<SegmentNode<RowGroup>> NextUpdateRowGroup(RowGroupSegmentTree &row_groups, row_t *ids, idx_t &pos,
	                                                       idx_t count) const;

	shared_ptr<RowGroupSegmentTree> GetRowGroups() const;

Review comment (refactor):
Can we remove this function again? The other functions exist to provide exclusively thread-safe access to the stats - this circumvents that (and then is also used to do thread-unsafe access :) )

Code after:

	void InitializeVacuumState(CollectionCheckpointState &checkpoint_state, VacuumState &state);
	bool ScheduleVacuumTasks(CollectionCheckpointState &checkpoint_state, VacuumState &state, idx_t segment_idx,
	                         bool schedule_vacuum);
	unique_ptr<CheckpointTask> GetCheckpointTask(CollectionCheckpointState &checkpoint_state, idx_t segment_idx);

	void CommitDropColumn(const idx_t column_index);
	void CommitDropTable();

	vector<PartitionStatistics> GetPartitionStats() const;
	vector<ColumnSegmentInfo> GetColumnSegmentInfo(const QueryContext &context);
	const vector<LogicalType> &GetTypes() const;

	shared_ptr<RowGroupCollection> AddColumn(ClientContext &context, ColumnDefinition &new_column,
	                                         ExpressionExecutor &default_executor);
	shared_ptr<RowGroupCollection> RemoveColumn(idx_t col_idx);
	shared_ptr<RowGroupCollection> AlterType(ClientContext &context, idx_t changed_idx, const LogicalType &target_type,
	                                         vector<StorageIndex> bound_columns, Expression &cast_expr);
	void VerifyNewConstraint(const QueryContext &context, DataTable &parent, const BoundConstraint &constraint);

	void SetStats(TableStatistics &new_stats);
	void CopyStats(TableStatistics &stats);
	unique_ptr<BaseStatistics> CopyStats(column_t column_id);
	unique_ptr<BlockingSample> GetSample();
	void SetDistinct(column_t column_id, unique_ptr<DistinctStatistics> distinct_stats);

	AttachedDatabase &GetAttached();
	BlockManager &GetBlockManager() {
		return block_manager;
	}
	MetadataManager &GetMetadataManager();
	DataTableInfo &GetTableInfo() {
		return *info;
	}

	idx_t GetAllocationSize() const {
		return allocation_size;
	}

	idx_t GetRowGroupSize() const {
		return row_group_size;
	}
	void SetAppendRequiresNewRowGroup();

private:
	optional_ptr<SegmentNode<RowGroup>> NextUpdateRowGroup(RowGroupSegmentTree &row_groups, row_t *ids, idx_t &pos,
	                                                       idx_t count) const;

	shared_ptr<RowGroupSegmentTree> GetRowGroups() const;
	void SetRowGroups(shared_ptr<RowGroupSegmentTree> row_groups);