1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/storage/table/table_statistics.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/common/common.hpp"
12#include "duckdb/common/types/data_chunk.hpp"
13#include "duckdb/common/mutex.hpp"
14#include "duckdb/storage/statistics/column_statistics.hpp"
15
16namespace duckdb {
17class ColumnList;
18class PersistentTableData;
19
20class TableStatisticsLock {
21public:
22 TableStatisticsLock(mutex &l) : guard(l) {
23 }
24
25 lock_guard<mutex> guard;
26};
27
28class TableStatistics {
29public:
30 void Initialize(const vector<LogicalType> &types, PersistentTableData &data);
31 void InitializeEmpty(const vector<LogicalType> &types);
32
33 void InitializeAddColumn(TableStatistics &parent, const LogicalType &new_column_type);
34 void InitializeRemoveColumn(TableStatistics &parent, idx_t removed_column);
35 void InitializeAlterType(TableStatistics &parent, idx_t changed_idx, const LogicalType &new_type);
36 void InitializeAddConstraint(TableStatistics &parent);
37
38 void MergeStats(TableStatistics &other);
39 void MergeStats(idx_t i, BaseStatistics &stats);
40 void MergeStats(TableStatisticsLock &lock, idx_t i, BaseStatistics &stats);
41
42 void CopyStats(TableStatistics &other);
43 unique_ptr<BaseStatistics> CopyStats(idx_t i);
44 ColumnStatistics &GetStats(idx_t i);
45
46 bool Empty();
47
48 unique_ptr<TableStatisticsLock> GetLock();
49
50 void Serialize(Serializer &serializer);
51 void Deserialize(Deserializer &source, ColumnList &columns);
52
53private:
54 //! The statistics lock
55 mutex stats_lock;
56 //! Column statistics
57 vector<shared_ptr<ColumnStatistics>> column_stats;
58};
59
60} // namespace duckdb
61