duckdb 0.7.2-dev16.0 → 0.7.2-dev314.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/binding.gyp +2 -0
- package/package.json +1 -1
- package/src/duckdb/extension/icu/icu-extension.cpp +2 -0
- package/src/duckdb/extension/icu/icu-table-range.cpp +194 -0
- package/src/duckdb/extension/icu/include/icu-table-range.hpp +17 -0
- package/src/duckdb/extension/parquet/column_reader.cpp +5 -6
- package/src/duckdb/extension/parquet/column_writer.cpp +0 -1
- package/src/duckdb/extension/parquet/include/column_reader.hpp +1 -2
- package/src/duckdb/extension/parquet/include/generated_column_reader.hpp +1 -11
- package/src/duckdb/extension/parquet/parquet-extension.cpp +11 -2
- package/src/duckdb/extension/parquet/parquet_statistics.cpp +26 -32
- package/src/duckdb/src/catalog/catalog_entry/duck_schema_entry.cpp +4 -0
- package/src/duckdb/src/catalog/catalog_entry/scalar_function_catalog_entry.cpp +7 -6
- package/src/duckdb/src/catalog/catalog_entry/table_function_catalog_entry.cpp +20 -1
- package/src/duckdb/src/common/enums/statement_type.cpp +2 -0
- package/src/duckdb/src/common/sort/sort_state.cpp +5 -7
- package/src/duckdb/src/common/types/bit.cpp +95 -58
- package/src/duckdb/src/common/types/value.cpp +149 -53
- package/src/duckdb/src/common/types/vector.cpp +13 -10
- package/src/duckdb/src/execution/column_binding_resolver.cpp +6 -0
- package/src/duckdb/src/execution/operator/aggregate/physical_perfecthash_aggregate.cpp +4 -5
- package/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +1 -1
- package/src/duckdb/src/execution/operator/helper/physical_vacuum.cpp +2 -3
- package/src/duckdb/src/execution/operator/join/physical_blockwise_nl_join.cpp +32 -6
- package/src/duckdb/src/execution/operator/persistent/buffered_csv_reader.cpp +1 -1
- package/src/duckdb/src/execution/physical_plan/plan_aggregate.cpp +15 -15
- package/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp +18 -12
- package/src/duckdb/src/function/aggregate/algebraic/avg.cpp +0 -6
- package/src/duckdb/src/function/aggregate/distributive/bitagg.cpp +99 -95
- package/src/duckdb/src/function/aggregate/distributive/bitstring_agg.cpp +254 -0
- package/src/duckdb/src/function/aggregate/distributive/count.cpp +2 -4
- package/src/duckdb/src/function/aggregate/distributive/sum.cpp +11 -16
- package/src/duckdb/src/function/aggregate/distributive_functions.cpp +1 -0
- package/src/duckdb/src/function/aggregate/sorted_aggregate_function.cpp +16 -5
- package/src/duckdb/src/function/cast/bit_cast.cpp +0 -2
- package/src/duckdb/src/function/cast/blob_cast.cpp +0 -1
- package/src/duckdb/src/function/scalar/bit/bitstring.cpp +99 -0
- package/src/duckdb/src/function/scalar/date/date_diff.cpp +0 -1
- package/src/duckdb/src/function/scalar/date/date_part.cpp +17 -25
- package/src/duckdb/src/function/scalar/date/date_sub.cpp +0 -1
- package/src/duckdb/src/function/scalar/date/date_trunc.cpp +10 -14
- package/src/duckdb/src/function/scalar/generic/stats.cpp +2 -4
- package/src/duckdb/src/function/scalar/list/flatten.cpp +5 -12
- package/src/duckdb/src/function/scalar/list/list_concat.cpp +3 -8
- package/src/duckdb/src/function/scalar/list/list_extract.cpp +5 -12
- package/src/duckdb/src/function/scalar/list/list_value.cpp +5 -9
- package/src/duckdb/src/function/scalar/map/map_entries.cpp +61 -0
- package/src/duckdb/src/function/scalar/map/map_keys_values.cpp +97 -0
- package/src/duckdb/src/function/scalar/math/numeric.cpp +14 -17
- package/src/duckdb/src/function/scalar/nested_functions.cpp +3 -0
- package/src/duckdb/src/function/scalar/operators/add.cpp +0 -9
- package/src/duckdb/src/function/scalar/operators/arithmetic.cpp +29 -48
- package/src/duckdb/src/function/scalar/operators/bitwise.cpp +0 -63
- package/src/duckdb/src/function/scalar/operators/multiply.cpp +0 -6
- package/src/duckdb/src/function/scalar/operators/subtract.cpp +0 -6
- package/src/duckdb/src/function/scalar/string/caseconvert.cpp +2 -6
- package/src/duckdb/src/function/scalar/string/instr.cpp +2 -6
- package/src/duckdb/src/function/scalar/string/length.cpp +2 -6
- package/src/duckdb/src/function/scalar/string/like.cpp +2 -6
- package/src/duckdb/src/function/scalar/string/substring.cpp +2 -6
- package/src/duckdb/src/function/scalar/string_functions.cpp +1 -0
- package/src/duckdb/src/function/scalar/struct/struct_extract.cpp +4 -9
- package/src/duckdb/src/function/scalar/struct/struct_insert.cpp +10 -13
- package/src/duckdb/src/function/scalar/struct/struct_pack.cpp +5 -6
- package/src/duckdb/src/function/table/read_csv.cpp +9 -0
- package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
- package/src/duckdb/src/function/table_function.cpp +19 -0
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_function_catalog_entry.hpp +6 -8
- package/src/duckdb/src/include/duckdb/common/constants.hpp +0 -19
- package/src/duckdb/src/include/duckdb/common/enums/statement_type.hpp +2 -1
- package/src/duckdb/src/include/duckdb/common/enums/tableref_type.hpp +2 -1
- package/src/duckdb/src/include/duckdb/common/types/bit.hpp +5 -1
- package/src/duckdb/src/include/duckdb/common/types/value.hpp +2 -8
- package/src/duckdb/src/include/duckdb/common/types.hpp +1 -2
- package/src/duckdb/src/include/duckdb/execution/operator/aggregate/physical_perfecthash_aggregate.hpp +1 -1
- package/src/duckdb/src/include/duckdb/function/aggregate/distributive_functions.hpp +5 -0
- package/src/duckdb/src/include/duckdb/function/aggregate_function.hpp +12 -3
- package/src/duckdb/src/include/duckdb/function/scalar/bit_functions.hpp +4 -0
- package/src/duckdb/src/include/duckdb/function/scalar/nested_functions.hpp +12 -0
- package/src/duckdb/src/include/duckdb/function/scalar_function.hpp +2 -2
- package/src/duckdb/src/include/duckdb/function/table_function.hpp +2 -0
- package/src/duckdb/src/include/duckdb/main/capi/capi_internal.hpp +2 -0
- package/src/duckdb/src/include/duckdb/main/config.hpp +3 -0
- package/src/duckdb/src/include/duckdb/main/database.hpp +1 -0
- package/src/duckdb/src/include/duckdb/optimizer/join_order/cardinality_estimator.hpp +2 -2
- package/src/duckdb/src/include/duckdb/parser/common_table_expression_info.hpp +2 -0
- package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_info.hpp +2 -1
- package/src/duckdb/src/include/duckdb/parser/parsed_data/{alter_function_info.hpp → alter_scalar_function_info.hpp} +13 -13
- package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_table_function_info.hpp +47 -0
- package/src/duckdb/src/include/duckdb/parser/parsed_data/create_table_function_info.hpp +2 -1
- package/src/duckdb/src/include/duckdb/parser/query_node.hpp +2 -1
- package/src/duckdb/src/include/duckdb/parser/statement/multi_statement.hpp +28 -0
- package/src/duckdb/src/include/duckdb/parser/tableref/list.hpp +1 -0
- package/src/duckdb/src/include/duckdb/parser/tableref/pivotref.hpp +76 -0
- package/src/duckdb/src/include/duckdb/parser/tokens.hpp +2 -0
- package/src/duckdb/src/include/duckdb/parser/transformer.hpp +28 -0
- package/src/duckdb/src/include/duckdb/planner/bind_context.hpp +2 -0
- package/src/duckdb/src/include/duckdb/planner/binder.hpp +8 -0
- package/src/duckdb/src/include/duckdb/storage/buffer/block_handle.hpp +2 -0
- package/src/duckdb/src/include/duckdb/storage/buffer_manager.hpp +76 -44
- package/src/duckdb/src/include/duckdb/storage/checkpoint/table_data_writer.hpp +3 -2
- package/src/duckdb/src/include/duckdb/storage/compression/chimp/chimp_compress.hpp +2 -2
- package/src/duckdb/src/include/duckdb/storage/compression/chimp/chimp_fetch.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/compression/chimp/chimp_scan.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/compression/patas/patas_compress.hpp +2 -2
- package/src/duckdb/src/include/duckdb/storage/compression/patas/patas_fetch.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/compression/patas/patas_scan.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/data_pointer.hpp +5 -2
- package/src/duckdb/src/include/duckdb/storage/data_table.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/statistics/base_statistics.hpp +93 -29
- package/src/duckdb/src/include/duckdb/storage/statistics/column_statistics.hpp +22 -3
- package/src/duckdb/src/include/duckdb/storage/statistics/distinct_statistics.hpp +6 -6
- package/src/duckdb/src/include/duckdb/storage/statistics/list_stats.hpp +41 -0
- package/src/duckdb/src/include/duckdb/storage/statistics/node_statistics.hpp +26 -0
- package/src/duckdb/src/include/duckdb/storage/statistics/numeric_stats.hpp +157 -0
- package/src/duckdb/src/include/duckdb/storage/statistics/segment_statistics.hpp +2 -7
- package/src/duckdb/src/include/duckdb/storage/statistics/string_stats.hpp +74 -0
- package/src/duckdb/src/include/duckdb/storage/statistics/struct_stats.hpp +42 -0
- package/src/duckdb/src/include/duckdb/storage/string_uncompressed.hpp +2 -3
- package/src/duckdb/src/include/duckdb/storage/table/column_segment.hpp +2 -2
- package/src/duckdb/src/include/duckdb/storage/table/list_column_data.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/table/persistent_table_data.hpp +2 -1
- package/src/duckdb/src/include/duckdb/storage/table/row_group.hpp +4 -3
- package/src/duckdb/src/include/duckdb/storage/table/row_group_collection.hpp +3 -2
- package/src/duckdb/src/include/duckdb/storage/table/scan_state.hpp +2 -0
- package/src/duckdb/src/include/duckdb/storage/table/table_statistics.hpp +5 -0
- package/src/duckdb/src/include/duckdb.h +49 -1
- package/src/duckdb/src/include/duckdb.hpp +0 -1
- package/src/duckdb/src/main/capi/pending-c.cpp +16 -3
- package/src/duckdb/src/main/capi/result-c.cpp +27 -1
- package/src/duckdb/src/main/capi/stream-c.cpp +25 -0
- package/src/duckdb/src/main/client_context.cpp +8 -1
- package/src/duckdb/src/main/config.cpp +66 -1
- package/src/duckdb/src/main/database.cpp +10 -2
- package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +98 -67
- package/src/duckdb/src/optimizer/join_order/join_order_optimizer.cpp +16 -3
- package/src/duckdb/src/optimizer/statistics/expression/propagate_aggregate.cpp +9 -3
- package/src/duckdb/src/optimizer/statistics/expression/propagate_and_compress.cpp +6 -7
- package/src/duckdb/src/optimizer/statistics/expression/propagate_cast.cpp +14 -11
- package/src/duckdb/src/optimizer/statistics/expression/propagate_columnref.cpp +1 -1
- package/src/duckdb/src/optimizer/statistics/expression/propagate_comparison.cpp +13 -15
- package/src/duckdb/src/optimizer/statistics/expression/propagate_conjunction.cpp +0 -1
- package/src/duckdb/src/optimizer/statistics/expression/propagate_constant.cpp +3 -75
- package/src/duckdb/src/optimizer/statistics/expression/propagate_function.cpp +7 -2
- package/src/duckdb/src/optimizer/statistics/expression/propagate_operator.cpp +10 -0
- package/src/duckdb/src/optimizer/statistics/operator/propagate_aggregate.cpp +2 -3
- package/src/duckdb/src/optimizer/statistics/operator/propagate_filter.cpp +28 -31
- package/src/duckdb/src/optimizer/statistics/operator/propagate_join.cpp +4 -5
- package/src/duckdb/src/optimizer/statistics/operator/propagate_set_operation.cpp +3 -3
- package/src/duckdb/src/optimizer/statistics_propagator.cpp +1 -1
- package/src/duckdb/src/parser/parsed_data/alter_info.cpp +7 -3
- package/src/duckdb/src/parser/parsed_data/alter_scalar_function_info.cpp +56 -0
- package/src/duckdb/src/parser/parsed_data/alter_table_function_info.cpp +51 -0
- package/src/duckdb/src/parser/parsed_data/create_scalar_function_info.cpp +3 -2
- package/src/duckdb/src/parser/parsed_data/create_table_function_info.cpp +6 -0
- package/src/duckdb/src/parser/parsed_expression_iterator.cpp +8 -0
- package/src/duckdb/src/parser/query_node.cpp +1 -1
- package/src/duckdb/src/parser/statement/multi_statement.cpp +18 -0
- package/src/duckdb/src/parser/tableref/pivotref.cpp +296 -0
- package/src/duckdb/src/parser/tableref.cpp +3 -0
- package/src/duckdb/src/parser/transform/helpers/transform_alias.cpp +12 -6
- package/src/duckdb/src/parser/transform/helpers/transform_cte.cpp +24 -0
- package/src/duckdb/src/parser/transform/statement/transform_create_function.cpp +4 -0
- package/src/duckdb/src/parser/transform/statement/transform_create_view.cpp +4 -0
- package/src/duckdb/src/parser/transform/statement/transform_pivot_stmt.cpp +150 -0
- package/src/duckdb/src/parser/transform/statement/transform_select.cpp +8 -0
- package/src/duckdb/src/parser/transform/statement/transform_select_node.cpp +1 -1
- package/src/duckdb/src/parser/transform/tableref/transform_join.cpp +4 -0
- package/src/duckdb/src/parser/transform/tableref/transform_pivot.cpp +105 -0
- package/src/duckdb/src/parser/transform/tableref/transform_tableref.cpp +2 -0
- package/src/duckdb/src/parser/transformer.cpp +15 -3
- package/src/duckdb/src/planner/bind_context.cpp +16 -0
- package/src/duckdb/src/planner/binder/query_node/bind_select_node.cpp +11 -3
- package/src/duckdb/src/planner/binder/query_node/plan_select_node.cpp +0 -1
- package/src/duckdb/src/planner/binder/statement/bind_create.cpp +1 -1
- package/src/duckdb/src/planner/binder/statement/bind_logical_plan.cpp +17 -0
- package/src/duckdb/src/planner/binder/tableref/bind_joinref.cpp +9 -0
- package/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp +365 -0
- package/src/duckdb/src/planner/binder.cpp +7 -1
- package/src/duckdb/src/planner/bound_result_modifier.cpp +1 -1
- package/src/duckdb/src/planner/expression/bound_window_expression.cpp +1 -1
- package/src/duckdb/src/planner/filter/constant_filter.cpp +4 -6
- package/src/duckdb/src/planner/pragma_handler.cpp +10 -2
- package/src/duckdb/src/storage/buffer_manager.cpp +44 -46
- package/src/duckdb/src/storage/checkpoint/row_group_writer.cpp +1 -1
- package/src/duckdb/src/storage/checkpoint/table_data_reader.cpp +1 -4
- package/src/duckdb/src/storage/checkpoint/table_data_writer.cpp +4 -4
- package/src/duckdb/src/storage/compression/bitpacking.cpp +28 -24
- package/src/duckdb/src/storage/compression/fixed_size_uncompressed.cpp +43 -45
- package/src/duckdb/src/storage/compression/numeric_constant.cpp +9 -10
- package/src/duckdb/src/storage/compression/patas.cpp +1 -1
- package/src/duckdb/src/storage/compression/rle.cpp +19 -15
- package/src/duckdb/src/storage/compression/validity_uncompressed.cpp +5 -5
- package/src/duckdb/src/storage/data_table.cpp +4 -6
- package/src/duckdb/src/storage/statistics/base_statistics.cpp +373 -128
- package/src/duckdb/src/storage/statistics/column_statistics.cpp +58 -3
- package/src/duckdb/src/storage/statistics/distinct_statistics.cpp +4 -9
- package/src/duckdb/src/storage/statistics/list_stats.cpp +117 -0
- package/src/duckdb/src/storage/statistics/numeric_stats.cpp +529 -0
- package/src/duckdb/src/storage/statistics/segment_statistics.cpp +2 -11
- package/src/duckdb/src/storage/statistics/string_stats.cpp +273 -0
- package/src/duckdb/src/storage/statistics/struct_stats.cpp +131 -0
- package/src/duckdb/src/storage/storage_info.cpp +1 -1
- package/src/duckdb/src/storage/table/column_checkpoint_state.cpp +3 -4
- package/src/duckdb/src/storage/table/column_data.cpp +16 -11
- package/src/duckdb/src/storage/table/column_data_checkpointer.cpp +2 -3
- package/src/duckdb/src/storage/table/column_segment.cpp +6 -8
- package/src/duckdb/src/storage/table/list_column_data.cpp +39 -58
- package/src/duckdb/src/storage/table/row_group.cpp +24 -23
- package/src/duckdb/src/storage/table/row_group_collection.cpp +12 -12
- package/src/duckdb/src/storage/table/standard_column_data.cpp +6 -6
- package/src/duckdb/src/storage/table/struct_column_data.cpp +15 -16
- package/src/duckdb/src/storage/table/table_statistics.cpp +27 -7
- package/src/duckdb/src/storage/table/update_segment.cpp +10 -12
- package/src/duckdb/third_party/libpg_query/include/nodes/nodes.hpp +3 -0
- package/src/duckdb/third_party/libpg_query/include/nodes/parsenodes.hpp +34 -1
- package/src/duckdb/third_party/libpg_query/include/parser/gram.hpp +1020 -530
- package/src/duckdb/third_party/libpg_query/include/parser/kwlist.hpp +7 -0
- package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +23560 -22737
- package/src/duckdb/ub_src_function_aggregate_distributive.cpp +2 -0
- package/src/duckdb/ub_src_function_scalar_bit.cpp +2 -0
- package/src/duckdb/ub_src_function_scalar_map.cpp +4 -0
- package/src/duckdb/ub_src_main_capi.cpp +2 -0
- package/src/duckdb/ub_src_parser_parsed_data.cpp +4 -2
- package/src/duckdb/ub_src_parser_statement.cpp +2 -0
- package/src/duckdb/ub_src_parser_tableref.cpp +2 -0
- package/src/duckdb/ub_src_parser_transform_statement.cpp +2 -0
- package/src/duckdb/ub_src_parser_transform_tableref.cpp +2 -0
- package/src/duckdb/ub_src_planner_binder_tableref.cpp +2 -0
- package/src/duckdb/ub_src_storage_statistics.cpp +4 -6
- package/src/duckdb/src/include/duckdb/main/loadable_extension.hpp +0 -59
- package/src/duckdb/src/include/duckdb/storage/statistics/list_statistics.hpp +0 -36
- package/src/duckdb/src/include/duckdb/storage/statistics/numeric_statistics.hpp +0 -75
- package/src/duckdb/src/include/duckdb/storage/statistics/string_statistics.hpp +0 -49
- package/src/duckdb/src/include/duckdb/storage/statistics/struct_statistics.hpp +0 -36
- package/src/duckdb/src/include/duckdb/storage/statistics/validity_statistics.hpp +0 -45
- package/src/duckdb/src/parser/parsed_data/alter_function_info.cpp +0 -55
- package/src/duckdb/src/storage/statistics/list_statistics.cpp +0 -94
- package/src/duckdb/src/storage/statistics/numeric_statistics.cpp +0 -307
- package/src/duckdb/src/storage/statistics/string_statistics.cpp +0 -220
- package/src/duckdb/src/storage/statistics/struct_statistics.cpp +0 -108
- package/src/duckdb/src/storage/statistics/validity_statistics.cpp +0 -91
@@ -23,23 +23,75 @@ class DatabaseInstance;
|
|
23
23
|
class TemporaryDirectoryHandle;
|
24
24
|
struct EvictionQueue;
|
25
25
|
|
26
|
+
//! The BufferPool is in charge of handling memory management for one or more databases. It defines memory limits
|
27
|
+
//! and implements priority eviction among all users of the pool.
|
28
|
+
class BufferPool {
|
29
|
+
friend class BlockHandle;
|
30
|
+
friend class BlockManager;
|
31
|
+
friend class BufferManager;
|
32
|
+
|
33
|
+
public:
|
34
|
+
explicit BufferPool(idx_t maximum_memory);
|
35
|
+
virtual ~BufferPool();
|
36
|
+
|
37
|
+
//! Set a new memory limit to the buffer pool, throws an exception if the new limit is too low and not enough
|
38
|
+
//! blocks can be evicted
|
39
|
+
void SetLimit(idx_t limit, const char *exception_postscript);
|
40
|
+
|
41
|
+
idx_t GetUsedMemory() {
|
42
|
+
return current_memory;
|
43
|
+
}
|
44
|
+
idx_t GetMaxMemory() {
|
45
|
+
return maximum_memory;
|
46
|
+
}
|
47
|
+
|
48
|
+
protected:
|
49
|
+
//! Evict blocks until the currently used memory + extra_memory fit, returns false if this was not possible
|
50
|
+
//! (i.e. not enough blocks could be evicted)
|
51
|
+
//! If the "buffer" argument is specified AND the system can find a buffer to re-use for the given allocation size
|
52
|
+
//! "buffer" will be made to point to the re-usable memory. Note that this is not guaranteed.
|
53
|
+
//! Returns a pair. result.first indicates if eviction was successful. result.second contains the
|
54
|
+
//! reservation handle, which can be moved to the BlockHandle that will own the reservation.
|
55
|
+
struct EvictionResult {
|
56
|
+
bool success;
|
57
|
+
TempBufferPoolReservation reservation;
|
58
|
+
};
|
59
|
+
virtual EvictionResult EvictBlocks(idx_t extra_memory, idx_t memory_limit,
|
60
|
+
unique_ptr<FileBuffer> *buffer = nullptr);
|
61
|
+
|
62
|
+
//! Garbage collect eviction queue
|
63
|
+
void PurgeQueue();
|
64
|
+
void AddToEvictionQueue(shared_ptr<BlockHandle> &handle);
|
65
|
+
|
66
|
+
private:
|
67
|
+
//! The lock for changing the memory limit
|
68
|
+
mutex limit_lock;
|
69
|
+
//! The current amount of memory that is occupied by the buffer manager (in bytes)
|
70
|
+
atomic<idx_t> current_memory;
|
71
|
+
//! The maximum amount of memory that the buffer manager can keep (in bytes)
|
72
|
+
atomic<idx_t> maximum_memory;
|
73
|
+
//! Eviction queue
|
74
|
+
unique_ptr<EvictionQueue> queue;
|
75
|
+
//! Total number of insertions into the eviction queue. This guides the schedule for calling PurgeQueue.
|
76
|
+
atomic<uint32_t> queue_insertions;
|
77
|
+
};
|
78
|
+
|
26
79
|
struct TemporaryFileInformation {
|
27
80
|
string path;
|
28
81
|
idx_t size;
|
29
82
|
};
|
30
83
|
|
31
|
-
//! The
|
32
|
-
//!
|
33
|
-
|
34
|
-
//!
|
35
|
-
//! can be shared by many BlockManagers.
|
84
|
+
//! The BufferManager is in charge of handling memory management for a singke database. It cooperatively shares a
|
85
|
+
//! BufferPool with other BufferManagers, belonging to different databases. It hands out memory buffers that can
|
86
|
+
//! be used by the database internally, and offers configuration options specific to a database, which need not be
|
87
|
+
//! shared by the BufferPool, including whether to support swapping temp buffers to disk, and where to swap them to.
|
36
88
|
class BufferManager {
|
37
89
|
friend class BufferHandle;
|
38
90
|
friend class BlockHandle;
|
39
91
|
friend class BlockManager;
|
40
92
|
|
41
93
|
public:
|
42
|
-
BufferManager(DatabaseInstance &db, string temp_directory
|
94
|
+
BufferManager(DatabaseInstance &db, string temp_directory);
|
43
95
|
virtual ~BufferManager();
|
44
96
|
|
45
97
|
//! Registers an in-memory buffer that cannot be unloaded until it is destroyed
|
@@ -58,21 +110,17 @@ public:
|
|
58
110
|
BufferHandle Pin(shared_ptr<BlockHandle> &handle);
|
59
111
|
void Unpin(shared_ptr<BlockHandle> &handle);
|
60
112
|
|
61
|
-
//! Set a new memory limit to the buffer manager, throws an exception if the new limit is too low and not enough
|
62
|
-
//! blocks can be evicted
|
63
|
-
void SetLimit(idx_t limit = (idx_t)-1);
|
64
|
-
|
65
113
|
DUCKDB_API static BufferManager &GetBufferManager(ClientContext &context);
|
66
114
|
DUCKDB_API static BufferManager &GetBufferManager(DatabaseInstance &db);
|
67
115
|
DUCKDB_API static BufferManager &GetBufferManager(AttachedDatabase &db);
|
68
116
|
|
69
117
|
//! Returns the currently allocated memory
|
70
118
|
idx_t GetUsedMemory() {
|
71
|
-
return current_memory;
|
119
|
+
return buffer_pool.current_memory;
|
72
120
|
}
|
73
121
|
//! Returns the maximum available memory
|
74
122
|
idx_t GetMaxMemory() {
|
75
|
-
return maximum_memory;
|
123
|
+
return buffer_pool.maximum_memory;
|
76
124
|
}
|
77
125
|
|
78
126
|
//! Increases the currently allocated memory, but the actual allocation does not go through the buffer manager
|
@@ -92,6 +140,10 @@ public:
|
|
92
140
|
return db;
|
93
141
|
}
|
94
142
|
|
143
|
+
BufferPool &GetBufferPool() {
|
144
|
+
return buffer_pool;
|
145
|
+
}
|
146
|
+
|
95
147
|
static idx_t GetAllocSize(idx_t block_size) {
|
96
148
|
return AlignValue<idx_t, Storage::SECTOR_SIZE>(block_size + Storage::BLOCK_HEADER_SIZE);
|
97
149
|
}
|
@@ -103,6 +155,11 @@ public:
|
|
103
155
|
DUCKDB_API void ReserveMemory(idx_t size);
|
104
156
|
DUCKDB_API void FreeReservedMemory(idx_t size);
|
105
157
|
|
158
|
+
//! Set a new memory limit to the buffer pool, throws an exception if the new limit is too low and not enough
|
159
|
+
//! blocks can be evicted. (Sugar for calling method directly on the BufferPool.)
|
160
|
+
void SetLimit(idx_t limit = (idx_t)-1) {
|
161
|
+
buffer_pool.SetLimit(limit, InMemoryWarning());
|
162
|
+
}
|
106
163
|
//! Returns a list of all temporary files
|
107
164
|
vector<TemporaryFileInformation> GetTemporaryFiles();
|
108
165
|
|
@@ -113,25 +170,6 @@ private:
|
|
113
170
|
//! This needs to be private to prevent creating blocks without ever pinning them:
|
114
171
|
//! blocks that are never pinned are never added to the eviction queue
|
115
172
|
shared_ptr<BlockHandle> RegisterMemory(idx_t block_size, bool can_destroy);
|
116
|
-
//! Evict blocks until the currently used memory + extra_memory fit, returns false if this was not possible
|
117
|
-
//! (i.e. not enough blocks could be evicted)
|
118
|
-
//! If the "buffer" argument is specified AND the system can find a buffer to re-use for the given allocation size
|
119
|
-
//! "buffer" will be made to point to the re-usable memory. Note that this is not guaranteed.
|
120
|
-
//! Returns a pair. result.first indicates if eviction was successful. result.second contains the
|
121
|
-
//! reservation handle, which can be moved to the BlockHandle that will own the reservation.
|
122
|
-
struct EvictionResult {
|
123
|
-
bool success;
|
124
|
-
TempBufferPoolReservation reservation;
|
125
|
-
};
|
126
|
-
EvictionResult EvictBlocks(idx_t extra_memory, idx_t memory_limit, unique_ptr<FileBuffer> *buffer = nullptr);
|
127
|
-
|
128
|
-
//! Helper
|
129
|
-
template <typename... ARGS>
|
130
|
-
TempBufferPoolReservation EvictBlocksOrThrow(idx_t extra_memory, idx_t limit, unique_ptr<FileBuffer> *buffer,
|
131
|
-
ARGS...);
|
132
|
-
|
133
|
-
//! Garbage collect eviction queue
|
134
|
-
void PurgeQueue();
|
135
173
|
|
136
174
|
//! Write a temporary buffer to disk
|
137
175
|
void WriteTemporaryBuffer(block_id_t block_id, FileBuffer &buffer);
|
@@ -144,9 +182,7 @@ private:
|
|
144
182
|
|
145
183
|
void RequireTemporaryDirectory();
|
146
184
|
|
147
|
-
|
148
|
-
|
149
|
-
string InMemoryWarning();
|
185
|
+
const char *InMemoryWarning();
|
150
186
|
|
151
187
|
static data_ptr_t BufferAllocatorAllocate(PrivateAllocatorData *private_data, idx_t size);
|
152
188
|
static void BufferAllocatorFree(PrivateAllocatorData *private_data, data_ptr_t pointer, idx_t size);
|
@@ -157,27 +193,23 @@ private:
|
|
157
193
|
//! overwrites the data within with garbage. Any readers that do not hold the pin will notice
|
158
194
|
void VerifyZeroReaders(shared_ptr<BlockHandle> &handle);
|
159
195
|
|
196
|
+
//! Helper
|
197
|
+
template <typename... ARGS>
|
198
|
+
TempBufferPoolReservation EvictBlocksOrThrow(idx_t extra_memory, unique_ptr<FileBuffer> *buffer, ARGS...);
|
199
|
+
|
160
200
|
private:
|
161
201
|
//! The database instance
|
162
202
|
DatabaseInstance &db;
|
163
|
-
//! The
|
164
|
-
|
165
|
-
//! The current amount of memory that is occupied by the buffer manager (in bytes)
|
166
|
-
atomic<idx_t> current_memory;
|
167
|
-
//! The maximum amount of memory that the buffer manager can keep (in bytes)
|
168
|
-
atomic<idx_t> maximum_memory;
|
203
|
+
//! The buffer pool
|
204
|
+
BufferPool &buffer_pool;
|
169
205
|
//! The directory name where temporary files are stored
|
170
206
|
string temp_directory;
|
171
207
|
//! Lock for creating the temp handle
|
172
208
|
mutex temp_handle_lock;
|
173
209
|
//! Handle for the temporary directory
|
174
210
|
unique_ptr<TemporaryDirectoryHandle> temp_directory_handle;
|
175
|
-
//! Eviction queue
|
176
|
-
unique_ptr<EvictionQueue> queue;
|
177
211
|
//! The temporary id used for managed buffers
|
178
212
|
atomic<block_id_t> temporary_id;
|
179
|
-
//! Total number of insertions into the eviction queue. This guides the schedule for calling PurgeQueue.
|
180
|
-
atomic<uint32_t> queue_insertions;
|
181
213
|
//! Allocator associated with the buffer manager, that passes all allocations through this buffer manager
|
182
214
|
Allocator buffer_allocator;
|
183
215
|
//! Block manager for temp data
|
@@ -12,6 +12,7 @@
|
|
12
12
|
|
13
13
|
namespace duckdb {
|
14
14
|
class DuckTableEntry;
|
15
|
+
class TableStatistics;
|
15
16
|
|
16
17
|
//! The table data writer is responsible for writing the data of a table to
|
17
18
|
//! storage.
|
@@ -30,7 +31,7 @@ public:
|
|
30
31
|
|
31
32
|
CompressionType GetColumnCompressionType(idx_t i);
|
32
33
|
|
33
|
-
virtual void FinalizeTable(
|
34
|
+
virtual void FinalizeTable(TableStatistics &&global_stats, DataTableInfo *info) = 0;
|
34
35
|
virtual unique_ptr<RowGroupWriter> GetRowGroupWriter(RowGroup &row_group) = 0;
|
35
36
|
|
36
37
|
virtual void AddRowGroup(RowGroupPointer &&row_group_pointer, unique_ptr<RowGroupWriter> &&writer);
|
@@ -47,7 +48,7 @@ public:
|
|
47
48
|
MetaBlockWriter &table_data_writer, MetaBlockWriter &meta_data_writer);
|
48
49
|
|
49
50
|
public:
|
50
|
-
virtual void FinalizeTable(
|
51
|
+
virtual void FinalizeTable(TableStatistics &&global_stats, DataTableInfo *info) override;
|
51
52
|
virtual unique_ptr<RowGroupWriter> GetRowGroupWriter(RowGroup &row_group) override;
|
52
53
|
|
53
54
|
private:
|
@@ -18,7 +18,7 @@
|
|
18
18
|
#include "duckdb/function/compression/compression.hpp"
|
19
19
|
#include "duckdb/main/config.hpp"
|
20
20
|
#include "duckdb/storage/buffer_manager.hpp"
|
21
|
-
|
21
|
+
|
22
22
|
#include "duckdb/storage/table/column_data_checkpointer.hpp"
|
23
23
|
#include "duckdb/storage/table/column_segment.hpp"
|
24
24
|
#include "duckdb/common/operator/subtract.hpp"
|
@@ -150,7 +150,7 @@ public:
|
|
150
150
|
|
151
151
|
if (is_valid) {
|
152
152
|
T floating_point_value = Load<T>((const_data_ptr_t)&value);
|
153
|
-
|
153
|
+
NumericStats::Update<T>(current_segment->stats.statistics, floating_point_value);
|
154
154
|
} else {
|
155
155
|
//! FIXME: find a cheaper alternative to storing a NULL
|
156
156
|
// store this as "value_identical", only using 9 bits for a NULL
|
@@ -17,7 +17,7 @@
|
|
17
17
|
#include "duckdb/function/compression_function.hpp"
|
18
18
|
#include "duckdb/main/config.hpp"
|
19
19
|
#include "duckdb/storage/buffer_manager.hpp"
|
20
|
-
|
20
|
+
|
21
21
|
#include "duckdb/storage/table/column_data_checkpointer.hpp"
|
22
22
|
#include "duckdb/storage/table/column_segment.hpp"
|
23
23
|
#include "duckdb/common/operator/subtract.hpp"
|
@@ -17,7 +17,7 @@
|
|
17
17
|
#include "duckdb/function/compression_function.hpp"
|
18
18
|
#include "duckdb/main/config.hpp"
|
19
19
|
#include "duckdb/storage/buffer_manager.hpp"
|
20
|
-
|
20
|
+
|
21
21
|
#include "duckdb/storage/table/column_data_checkpointer.hpp"
|
22
22
|
#include "duckdb/storage/table/column_segment.hpp"
|
23
23
|
#include "duckdb/common/operator/subtract.hpp"
|
@@ -18,7 +18,7 @@
|
|
18
18
|
#include "duckdb/function/compression/compression.hpp"
|
19
19
|
#include "duckdb/main/config.hpp"
|
20
20
|
#include "duckdb/storage/buffer_manager.hpp"
|
21
|
-
|
21
|
+
|
22
22
|
#include "duckdb/storage/table/column_data_checkpointer.hpp"
|
23
23
|
#include "duckdb/storage/table/column_segment.hpp"
|
24
24
|
#include "duckdb/common/operator/subtract.hpp"
|
@@ -49,7 +49,7 @@ public:
|
|
49
49
|
}
|
50
50
|
|
51
51
|
if (is_valid) {
|
52
|
-
|
52
|
+
NumericStats::Update<VALUE_TYPE>(state_wrapper->current_segment->stats.statistics, value);
|
53
53
|
}
|
54
54
|
|
55
55
|
state_wrapper->WriteValue(Load<EXACT_TYPE>((const_data_ptr_t)&value));
|
@@ -17,7 +17,7 @@
|
|
17
17
|
#include "duckdb/function/compression_function.hpp"
|
18
18
|
#include "duckdb/main/config.hpp"
|
19
19
|
#include "duckdb/storage/buffer_manager.hpp"
|
20
|
-
|
20
|
+
|
21
21
|
#include "duckdb/storage/table/column_data_checkpointer.hpp"
|
22
22
|
#include "duckdb/storage/table/column_segment.hpp"
|
23
23
|
#include "duckdb/common/operator/subtract.hpp"
|
@@ -17,7 +17,7 @@
|
|
17
17
|
#include "duckdb/function/compression_function.hpp"
|
18
18
|
#include "duckdb/main/config.hpp"
|
19
19
|
#include "duckdb/storage/buffer_manager.hpp"
|
20
|
-
|
20
|
+
|
21
21
|
#include "duckdb/storage/table/column_data_checkpointer.hpp"
|
22
22
|
#include "duckdb/storage/table/column_segment.hpp"
|
23
23
|
#include "duckdb/common/operator/subtract.hpp"
|
@@ -18,12 +18,15 @@
|
|
18
18
|
namespace duckdb {
|
19
19
|
|
20
20
|
struct DataPointer {
|
21
|
+
DataPointer(BaseStatistics stats) : statistics(std::move(stats)) {
|
22
|
+
}
|
23
|
+
|
21
24
|
uint64_t row_start;
|
22
25
|
uint64_t tuple_count;
|
23
26
|
BlockPointer block_pointer;
|
24
27
|
CompressionType compression_type;
|
25
28
|
//! Type-specific statistics of the segment
|
26
|
-
|
29
|
+
BaseStatistics statistics;
|
27
30
|
};
|
28
31
|
|
29
32
|
struct RowGroupPointer {
|
@@ -32,7 +35,7 @@ struct RowGroupPointer {
|
|
32
35
|
//! The data pointers of the column segments stored in the row group
|
33
36
|
vector<BlockPointer> data_pointers;
|
34
37
|
//! The per-column statistics of the row group
|
35
|
-
vector<
|
38
|
+
vector<BaseStatistics> statistics;
|
36
39
|
//! The versions information of the row group (if any)
|
37
40
|
shared_ptr<VersionNode> versions;
|
38
41
|
};
|
@@ -169,7 +169,7 @@ public:
|
|
169
169
|
//! Get statistics of a physical column within the table
|
170
170
|
unique_ptr<BaseStatistics> GetStatistics(ClientContext &context, column_t column_id);
|
171
171
|
//! Sets statistics of a physical column within the table
|
172
|
-
void
|
172
|
+
void SetDistinct(column_t column_id, unique_ptr<DistinctStatistics> distinct_stats);
|
173
173
|
|
174
174
|
//! Checkpoint the table to the specified table data writer
|
175
175
|
void Checkpoint(TableDataWriter &writer);
|
@@ -13,6 +13,8 @@
|
|
13
13
|
#include "duckdb/common/operator/comparison_operators.hpp"
|
14
14
|
#include "duckdb/common/enums/expression_type.hpp"
|
15
15
|
#include "duckdb/common/types/value.hpp"
|
16
|
+
#include "duckdb/storage/statistics/numeric_stats.hpp"
|
17
|
+
#include "duckdb/storage/statistics/string_stats.hpp"
|
16
18
|
|
17
19
|
namespace duckdb {
|
18
20
|
struct SelectionVector;
|
@@ -22,59 +24,121 @@ class Deserializer;
|
|
22
24
|
class FieldWriter;
|
23
25
|
class FieldReader;
|
24
26
|
class Vector;
|
25
|
-
class ValidityStatistics;
|
26
|
-
class DistinctStatistics;
|
27
27
|
struct UnifiedVectorFormat;
|
28
28
|
|
29
|
-
enum
|
29
|
+
enum class StatsInfo : uint8_t {
|
30
|
+
CAN_HAVE_NULL_VALUES = 0,
|
31
|
+
CANNOT_HAVE_NULL_VALUES = 1,
|
32
|
+
CAN_HAVE_VALID_VALUES = 2,
|
33
|
+
CANNOT_HAVE_VALID_VALUES = 3,
|
34
|
+
CAN_HAVE_NULL_AND_VALID_VALUES = 4
|
35
|
+
};
|
36
|
+
|
37
|
+
enum class StatisticsType : uint8_t { NUMERIC_STATS, STRING_STATS, LIST_STATS, STRUCT_STATS, BASE_STATS };
|
30
38
|
|
31
39
|
class BaseStatistics {
|
32
|
-
|
33
|
-
|
34
|
-
|
40
|
+
friend struct NumericStats;
|
41
|
+
friend struct StringStats;
|
42
|
+
friend struct StructStats;
|
43
|
+
friend struct ListStats;
|
35
44
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
StatisticsType stats_type;
|
45
|
+
public:
|
46
|
+
DUCKDB_API ~BaseStatistics();
|
47
|
+
// disable copy constructors
|
48
|
+
BaseStatistics(const BaseStatistics &other) = delete;
|
49
|
+
BaseStatistics &operator=(const BaseStatistics &) = delete;
|
50
|
+
//! enable move constructors
|
51
|
+
DUCKDB_API BaseStatistics(BaseStatistics &&other) noexcept;
|
52
|
+
DUCKDB_API BaseStatistics &operator=(BaseStatistics &&) noexcept;
|
45
53
|
|
46
54
|
public:
|
47
|
-
|
55
|
+
//! Creates a set of statistics for data that is unknown, i.e. "has_null" is true, "has_no_null" is true, etc
|
56
|
+
//! This can be used in case nothing is known about the data - or can be used as a baseline when only a few things
|
57
|
+
//! are known
|
58
|
+
static BaseStatistics CreateUnknown(LogicalType type);
|
59
|
+
//! Creates statistics for an empty database, i.e. "has_null" is false, "has_no_null" is false, etc
|
60
|
+
//! This is used when incrementally constructing statistics by constantly adding new values
|
61
|
+
static BaseStatistics CreateEmpty(LogicalType type);
|
62
|
+
|
63
|
+
DUCKDB_API StatisticsType GetStatsType() const;
|
64
|
+
DUCKDB_API static StatisticsType GetStatsType(const LogicalType &type);
|
48
65
|
|
49
66
|
DUCKDB_API bool CanHaveNull() const;
|
50
67
|
DUCKDB_API bool CanHaveNoNull() const;
|
51
68
|
|
52
|
-
void
|
69
|
+
void SetDistinctCount(idx_t distinct_count);
|
70
|
+
|
71
|
+
bool IsConstant() const;
|
53
72
|
|
54
|
-
|
55
|
-
return
|
73
|
+
const LogicalType &GetType() const {
|
74
|
+
return type;
|
56
75
|
}
|
57
76
|
|
58
|
-
|
77
|
+
void Set(StatsInfo info);
|
78
|
+
void CombineValidity(BaseStatistics &left, BaseStatistics &right);
|
79
|
+
void CopyValidity(BaseStatistics &stats);
|
80
|
+
inline void SetHasNull() {
|
81
|
+
has_null = true;
|
82
|
+
}
|
83
|
+
inline void SetHasNoNull() {
|
84
|
+
has_no_null = true;
|
85
|
+
}
|
59
86
|
|
60
|
-
|
87
|
+
void Merge(const BaseStatistics &other);
|
88
|
+
|
89
|
+
void Copy(const BaseStatistics &other);
|
90
|
+
|
91
|
+
BaseStatistics Copy() const;
|
92
|
+
unique_ptr<BaseStatistics> ToUnique() const;
|
61
93
|
void CopyBase(const BaseStatistics &orig);
|
62
94
|
|
63
|
-
|
64
|
-
|
95
|
+
void Serialize(Serializer &serializer) const;
|
96
|
+
void Serialize(FieldWriter &writer) const;
|
65
97
|
|
66
|
-
|
98
|
+
idx_t GetDistinctCount();
|
67
99
|
|
68
|
-
static
|
100
|
+
static BaseStatistics Deserialize(Deserializer &source, LogicalType type);
|
69
101
|
|
70
102
|
//! Verify that a vector does not violate the statistics
|
71
|
-
|
103
|
+
void Verify(Vector &vector, const SelectionVector &sel, idx_t count) const;
|
72
104
|
void Verify(Vector &vector, idx_t count) const;
|
73
105
|
|
74
|
-
|
106
|
+
string ToString() const;
|
107
|
+
|
108
|
+
static BaseStatistics FromConstant(const Value &input);
|
109
|
+
|
110
|
+
private:
|
111
|
+
BaseStatistics();
|
112
|
+
explicit BaseStatistics(LogicalType type);
|
113
|
+
|
114
|
+
static void Construct(BaseStatistics &stats, LogicalType type);
|
75
115
|
|
76
|
-
|
77
|
-
void
|
116
|
+
void InitializeUnknown();
|
117
|
+
void InitializeEmpty();
|
118
|
+
|
119
|
+
static BaseStatistics CreateUnknownType(LogicalType type);
|
120
|
+
static BaseStatistics CreateEmptyType(LogicalType type);
|
121
|
+
static BaseStatistics DeserializeType(FieldReader &reader, LogicalType type);
|
122
|
+
static BaseStatistics FromConstantType(const Value &input);
|
123
|
+
|
124
|
+
private:
|
125
|
+
//! The type of the logical segment
|
126
|
+
LogicalType type;
|
127
|
+
//! Whether or not the segment can contain NULL values
|
128
|
+
bool has_null;
|
129
|
+
//! Whether or not the segment can contain values that are not null
|
130
|
+
bool has_no_null;
|
131
|
+
// estimate that one may have even if distinct_stats==nullptr
|
132
|
+
idx_t distinct_count;
|
133
|
+
//! Numeric and String stats
|
134
|
+
union {
|
135
|
+
//! Numeric stats data, for numeric stats
|
136
|
+
NumericStatsData numeric_data;
|
137
|
+
//! String stats data, for string stats
|
138
|
+
StringStatsData string_data;
|
139
|
+
} stats_union;
|
140
|
+
//! Child stats (for LIST and STRUCT)
|
141
|
+
unique_ptr<BaseStatistics[]> child_stats;
|
78
142
|
};
|
79
143
|
|
80
144
|
} // namespace duckdb
|
@@ -9,17 +9,36 @@
|
|
9
9
|
#pragma once
|
10
10
|
|
11
11
|
#include "duckdb/storage/statistics/base_statistics.hpp"
|
12
|
+
#include "duckdb/storage/statistics/distinct_statistics.hpp"
|
12
13
|
|
13
14
|
namespace duckdb {
|
14
15
|
|
15
16
|
class ColumnStatistics {
|
16
17
|
public:
|
17
|
-
explicit ColumnStatistics(
|
18
|
-
|
19
|
-
unique_ptr<BaseStatistics> stats;
|
18
|
+
explicit ColumnStatistics(BaseStatistics stats_p);
|
19
|
+
ColumnStatistics(BaseStatistics stats_p, unique_ptr<DistinctStatistics> distinct_stats_p);
|
20
20
|
|
21
21
|
public:
|
22
22
|
static shared_ptr<ColumnStatistics> CreateEmptyStats(const LogicalType &type);
|
23
|
+
|
24
|
+
void Merge(ColumnStatistics &other);
|
25
|
+
|
26
|
+
void UpdateDistinctStatistics(Vector &v, idx_t count);
|
27
|
+
|
28
|
+
BaseStatistics &Statistics();
|
29
|
+
|
30
|
+
bool HasDistinctStats();
|
31
|
+
DistinctStatistics &DistinctStats();
|
32
|
+
void SetDistinct(unique_ptr<DistinctStatistics> distinct_stats);
|
33
|
+
|
34
|
+
shared_ptr<ColumnStatistics> Copy() const;
|
35
|
+
void Serialize(Serializer &serializer) const;
|
36
|
+
static shared_ptr<ColumnStatistics> Deserialize(Deserializer &source, const LogicalType &type);
|
37
|
+
|
38
|
+
private:
|
39
|
+
BaseStatistics stats;
|
40
|
+
//! The approximate count distinct stats of the column
|
41
|
+
unique_ptr<DistinctStatistics> distinct_stats;
|
23
42
|
};
|
24
43
|
|
25
44
|
} // namespace duckdb
|
@@ -17,7 +17,7 @@ class Serializer;
|
|
17
17
|
class Deserializer;
|
18
18
|
class Vector;
|
19
19
|
|
20
|
-
class DistinctStatistics
|
20
|
+
class DistinctStatistics {
|
21
21
|
public:
|
22
22
|
DistinctStatistics();
|
23
23
|
explicit DistinctStatistics(unique_ptr<HyperLogLog> log, idx_t sample_count, idx_t total_count);
|
@@ -30,12 +30,12 @@ public:
|
|
30
30
|
atomic<idx_t> total_count;
|
31
31
|
|
32
32
|
public:
|
33
|
-
void Merge(const
|
33
|
+
void Merge(const DistinctStatistics &other);
|
34
34
|
|
35
|
-
unique_ptr<
|
35
|
+
unique_ptr<DistinctStatistics> Copy() const;
|
36
36
|
|
37
|
-
void Serialize(Serializer &serializer) const
|
38
|
-
void Serialize(FieldWriter &writer) const
|
37
|
+
void Serialize(Serializer &serializer) const;
|
38
|
+
void Serialize(FieldWriter &writer) const;
|
39
39
|
|
40
40
|
static unique_ptr<DistinctStatistics> Deserialize(Deserializer &source);
|
41
41
|
static unique_ptr<DistinctStatistics> Deserialize(FieldReader &reader);
|
@@ -43,7 +43,7 @@ public:
|
|
43
43
|
void Update(Vector &update, idx_t count, bool sample = true);
|
44
44
|
void Update(UnifiedVectorFormat &update_data, const LogicalType &ptype, idx_t count, bool sample = true);
|
45
45
|
|
46
|
-
string ToString() const
|
46
|
+
string ToString() const;
|
47
47
|
idx_t GetCount() const;
|
48
48
|
|
49
49
|
private:
|
@@ -0,0 +1,41 @@
|
|
1
|
+
//===----------------------------------------------------------------------===//
|
2
|
+
// DuckDB
|
3
|
+
//
|
4
|
+
// duckdb/storage/statistics/list_stats.hpp
|
5
|
+
//
|
6
|
+
//
|
7
|
+
//===----------------------------------------------------------------------===//
|
8
|
+
|
9
|
+
#pragma once
|
10
|
+
|
11
|
+
#include "duckdb/common/common.hpp"
|
12
|
+
#include "duckdb/common/exception.hpp"
|
13
|
+
#include "duckdb/common/types/hugeint.hpp"
|
14
|
+
|
15
|
+
namespace duckdb {
|
16
|
+
class BaseStatistics;
|
17
|
+
class FieldWriter;
|
18
|
+
class FieldReader;
|
19
|
+
struct SelectionVector;
|
20
|
+
class Vector;
|
21
|
+
|
22
|
+
struct ListStats {
|
23
|
+
DUCKDB_API static void Construct(BaseStatistics &stats);
|
24
|
+
DUCKDB_API static BaseStatistics CreateUnknown(LogicalType type);
|
25
|
+
DUCKDB_API static BaseStatistics CreateEmpty(LogicalType type);
|
26
|
+
|
27
|
+
DUCKDB_API static const BaseStatistics &GetChildStats(const BaseStatistics &stats);
|
28
|
+
DUCKDB_API static BaseStatistics &GetChildStats(BaseStatistics &stats);
|
29
|
+
DUCKDB_API static void SetChildStats(BaseStatistics &stats, unique_ptr<BaseStatistics> new_stats);
|
30
|
+
|
31
|
+
DUCKDB_API static void Serialize(const BaseStatistics &stats, FieldWriter &writer);
|
32
|
+
DUCKDB_API static BaseStatistics Deserialize(FieldReader &reader, LogicalType type);
|
33
|
+
|
34
|
+
DUCKDB_API static string ToString(const BaseStatistics &stats);
|
35
|
+
|
36
|
+
DUCKDB_API static void Merge(BaseStatistics &stats, const BaseStatistics &other);
|
37
|
+
DUCKDB_API static void Copy(BaseStatistics &stats, const BaseStatistics &other);
|
38
|
+
DUCKDB_API static void Verify(const BaseStatistics &stats, Vector &vector, const SelectionVector &sel, idx_t count);
|
39
|
+
};
|
40
|
+
|
41
|
+
} // namespace duckdb
|
@@ -9,6 +9,7 @@
|
|
9
9
|
#pragma once
|
10
10
|
|
11
11
|
#include "duckdb/common/common.hpp"
|
12
|
+
#include "duckdb/common/serializer.hpp"
|
12
13
|
|
13
14
|
namespace duckdb {
|
14
15
|
|
@@ -23,6 +24,31 @@ public:
|
|
23
24
|
: has_estimated_cardinality(true), estimated_cardinality(estimated_cardinality), has_max_cardinality(true),
|
24
25
|
max_cardinality(max_cardinality) {
|
25
26
|
}
|
27
|
+
void Serialize(Serializer &serializer) const {
|
28
|
+
serializer.Write(has_estimated_cardinality);
|
29
|
+
if (has_estimated_cardinality) {
|
30
|
+
serializer.Write(estimated_cardinality);
|
31
|
+
serializer.Write(has_max_cardinality);
|
32
|
+
if (has_max_cardinality) {
|
33
|
+
serializer.Write(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_unique<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_unique<NodeStatistics>(estimated_cardinality);
|
48
|
+
}
|
49
|
+
idx_t max_cardinality = source.Read<idx_t>();
|
50
|
+
return make_unique<NodeStatistics>(estimated_cardinality, max_cardinality);
|
51
|
+
}
|
26
52
|
|
27
53
|
//! Whether or not the node has an estimated cardinality specified
|
28
54
|
bool has_estimated_cardinality;
|