1 | //===----------------------------------------------------------------------===// |
---|---|
2 | // DuckDB |
3 | // |
4 | // duckdb/storage/statistics/node_statistics.hpp |
5 | // |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #pragma once |
10 | |
11 | #include "duckdb/common/common.hpp" |
12 | #include "duckdb/common/serializer.hpp" |
13 | |
14 | namespace duckdb { |
15 | |
16 | class NodeStatistics { |
17 | public: |
18 | NodeStatistics() : has_estimated_cardinality(false), has_max_cardinality(false) { |
19 | } |
20 | explicit NodeStatistics(idx_t estimated_cardinality) |
21 | : has_estimated_cardinality(true), estimated_cardinality(estimated_cardinality), has_max_cardinality(false) { |
22 | } |
23 | NodeStatistics(idx_t estimated_cardinality, idx_t max_cardinality) |
24 | : has_estimated_cardinality(true), estimated_cardinality(estimated_cardinality), has_max_cardinality(true), |
25 | max_cardinality(max_cardinality) { |
26 | } |
27 | void Serialize(Serializer &serializer) const { |
28 | serializer.Write(element: has_estimated_cardinality); |
29 | if (has_estimated_cardinality) { |
30 | serializer.Write(element: estimated_cardinality); |
31 | serializer.Write(element: has_max_cardinality); |
32 | if (has_max_cardinality) { |
33 | serializer.Write(element: max_cardinality); |
34 | } |
35 | } else { |
36 | D_ASSERT(!has_max_cardinality); |
37 | } |
38 | } |
39 | static unique_ptr<NodeStatistics> Deserialize(Deserializer &source) { |
40 | bool has_estimated_cardinality = source.Read<bool>(); |
41 | if (!has_estimated_cardinality) { |
42 | return make_uniq<NodeStatistics>(); |
43 | } |
44 | idx_t estimated_cardinality = source.Read<idx_t>(); |
45 | bool has_max_cardinality = source.Read<bool>(); |
46 | if (!has_max_cardinality) { |
47 | return make_uniq<NodeStatistics>(args&: estimated_cardinality); |
48 | } |
49 | idx_t max_cardinality = source.Read<idx_t>(); |
50 | return make_uniq<NodeStatistics>(args&: estimated_cardinality, args&: max_cardinality); |
51 | } |
52 | |
53 | //! Whether or not the node has an estimated cardinality specified |
54 | bool has_estimated_cardinality; |
55 | //! The estimated cardinality at the specified node |
56 | idx_t estimated_cardinality; |
57 | //! Whether or not the node has a maximum cardinality specified |
58 | bool has_max_cardinality; |
59 | //! The max possible cardinality at the specified node |
60 | idx_t max_cardinality; |
61 | }; |
62 | |
63 | } // namespace duckdb |
64 |