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.
Files changed (242) hide show
  1. package/binding.gyp +2 -0
  2. package/package.json +1 -1
  3. package/src/duckdb/extension/icu/icu-extension.cpp +2 -0
  4. package/src/duckdb/extension/icu/icu-table-range.cpp +194 -0
  5. package/src/duckdb/extension/icu/include/icu-table-range.hpp +17 -0
  6. package/src/duckdb/extension/parquet/column_reader.cpp +5 -6
  7. package/src/duckdb/extension/parquet/column_writer.cpp +0 -1
  8. package/src/duckdb/extension/parquet/include/column_reader.hpp +1 -2
  9. package/src/duckdb/extension/parquet/include/generated_column_reader.hpp +1 -11
  10. package/src/duckdb/extension/parquet/parquet-extension.cpp +11 -2
  11. package/src/duckdb/extension/parquet/parquet_statistics.cpp +26 -32
  12. package/src/duckdb/src/catalog/catalog_entry/duck_schema_entry.cpp +4 -0
  13. package/src/duckdb/src/catalog/catalog_entry/scalar_function_catalog_entry.cpp +7 -6
  14. package/src/duckdb/src/catalog/catalog_entry/table_function_catalog_entry.cpp +20 -1
  15. package/src/duckdb/src/common/enums/statement_type.cpp +2 -0
  16. package/src/duckdb/src/common/sort/sort_state.cpp +5 -7
  17. package/src/duckdb/src/common/types/bit.cpp +95 -58
  18. package/src/duckdb/src/common/types/value.cpp +149 -53
  19. package/src/duckdb/src/common/types/vector.cpp +13 -10
  20. package/src/duckdb/src/execution/column_binding_resolver.cpp +6 -0
  21. package/src/duckdb/src/execution/operator/aggregate/physical_perfecthash_aggregate.cpp +4 -5
  22. package/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +1 -1
  23. package/src/duckdb/src/execution/operator/helper/physical_vacuum.cpp +2 -3
  24. package/src/duckdb/src/execution/operator/join/physical_blockwise_nl_join.cpp +32 -6
  25. package/src/duckdb/src/execution/operator/persistent/buffered_csv_reader.cpp +1 -1
  26. package/src/duckdb/src/execution/physical_plan/plan_aggregate.cpp +15 -15
  27. package/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp +18 -12
  28. package/src/duckdb/src/function/aggregate/algebraic/avg.cpp +0 -6
  29. package/src/duckdb/src/function/aggregate/distributive/bitagg.cpp +99 -95
  30. package/src/duckdb/src/function/aggregate/distributive/bitstring_agg.cpp +254 -0
  31. package/src/duckdb/src/function/aggregate/distributive/count.cpp +2 -4
  32. package/src/duckdb/src/function/aggregate/distributive/sum.cpp +11 -16
  33. package/src/duckdb/src/function/aggregate/distributive_functions.cpp +1 -0
  34. package/src/duckdb/src/function/aggregate/sorted_aggregate_function.cpp +16 -5
  35. package/src/duckdb/src/function/cast/bit_cast.cpp +0 -2
  36. package/src/duckdb/src/function/cast/blob_cast.cpp +0 -1
  37. package/src/duckdb/src/function/scalar/bit/bitstring.cpp +99 -0
  38. package/src/duckdb/src/function/scalar/date/date_diff.cpp +0 -1
  39. package/src/duckdb/src/function/scalar/date/date_part.cpp +17 -25
  40. package/src/duckdb/src/function/scalar/date/date_sub.cpp +0 -1
  41. package/src/duckdb/src/function/scalar/date/date_trunc.cpp +10 -14
  42. package/src/duckdb/src/function/scalar/generic/stats.cpp +2 -4
  43. package/src/duckdb/src/function/scalar/list/flatten.cpp +5 -12
  44. package/src/duckdb/src/function/scalar/list/list_concat.cpp +3 -8
  45. package/src/duckdb/src/function/scalar/list/list_extract.cpp +5 -12
  46. package/src/duckdb/src/function/scalar/list/list_value.cpp +5 -9
  47. package/src/duckdb/src/function/scalar/map/map_entries.cpp +61 -0
  48. package/src/duckdb/src/function/scalar/map/map_keys_values.cpp +97 -0
  49. package/src/duckdb/src/function/scalar/math/numeric.cpp +14 -17
  50. package/src/duckdb/src/function/scalar/nested_functions.cpp +3 -0
  51. package/src/duckdb/src/function/scalar/operators/add.cpp +0 -9
  52. package/src/duckdb/src/function/scalar/operators/arithmetic.cpp +29 -48
  53. package/src/duckdb/src/function/scalar/operators/bitwise.cpp +0 -63
  54. package/src/duckdb/src/function/scalar/operators/multiply.cpp +0 -6
  55. package/src/duckdb/src/function/scalar/operators/subtract.cpp +0 -6
  56. package/src/duckdb/src/function/scalar/string/caseconvert.cpp +2 -6
  57. package/src/duckdb/src/function/scalar/string/instr.cpp +2 -6
  58. package/src/duckdb/src/function/scalar/string/length.cpp +2 -6
  59. package/src/duckdb/src/function/scalar/string/like.cpp +2 -6
  60. package/src/duckdb/src/function/scalar/string/substring.cpp +2 -6
  61. package/src/duckdb/src/function/scalar/string_functions.cpp +1 -0
  62. package/src/duckdb/src/function/scalar/struct/struct_extract.cpp +4 -9
  63. package/src/duckdb/src/function/scalar/struct/struct_insert.cpp +10 -13
  64. package/src/duckdb/src/function/scalar/struct/struct_pack.cpp +5 -6
  65. package/src/duckdb/src/function/table/read_csv.cpp +9 -0
  66. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  67. package/src/duckdb/src/function/table_function.cpp +19 -0
  68. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_function_catalog_entry.hpp +6 -8
  69. package/src/duckdb/src/include/duckdb/common/constants.hpp +0 -19
  70. package/src/duckdb/src/include/duckdb/common/enums/statement_type.hpp +2 -1
  71. package/src/duckdb/src/include/duckdb/common/enums/tableref_type.hpp +2 -1
  72. package/src/duckdb/src/include/duckdb/common/types/bit.hpp +5 -1
  73. package/src/duckdb/src/include/duckdb/common/types/value.hpp +2 -8
  74. package/src/duckdb/src/include/duckdb/common/types.hpp +1 -2
  75. package/src/duckdb/src/include/duckdb/execution/operator/aggregate/physical_perfecthash_aggregate.hpp +1 -1
  76. package/src/duckdb/src/include/duckdb/function/aggregate/distributive_functions.hpp +5 -0
  77. package/src/duckdb/src/include/duckdb/function/aggregate_function.hpp +12 -3
  78. package/src/duckdb/src/include/duckdb/function/scalar/bit_functions.hpp +4 -0
  79. package/src/duckdb/src/include/duckdb/function/scalar/nested_functions.hpp +12 -0
  80. package/src/duckdb/src/include/duckdb/function/scalar_function.hpp +2 -2
  81. package/src/duckdb/src/include/duckdb/function/table_function.hpp +2 -0
  82. package/src/duckdb/src/include/duckdb/main/capi/capi_internal.hpp +2 -0
  83. package/src/duckdb/src/include/duckdb/main/config.hpp +3 -0
  84. package/src/duckdb/src/include/duckdb/main/database.hpp +1 -0
  85. package/src/duckdb/src/include/duckdb/optimizer/join_order/cardinality_estimator.hpp +2 -2
  86. package/src/duckdb/src/include/duckdb/parser/common_table_expression_info.hpp +2 -0
  87. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_info.hpp +2 -1
  88. package/src/duckdb/src/include/duckdb/parser/parsed_data/{alter_function_info.hpp → alter_scalar_function_info.hpp} +13 -13
  89. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_table_function_info.hpp +47 -0
  90. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_table_function_info.hpp +2 -1
  91. package/src/duckdb/src/include/duckdb/parser/query_node.hpp +2 -1
  92. package/src/duckdb/src/include/duckdb/parser/statement/multi_statement.hpp +28 -0
  93. package/src/duckdb/src/include/duckdb/parser/tableref/list.hpp +1 -0
  94. package/src/duckdb/src/include/duckdb/parser/tableref/pivotref.hpp +76 -0
  95. package/src/duckdb/src/include/duckdb/parser/tokens.hpp +2 -0
  96. package/src/duckdb/src/include/duckdb/parser/transformer.hpp +28 -0
  97. package/src/duckdb/src/include/duckdb/planner/bind_context.hpp +2 -0
  98. package/src/duckdb/src/include/duckdb/planner/binder.hpp +8 -0
  99. package/src/duckdb/src/include/duckdb/storage/buffer/block_handle.hpp +2 -0
  100. package/src/duckdb/src/include/duckdb/storage/buffer_manager.hpp +76 -44
  101. package/src/duckdb/src/include/duckdb/storage/checkpoint/table_data_writer.hpp +3 -2
  102. package/src/duckdb/src/include/duckdb/storage/compression/chimp/chimp_compress.hpp +2 -2
  103. package/src/duckdb/src/include/duckdb/storage/compression/chimp/chimp_fetch.hpp +1 -1
  104. package/src/duckdb/src/include/duckdb/storage/compression/chimp/chimp_scan.hpp +1 -1
  105. package/src/duckdb/src/include/duckdb/storage/compression/patas/patas_compress.hpp +2 -2
  106. package/src/duckdb/src/include/duckdb/storage/compression/patas/patas_fetch.hpp +1 -1
  107. package/src/duckdb/src/include/duckdb/storage/compression/patas/patas_scan.hpp +1 -1
  108. package/src/duckdb/src/include/duckdb/storage/data_pointer.hpp +5 -2
  109. package/src/duckdb/src/include/duckdb/storage/data_table.hpp +1 -1
  110. package/src/duckdb/src/include/duckdb/storage/statistics/base_statistics.hpp +93 -29
  111. package/src/duckdb/src/include/duckdb/storage/statistics/column_statistics.hpp +22 -3
  112. package/src/duckdb/src/include/duckdb/storage/statistics/distinct_statistics.hpp +6 -6
  113. package/src/duckdb/src/include/duckdb/storage/statistics/list_stats.hpp +41 -0
  114. package/src/duckdb/src/include/duckdb/storage/statistics/node_statistics.hpp +26 -0
  115. package/src/duckdb/src/include/duckdb/storage/statistics/numeric_stats.hpp +157 -0
  116. package/src/duckdb/src/include/duckdb/storage/statistics/segment_statistics.hpp +2 -7
  117. package/src/duckdb/src/include/duckdb/storage/statistics/string_stats.hpp +74 -0
  118. package/src/duckdb/src/include/duckdb/storage/statistics/struct_stats.hpp +42 -0
  119. package/src/duckdb/src/include/duckdb/storage/string_uncompressed.hpp +2 -3
  120. package/src/duckdb/src/include/duckdb/storage/table/column_segment.hpp +2 -2
  121. package/src/duckdb/src/include/duckdb/storage/table/list_column_data.hpp +1 -1
  122. package/src/duckdb/src/include/duckdb/storage/table/persistent_table_data.hpp +2 -1
  123. package/src/duckdb/src/include/duckdb/storage/table/row_group.hpp +4 -3
  124. package/src/duckdb/src/include/duckdb/storage/table/row_group_collection.hpp +3 -2
  125. package/src/duckdb/src/include/duckdb/storage/table/scan_state.hpp +2 -0
  126. package/src/duckdb/src/include/duckdb/storage/table/table_statistics.hpp +5 -0
  127. package/src/duckdb/src/include/duckdb.h +49 -1
  128. package/src/duckdb/src/include/duckdb.hpp +0 -1
  129. package/src/duckdb/src/main/capi/pending-c.cpp +16 -3
  130. package/src/duckdb/src/main/capi/result-c.cpp +27 -1
  131. package/src/duckdb/src/main/capi/stream-c.cpp +25 -0
  132. package/src/duckdb/src/main/client_context.cpp +8 -1
  133. package/src/duckdb/src/main/config.cpp +66 -1
  134. package/src/duckdb/src/main/database.cpp +10 -2
  135. package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +98 -67
  136. package/src/duckdb/src/optimizer/join_order/join_order_optimizer.cpp +16 -3
  137. package/src/duckdb/src/optimizer/statistics/expression/propagate_aggregate.cpp +9 -3
  138. package/src/duckdb/src/optimizer/statistics/expression/propagate_and_compress.cpp +6 -7
  139. package/src/duckdb/src/optimizer/statistics/expression/propagate_cast.cpp +14 -11
  140. package/src/duckdb/src/optimizer/statistics/expression/propagate_columnref.cpp +1 -1
  141. package/src/duckdb/src/optimizer/statistics/expression/propagate_comparison.cpp +13 -15
  142. package/src/duckdb/src/optimizer/statistics/expression/propagate_conjunction.cpp +0 -1
  143. package/src/duckdb/src/optimizer/statistics/expression/propagate_constant.cpp +3 -75
  144. package/src/duckdb/src/optimizer/statistics/expression/propagate_function.cpp +7 -2
  145. package/src/duckdb/src/optimizer/statistics/expression/propagate_operator.cpp +10 -0
  146. package/src/duckdb/src/optimizer/statistics/operator/propagate_aggregate.cpp +2 -3
  147. package/src/duckdb/src/optimizer/statistics/operator/propagate_filter.cpp +28 -31
  148. package/src/duckdb/src/optimizer/statistics/operator/propagate_join.cpp +4 -5
  149. package/src/duckdb/src/optimizer/statistics/operator/propagate_set_operation.cpp +3 -3
  150. package/src/duckdb/src/optimizer/statistics_propagator.cpp +1 -1
  151. package/src/duckdb/src/parser/parsed_data/alter_info.cpp +7 -3
  152. package/src/duckdb/src/parser/parsed_data/alter_scalar_function_info.cpp +56 -0
  153. package/src/duckdb/src/parser/parsed_data/alter_table_function_info.cpp +51 -0
  154. package/src/duckdb/src/parser/parsed_data/create_scalar_function_info.cpp +3 -2
  155. package/src/duckdb/src/parser/parsed_data/create_table_function_info.cpp +6 -0
  156. package/src/duckdb/src/parser/parsed_expression_iterator.cpp +8 -0
  157. package/src/duckdb/src/parser/query_node.cpp +1 -1
  158. package/src/duckdb/src/parser/statement/multi_statement.cpp +18 -0
  159. package/src/duckdb/src/parser/tableref/pivotref.cpp +296 -0
  160. package/src/duckdb/src/parser/tableref.cpp +3 -0
  161. package/src/duckdb/src/parser/transform/helpers/transform_alias.cpp +12 -6
  162. package/src/duckdb/src/parser/transform/helpers/transform_cte.cpp +24 -0
  163. package/src/duckdb/src/parser/transform/statement/transform_create_function.cpp +4 -0
  164. package/src/duckdb/src/parser/transform/statement/transform_create_view.cpp +4 -0
  165. package/src/duckdb/src/parser/transform/statement/transform_pivot_stmt.cpp +150 -0
  166. package/src/duckdb/src/parser/transform/statement/transform_select.cpp +8 -0
  167. package/src/duckdb/src/parser/transform/statement/transform_select_node.cpp +1 -1
  168. package/src/duckdb/src/parser/transform/tableref/transform_join.cpp +4 -0
  169. package/src/duckdb/src/parser/transform/tableref/transform_pivot.cpp +105 -0
  170. package/src/duckdb/src/parser/transform/tableref/transform_tableref.cpp +2 -0
  171. package/src/duckdb/src/parser/transformer.cpp +15 -3
  172. package/src/duckdb/src/planner/bind_context.cpp +16 -0
  173. package/src/duckdb/src/planner/binder/query_node/bind_select_node.cpp +11 -3
  174. package/src/duckdb/src/planner/binder/query_node/plan_select_node.cpp +0 -1
  175. package/src/duckdb/src/planner/binder/statement/bind_create.cpp +1 -1
  176. package/src/duckdb/src/planner/binder/statement/bind_logical_plan.cpp +17 -0
  177. package/src/duckdb/src/planner/binder/tableref/bind_joinref.cpp +9 -0
  178. package/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp +365 -0
  179. package/src/duckdb/src/planner/binder.cpp +7 -1
  180. package/src/duckdb/src/planner/bound_result_modifier.cpp +1 -1
  181. package/src/duckdb/src/planner/expression/bound_window_expression.cpp +1 -1
  182. package/src/duckdb/src/planner/filter/constant_filter.cpp +4 -6
  183. package/src/duckdb/src/planner/pragma_handler.cpp +10 -2
  184. package/src/duckdb/src/storage/buffer_manager.cpp +44 -46
  185. package/src/duckdb/src/storage/checkpoint/row_group_writer.cpp +1 -1
  186. package/src/duckdb/src/storage/checkpoint/table_data_reader.cpp +1 -4
  187. package/src/duckdb/src/storage/checkpoint/table_data_writer.cpp +4 -4
  188. package/src/duckdb/src/storage/compression/bitpacking.cpp +28 -24
  189. package/src/duckdb/src/storage/compression/fixed_size_uncompressed.cpp +43 -45
  190. package/src/duckdb/src/storage/compression/numeric_constant.cpp +9 -10
  191. package/src/duckdb/src/storage/compression/patas.cpp +1 -1
  192. package/src/duckdb/src/storage/compression/rle.cpp +19 -15
  193. package/src/duckdb/src/storage/compression/validity_uncompressed.cpp +5 -5
  194. package/src/duckdb/src/storage/data_table.cpp +4 -6
  195. package/src/duckdb/src/storage/statistics/base_statistics.cpp +373 -128
  196. package/src/duckdb/src/storage/statistics/column_statistics.cpp +58 -3
  197. package/src/duckdb/src/storage/statistics/distinct_statistics.cpp +4 -9
  198. package/src/duckdb/src/storage/statistics/list_stats.cpp +117 -0
  199. package/src/duckdb/src/storage/statistics/numeric_stats.cpp +529 -0
  200. package/src/duckdb/src/storage/statistics/segment_statistics.cpp +2 -11
  201. package/src/duckdb/src/storage/statistics/string_stats.cpp +273 -0
  202. package/src/duckdb/src/storage/statistics/struct_stats.cpp +131 -0
  203. package/src/duckdb/src/storage/storage_info.cpp +1 -1
  204. package/src/duckdb/src/storage/table/column_checkpoint_state.cpp +3 -4
  205. package/src/duckdb/src/storage/table/column_data.cpp +16 -11
  206. package/src/duckdb/src/storage/table/column_data_checkpointer.cpp +2 -3
  207. package/src/duckdb/src/storage/table/column_segment.cpp +6 -8
  208. package/src/duckdb/src/storage/table/list_column_data.cpp +39 -58
  209. package/src/duckdb/src/storage/table/row_group.cpp +24 -23
  210. package/src/duckdb/src/storage/table/row_group_collection.cpp +12 -12
  211. package/src/duckdb/src/storage/table/standard_column_data.cpp +6 -6
  212. package/src/duckdb/src/storage/table/struct_column_data.cpp +15 -16
  213. package/src/duckdb/src/storage/table/table_statistics.cpp +27 -7
  214. package/src/duckdb/src/storage/table/update_segment.cpp +10 -12
  215. package/src/duckdb/third_party/libpg_query/include/nodes/nodes.hpp +3 -0
  216. package/src/duckdb/third_party/libpg_query/include/nodes/parsenodes.hpp +34 -1
  217. package/src/duckdb/third_party/libpg_query/include/parser/gram.hpp +1020 -530
  218. package/src/duckdb/third_party/libpg_query/include/parser/kwlist.hpp +7 -0
  219. package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +23560 -22737
  220. package/src/duckdb/ub_src_function_aggregate_distributive.cpp +2 -0
  221. package/src/duckdb/ub_src_function_scalar_bit.cpp +2 -0
  222. package/src/duckdb/ub_src_function_scalar_map.cpp +4 -0
  223. package/src/duckdb/ub_src_main_capi.cpp +2 -0
  224. package/src/duckdb/ub_src_parser_parsed_data.cpp +4 -2
  225. package/src/duckdb/ub_src_parser_statement.cpp +2 -0
  226. package/src/duckdb/ub_src_parser_tableref.cpp +2 -0
  227. package/src/duckdb/ub_src_parser_transform_statement.cpp +2 -0
  228. package/src/duckdb/ub_src_parser_transform_tableref.cpp +2 -0
  229. package/src/duckdb/ub_src_planner_binder_tableref.cpp +2 -0
  230. package/src/duckdb/ub_src_storage_statistics.cpp +4 -6
  231. package/src/duckdb/src/include/duckdb/main/loadable_extension.hpp +0 -59
  232. package/src/duckdb/src/include/duckdb/storage/statistics/list_statistics.hpp +0 -36
  233. package/src/duckdb/src/include/duckdb/storage/statistics/numeric_statistics.hpp +0 -75
  234. package/src/duckdb/src/include/duckdb/storage/statistics/string_statistics.hpp +0 -49
  235. package/src/duckdb/src/include/duckdb/storage/statistics/struct_statistics.hpp +0 -36
  236. package/src/duckdb/src/include/duckdb/storage/statistics/validity_statistics.hpp +0 -45
  237. package/src/duckdb/src/parser/parsed_data/alter_function_info.cpp +0 -55
  238. package/src/duckdb/src/storage/statistics/list_statistics.cpp +0 -94
  239. package/src/duckdb/src/storage/statistics/numeric_statistics.cpp +0 -307
  240. package/src/duckdb/src/storage/statistics/string_statistics.cpp +0 -220
  241. package/src/duckdb/src/storage/statistics/struct_statistics.cpp +0 -108
  242. package/src/duckdb/src/storage/statistics/validity_statistics.cpp +0 -91
@@ -0,0 +1,117 @@
1
+ #include "duckdb/storage/statistics/list_stats.hpp"
2
+ #include "duckdb/storage/statistics/base_statistics.hpp"
3
+ #include "duckdb/common/field_writer.hpp"
4
+ #include "duckdb/common/string_util.hpp"
5
+ #include "duckdb/common/types/vector.hpp"
6
+
7
+ namespace duckdb {
8
+
9
+ void ListStats::Construct(BaseStatistics &stats) {
10
+ stats.child_stats = unique_ptr<BaseStatistics[]>(new BaseStatistics[1]);
11
+ BaseStatistics::Construct(stats.child_stats[0], ListType::GetChildType(stats.GetType()));
12
+ }
13
+
14
+ BaseStatistics ListStats::CreateUnknown(LogicalType type) {
15
+ auto &child_type = ListType::GetChildType(type);
16
+ BaseStatistics result(std::move(type));
17
+ result.InitializeUnknown();
18
+ result.child_stats[0].Copy(BaseStatistics::CreateUnknown(child_type));
19
+ return result;
20
+ }
21
+
22
+ BaseStatistics ListStats::CreateEmpty(LogicalType type) {
23
+ auto &child_type = ListType::GetChildType(type);
24
+ BaseStatistics result(std::move(type));
25
+ result.InitializeEmpty();
26
+ result.child_stats[0].Copy(BaseStatistics::CreateEmpty(child_type));
27
+ return result;
28
+ }
29
+
30
+ void ListStats::Copy(BaseStatistics &stats, const BaseStatistics &other) {
31
+ D_ASSERT(stats.child_stats);
32
+ D_ASSERT(other.child_stats);
33
+ stats.child_stats[0].Copy(other.child_stats[0]);
34
+ }
35
+
36
+ const BaseStatistics &ListStats::GetChildStats(const BaseStatistics &stats) {
37
+ D_ASSERT(stats.GetStatsType() == StatisticsType::LIST_STATS);
38
+ D_ASSERT(stats.child_stats);
39
+ return stats.child_stats[0];
40
+ }
41
+ BaseStatistics &ListStats::GetChildStats(BaseStatistics &stats) {
42
+ D_ASSERT(stats.GetStatsType() == StatisticsType::LIST_STATS);
43
+ D_ASSERT(stats.child_stats);
44
+ return stats.child_stats[0];
45
+ }
46
+
47
+ void ListStats::SetChildStats(BaseStatistics &stats, unique_ptr<BaseStatistics> new_stats) {
48
+ if (!new_stats) {
49
+ stats.child_stats[0].Copy(BaseStatistics::CreateUnknown(ListType::GetChildType(stats.GetType())));
50
+ } else {
51
+ stats.child_stats[0].Copy(*new_stats);
52
+ }
53
+ }
54
+
55
+ void ListStats::Merge(BaseStatistics &stats, const BaseStatistics &other) {
56
+ if (other.GetType().id() == LogicalTypeId::VALIDITY) {
57
+ return;
58
+ }
59
+
60
+ auto &child_stats = ListStats::GetChildStats(stats);
61
+ auto &other_child_stats = ListStats::GetChildStats(other);
62
+ child_stats.Merge(other_child_stats);
63
+ }
64
+
65
+ void ListStats::Serialize(const BaseStatistics &stats, FieldWriter &writer) {
66
+ auto &child_stats = ListStats::GetChildStats(stats);
67
+ writer.WriteSerializable(child_stats);
68
+ }
69
+
70
+ BaseStatistics ListStats::Deserialize(FieldReader &reader, LogicalType type) {
71
+ D_ASSERT(type.InternalType() == PhysicalType::LIST);
72
+ auto &child_type = ListType::GetChildType(type);
73
+ BaseStatistics result(std::move(type));
74
+ result.child_stats[0].Copy(reader.ReadRequiredSerializable<BaseStatistics, BaseStatistics>(child_type));
75
+ return result;
76
+ }
77
+
78
+ string ListStats::ToString(const BaseStatistics &stats) {
79
+ auto &child_stats = ListStats::GetChildStats(stats);
80
+ return StringUtil::Format("[%s]", child_stats.ToString());
81
+ }
82
+
83
+ void ListStats::Verify(const BaseStatistics &stats, Vector &vector, const SelectionVector &sel, idx_t count) {
84
+ auto &child_stats = ListStats::GetChildStats(stats);
85
+ auto &child_entry = ListVector::GetEntry(vector);
86
+ UnifiedVectorFormat vdata;
87
+ vector.ToUnifiedFormat(count, vdata);
88
+
89
+ auto list_data = (list_entry_t *)vdata.data;
90
+ idx_t total_list_count = 0;
91
+ for (idx_t i = 0; i < count; i++) {
92
+ auto idx = sel.get_index(i);
93
+ auto index = vdata.sel->get_index(idx);
94
+ auto list = list_data[index];
95
+ if (vdata.validity.RowIsValid(index)) {
96
+ for (idx_t list_idx = 0; list_idx < list.length; list_idx++) {
97
+ total_list_count++;
98
+ }
99
+ }
100
+ }
101
+ SelectionVector list_sel(total_list_count);
102
+ idx_t list_count = 0;
103
+ for (idx_t i = 0; i < count; i++) {
104
+ auto idx = sel.get_index(i);
105
+ auto index = vdata.sel->get_index(idx);
106
+ auto list = list_data[index];
107
+ if (vdata.validity.RowIsValid(index)) {
108
+ for (idx_t list_idx = 0; list_idx < list.length; list_idx++) {
109
+ list_sel.set_index(list_count++, list.offset + list_idx);
110
+ }
111
+ }
112
+ }
113
+
114
+ child_stats.Verify(child_entry, list_sel, list_count);
115
+ }
116
+
117
+ } // namespace duckdb
@@ -0,0 +1,529 @@
1
+ #include "duckdb/storage/statistics/numeric_stats.hpp"
2
+ #include "duckdb/storage/statistics/base_statistics.hpp"
3
+ #include "duckdb/common/field_writer.hpp"
4
+ #include "duckdb/common/types/vector.hpp"
5
+
6
+ namespace duckdb {
7
+
8
+ template <>
9
+ void NumericStats::Update<interval_t>(BaseStatistics &stats, interval_t new_value) {
10
+ }
11
+
12
+ template <>
13
+ void NumericStats::Update<list_entry_t>(BaseStatistics &stats, list_entry_t new_value) {
14
+ }
15
+
16
+ BaseStatistics NumericStats::CreateUnknown(LogicalType type) {
17
+ BaseStatistics result(std::move(type));
18
+ result.InitializeUnknown();
19
+ SetMin(result, Value(result.GetType()));
20
+ SetMax(result, Value(result.GetType()));
21
+ return result;
22
+ }
23
+
24
+ BaseStatistics NumericStats::CreateEmpty(LogicalType type) {
25
+ BaseStatistics result(std::move(type));
26
+ result.InitializeEmpty();
27
+ SetMin(result, Value::MaximumValue(result.GetType()));
28
+ SetMax(result, Value::MinimumValue(result.GetType()));
29
+ return result;
30
+ }
31
+
32
+ NumericStatsData &NumericStats::GetDataUnsafe(BaseStatistics &stats) {
33
+ D_ASSERT(stats.GetStatsType() == StatisticsType::NUMERIC_STATS);
34
+ return stats.stats_union.numeric_data;
35
+ }
36
+
37
+ const NumericStatsData &NumericStats::GetDataUnsafe(const BaseStatistics &stats) {
38
+ D_ASSERT(stats.GetStatsType() == StatisticsType::NUMERIC_STATS);
39
+ return stats.stats_union.numeric_data;
40
+ }
41
+
42
+ void NumericStats::Merge(BaseStatistics &stats, const BaseStatistics &other) {
43
+ if (other.GetType().id() == LogicalTypeId::VALIDITY) {
44
+ return;
45
+ }
46
+ D_ASSERT(stats.GetType() == other.GetType());
47
+ if (NumericStats::HasMin(other) && NumericStats::HasMin(stats)) {
48
+ auto other_min = NumericStats::Min(other);
49
+ if (other_min < NumericStats::Min(stats)) {
50
+ NumericStats::SetMin(stats, other_min);
51
+ }
52
+ } else {
53
+ NumericStats::SetMin(stats, Value());
54
+ }
55
+ if (NumericStats::HasMax(other) && NumericStats::HasMax(stats)) {
56
+ auto other_max = NumericStats::Max(other);
57
+ if (other_max > NumericStats::Max(stats)) {
58
+ NumericStats::SetMax(stats, other_max);
59
+ }
60
+ } else {
61
+ NumericStats::SetMax(stats, Value());
62
+ }
63
+ }
64
+
65
+ FilterPropagateResult NumericStats::CheckZonemap(const BaseStatistics &stats, ExpressionType comparison_type,
66
+ const Value &constant) {
67
+ if (constant.IsNull()) {
68
+ return FilterPropagateResult::FILTER_ALWAYS_FALSE;
69
+ }
70
+ if (!NumericStats::HasMinMax(stats)) {
71
+ return FilterPropagateResult::NO_PRUNING_POSSIBLE;
72
+ }
73
+ auto min_value = NumericStats::Min(stats);
74
+ auto max_value = NumericStats::Max(stats);
75
+ switch (comparison_type) {
76
+ case ExpressionType::COMPARE_EQUAL:
77
+ if (constant == min_value && constant == max_value) {
78
+ return FilterPropagateResult::FILTER_ALWAYS_TRUE;
79
+ } else if (constant >= min_value && constant <= max_value) {
80
+ return FilterPropagateResult::NO_PRUNING_POSSIBLE;
81
+ } else {
82
+ return FilterPropagateResult::FILTER_ALWAYS_FALSE;
83
+ }
84
+ case ExpressionType::COMPARE_NOTEQUAL:
85
+ if (constant < min_value || constant > max_value) {
86
+ return FilterPropagateResult::FILTER_ALWAYS_TRUE;
87
+ } else if (min_value == max_value && min_value == constant) {
88
+ // corner case of a cluster with one numeric equal to the target constant
89
+ return FilterPropagateResult::FILTER_ALWAYS_FALSE;
90
+ }
91
+ return FilterPropagateResult::NO_PRUNING_POSSIBLE;
92
+ case ExpressionType::COMPARE_GREATERTHANOREQUALTO:
93
+ // X >= C
94
+ // this can be true only if max(X) >= C
95
+ // if min(X) >= C, then this is always true
96
+ if (min_value >= constant) {
97
+ return FilterPropagateResult::FILTER_ALWAYS_TRUE;
98
+ } else if (max_value >= constant) {
99
+ return FilterPropagateResult::NO_PRUNING_POSSIBLE;
100
+ } else {
101
+ return FilterPropagateResult::FILTER_ALWAYS_FALSE;
102
+ }
103
+ case ExpressionType::COMPARE_GREATERTHAN:
104
+ // X > C
105
+ // this can be true only if max(X) > C
106
+ // if min(X) > C, then this is always true
107
+ if (min_value > constant) {
108
+ return FilterPropagateResult::FILTER_ALWAYS_TRUE;
109
+ } else if (max_value > constant) {
110
+ return FilterPropagateResult::NO_PRUNING_POSSIBLE;
111
+ } else {
112
+ return FilterPropagateResult::FILTER_ALWAYS_FALSE;
113
+ }
114
+ case ExpressionType::COMPARE_LESSTHANOREQUALTO:
115
+ // X <= C
116
+ // this can be true only if min(X) <= C
117
+ // if max(X) <= C, then this is always true
118
+ if (max_value <= constant) {
119
+ return FilterPropagateResult::FILTER_ALWAYS_TRUE;
120
+ } else if (min_value <= constant) {
121
+ return FilterPropagateResult::NO_PRUNING_POSSIBLE;
122
+ } else {
123
+ return FilterPropagateResult::FILTER_ALWAYS_FALSE;
124
+ }
125
+ case ExpressionType::COMPARE_LESSTHAN:
126
+ // X < C
127
+ // this can be true only if min(X) < C
128
+ // if max(X) < C, then this is always true
129
+ if (max_value < constant) {
130
+ return FilterPropagateResult::FILTER_ALWAYS_TRUE;
131
+ } else if (min_value < constant) {
132
+ return FilterPropagateResult::NO_PRUNING_POSSIBLE;
133
+ } else {
134
+ return FilterPropagateResult::FILTER_ALWAYS_FALSE;
135
+ }
136
+ default:
137
+ throw InternalException("Expression type in zonemap check not implemented");
138
+ }
139
+ }
140
+
141
+ bool NumericStats::IsConstant(const BaseStatistics &stats) {
142
+ return NumericStats::Max(stats) <= NumericStats::Min(stats);
143
+ }
144
+
145
+ void SetNumericValueInternal(const Value &input, const LogicalType &type, NumericValueUnion &val, bool &has_val) {
146
+ if (input.IsNull()) {
147
+ has_val = false;
148
+ return;
149
+ }
150
+ if (input.type().InternalType() != type.InternalType()) {
151
+ throw InternalException("SetMin or SetMax called with Value that does not match statistics' column value");
152
+ }
153
+ has_val = true;
154
+ switch (type.InternalType()) {
155
+ case PhysicalType::BOOL:
156
+ val.value_.boolean = BooleanValue::Get(input);
157
+ break;
158
+ case PhysicalType::INT8:
159
+ val.value_.tinyint = TinyIntValue::Get(input);
160
+ break;
161
+ case PhysicalType::INT16:
162
+ val.value_.smallint = SmallIntValue::Get(input);
163
+ break;
164
+ case PhysicalType::INT32:
165
+ val.value_.integer = IntegerValue::Get(input);
166
+ break;
167
+ case PhysicalType::INT64:
168
+ val.value_.bigint = BigIntValue::Get(input);
169
+ break;
170
+ case PhysicalType::UINT8:
171
+ val.value_.utinyint = UTinyIntValue::Get(input);
172
+ break;
173
+ case PhysicalType::UINT16:
174
+ val.value_.usmallint = USmallIntValue::Get(input);
175
+ break;
176
+ case PhysicalType::UINT32:
177
+ val.value_.uinteger = UIntegerValue::Get(input);
178
+ break;
179
+ case PhysicalType::UINT64:
180
+ val.value_.ubigint = UBigIntValue::Get(input);
181
+ break;
182
+ case PhysicalType::INT128:
183
+ val.value_.hugeint = HugeIntValue::Get(input);
184
+ break;
185
+ case PhysicalType::FLOAT:
186
+ val.value_.float_ = FloatValue::Get(input);
187
+ break;
188
+ case PhysicalType::DOUBLE:
189
+ val.value_.double_ = DoubleValue::Get(input);
190
+ break;
191
+ default:
192
+ throw InternalException("Unsupported type for NumericStatistics::SetValueInternal");
193
+ }
194
+ }
195
+
196
+ void NumericStats::SetMin(BaseStatistics &stats, const Value &new_min) {
197
+ auto &data = NumericStats::GetDataUnsafe(stats);
198
+ SetNumericValueInternal(new_min, stats.GetType(), data.min, data.has_min);
199
+ }
200
+
201
+ void NumericStats::SetMax(BaseStatistics &stats, const Value &new_max) {
202
+ auto &data = NumericStats::GetDataUnsafe(stats);
203
+ SetNumericValueInternal(new_max, stats.GetType(), data.max, data.has_max);
204
+ }
205
+
206
+ Value NumericValueUnionToValueInternal(const LogicalType &type, const NumericValueUnion &val) {
207
+ switch (type.InternalType()) {
208
+ case PhysicalType::BOOL:
209
+ return Value::BOOLEAN(val.value_.boolean);
210
+ case PhysicalType::INT8:
211
+ return Value::TINYINT(val.value_.tinyint);
212
+ case PhysicalType::INT16:
213
+ return Value::SMALLINT(val.value_.smallint);
214
+ case PhysicalType::INT32:
215
+ return Value::INTEGER(val.value_.integer);
216
+ case PhysicalType::INT64:
217
+ return Value::BIGINT(val.value_.bigint);
218
+ case PhysicalType::UINT8:
219
+ return Value::UTINYINT(val.value_.utinyint);
220
+ case PhysicalType::UINT16:
221
+ return Value::USMALLINT(val.value_.usmallint);
222
+ case PhysicalType::UINT32:
223
+ return Value::UINTEGER(val.value_.uinteger);
224
+ case PhysicalType::UINT64:
225
+ return Value::UBIGINT(val.value_.ubigint);
226
+ case PhysicalType::INT128:
227
+ return Value::HUGEINT(val.value_.hugeint);
228
+ case PhysicalType::FLOAT:
229
+ return Value::FLOAT(val.value_.float_);
230
+ case PhysicalType::DOUBLE:
231
+ return Value::DOUBLE(val.value_.double_);
232
+ default:
233
+ throw InternalException("Unsupported type for NumericValueUnionToValue");
234
+ }
235
+ }
236
+
237
+ Value NumericValueUnionToValue(const LogicalType &type, const NumericValueUnion &val) {
238
+ Value result = NumericValueUnionToValueInternal(type, val);
239
+ result.GetTypeMutable() = type;
240
+ return result;
241
+ }
242
+
243
+ bool NumericStats::HasMinMax(const BaseStatistics &stats) {
244
+ return NumericStats::HasMin(stats) && NumericStats::HasMax(stats);
245
+ }
246
+
247
+ bool NumericStats::HasMin(const BaseStatistics &stats) {
248
+ if (stats.GetType().id() == LogicalTypeId::SQLNULL) {
249
+ return false;
250
+ }
251
+ return NumericStats::GetDataUnsafe(stats).has_min;
252
+ }
253
+
254
+ bool NumericStats::HasMax(const BaseStatistics &stats) {
255
+ if (stats.GetType().id() == LogicalTypeId::SQLNULL) {
256
+ return false;
257
+ }
258
+ return NumericStats::GetDataUnsafe(stats).has_max;
259
+ }
260
+
261
+ Value NumericStats::Min(const BaseStatistics &stats) {
262
+ if (!NumericStats::HasMin(stats)) {
263
+ throw InternalException("Min() called on statistics that does not have min");
264
+ }
265
+ return NumericValueUnionToValue(stats.GetType(), NumericStats::GetDataUnsafe(stats).min);
266
+ }
267
+
268
+ Value NumericStats::Max(const BaseStatistics &stats) {
269
+ if (!NumericStats::HasMax(stats)) {
270
+ throw InternalException("Max() called on statistics that does not have max");
271
+ }
272
+ return NumericValueUnionToValue(stats.GetType(), NumericStats::GetDataUnsafe(stats).max);
273
+ }
274
+
275
+ Value NumericStats::MinOrNull(const BaseStatistics &stats) {
276
+ if (!NumericStats::HasMin(stats)) {
277
+ return Value(stats.GetType());
278
+ }
279
+ return NumericStats::Min(stats);
280
+ }
281
+
282
+ Value NumericStats::MaxOrNull(const BaseStatistics &stats) {
283
+ if (!NumericStats::HasMax(stats)) {
284
+ return Value(stats.GetType());
285
+ }
286
+ return NumericStats::Max(stats);
287
+ }
288
+
289
+ void SerializeNumericStatsValue(const LogicalType &type, NumericValueUnion val, bool has_value, FieldWriter &writer) {
290
+ writer.WriteField<bool>(!has_value);
291
+ if (!has_value) {
292
+ return;
293
+ }
294
+ switch (type.InternalType()) {
295
+ case PhysicalType::BOOL:
296
+ writer.WriteField<bool>(val.value_.boolean);
297
+ break;
298
+ case PhysicalType::INT8:
299
+ writer.WriteField<int8_t>(val.value_.tinyint);
300
+ break;
301
+ case PhysicalType::INT16:
302
+ writer.WriteField<int16_t>(val.value_.smallint);
303
+ break;
304
+ case PhysicalType::INT32:
305
+ writer.WriteField<int32_t>(val.value_.integer);
306
+ break;
307
+ case PhysicalType::INT64:
308
+ writer.WriteField<int64_t>(val.value_.bigint);
309
+ break;
310
+ case PhysicalType::UINT8:
311
+ writer.WriteField<int8_t>(val.value_.utinyint);
312
+ break;
313
+ case PhysicalType::UINT16:
314
+ writer.WriteField<int16_t>(val.value_.usmallint);
315
+ break;
316
+ case PhysicalType::UINT32:
317
+ writer.WriteField<int32_t>(val.value_.uinteger);
318
+ break;
319
+ case PhysicalType::UINT64:
320
+ writer.WriteField<int64_t>(val.value_.ubigint);
321
+ break;
322
+ case PhysicalType::INT128:
323
+ writer.WriteField<hugeint_t>(val.value_.hugeint);
324
+ break;
325
+ case PhysicalType::FLOAT:
326
+ writer.WriteField<float>(val.value_.float_);
327
+ break;
328
+ case PhysicalType::DOUBLE:
329
+ writer.WriteField<double>(val.value_.double_);
330
+ break;
331
+ default:
332
+ throw InternalException("Unsupported type for serializing numeric statistics");
333
+ }
334
+ }
335
+
336
+ void NumericStats::Serialize(const BaseStatistics &stats, FieldWriter &writer) {
337
+ auto &numeric_stats = NumericStats::GetDataUnsafe(stats);
338
+ SerializeNumericStatsValue(stats.GetType(), numeric_stats.min, numeric_stats.has_min, writer);
339
+ SerializeNumericStatsValue(stats.GetType(), numeric_stats.max, numeric_stats.has_max, writer);
340
+ }
341
+
342
+ void DeserializeNumericStatsValue(const LogicalType &type, FieldReader &reader, NumericValueUnion &result,
343
+ bool &has_stats) {
344
+ auto is_null = reader.ReadRequired<bool>();
345
+ if (is_null) {
346
+ has_stats = false;
347
+ return;
348
+ }
349
+ has_stats = true;
350
+ switch (type.InternalType()) {
351
+ case PhysicalType::BOOL:
352
+ result.value_.boolean = reader.ReadRequired<bool>();
353
+ break;
354
+ case PhysicalType::INT8:
355
+ result.value_.tinyint = reader.ReadRequired<int8_t>();
356
+ break;
357
+ case PhysicalType::INT16:
358
+ result.value_.smallint = reader.ReadRequired<int16_t>();
359
+ break;
360
+ case PhysicalType::INT32:
361
+ result.value_.integer = reader.ReadRequired<int32_t>();
362
+ break;
363
+ case PhysicalType::INT64:
364
+ result.value_.bigint = reader.ReadRequired<int64_t>();
365
+ break;
366
+ case PhysicalType::UINT8:
367
+ result.value_.utinyint = reader.ReadRequired<uint8_t>();
368
+ break;
369
+ case PhysicalType::UINT16:
370
+ result.value_.usmallint = reader.ReadRequired<uint16_t>();
371
+ break;
372
+ case PhysicalType::UINT32:
373
+ result.value_.uinteger = reader.ReadRequired<uint32_t>();
374
+ break;
375
+ case PhysicalType::UINT64:
376
+ result.value_.ubigint = reader.ReadRequired<uint64_t>();
377
+ break;
378
+ case PhysicalType::INT128:
379
+ result.value_.hugeint = reader.ReadRequired<hugeint_t>();
380
+ break;
381
+ case PhysicalType::FLOAT:
382
+ result.value_.float_ = reader.ReadRequired<float>();
383
+ break;
384
+ case PhysicalType::DOUBLE:
385
+ result.value_.double_ = reader.ReadRequired<double>();
386
+ break;
387
+ default:
388
+ throw InternalException("Unsupported type for deserializing numeric statistics");
389
+ }
390
+ }
391
+
392
+ BaseStatistics NumericStats::Deserialize(FieldReader &reader, LogicalType type) {
393
+ BaseStatistics result(std::move(type));
394
+ auto &numeric_stats = NumericStats::GetDataUnsafe(result);
395
+ DeserializeNumericStatsValue(result.GetType(), reader, numeric_stats.min, numeric_stats.has_min);
396
+ DeserializeNumericStatsValue(result.GetType(), reader, numeric_stats.max, numeric_stats.has_max);
397
+ return result;
398
+ }
399
+
400
+ string NumericStats::ToString(const BaseStatistics &stats) {
401
+ return StringUtil::Format("[Min: %s, Max: %s]", NumericStats::MinOrNull(stats).ToString(),
402
+ NumericStats::MaxOrNull(stats).ToString());
403
+ }
404
+
405
+ template <class T>
406
+ void NumericStats::TemplatedVerify(const BaseStatistics &stats, Vector &vector, const SelectionVector &sel,
407
+ idx_t count) {
408
+ UnifiedVectorFormat vdata;
409
+ vector.ToUnifiedFormat(count, vdata);
410
+
411
+ auto data = (T *)vdata.data;
412
+ auto min_value = NumericStats::MinOrNull(stats);
413
+ auto max_value = NumericStats::MaxOrNull(stats);
414
+ for (idx_t i = 0; i < count; i++) {
415
+ auto idx = sel.get_index(i);
416
+ auto index = vdata.sel->get_index(idx);
417
+ if (!vdata.validity.RowIsValid(index)) {
418
+ continue;
419
+ }
420
+ if (!min_value.IsNull() && LessThan::Operation(data[index], min_value.GetValueUnsafe<T>())) { // LCOV_EXCL_START
421
+ throw InternalException("Statistics mismatch: value is smaller than min.\nStatistics: %s\nVector: %s",
422
+ stats.ToString(), vector.ToString(count));
423
+ } // LCOV_EXCL_STOP
424
+ if (!max_value.IsNull() && GreaterThan::Operation(data[index], max_value.GetValueUnsafe<T>())) {
425
+ throw InternalException("Statistics mismatch: value is bigger than max.\nStatistics: %s\nVector: %s",
426
+ stats.ToString(), vector.ToString(count));
427
+ }
428
+ }
429
+ }
430
+
431
+ void NumericStats::Verify(const BaseStatistics &stats, Vector &vector, const SelectionVector &sel, idx_t count) {
432
+ auto &type = stats.GetType();
433
+ switch (type.InternalType()) {
434
+ case PhysicalType::BOOL:
435
+ break;
436
+ case PhysicalType::INT8:
437
+ TemplatedVerify<int8_t>(stats, vector, sel, count);
438
+ break;
439
+ case PhysicalType::INT16:
440
+ TemplatedVerify<int16_t>(stats, vector, sel, count);
441
+ break;
442
+ case PhysicalType::INT32:
443
+ TemplatedVerify<int32_t>(stats, vector, sel, count);
444
+ break;
445
+ case PhysicalType::INT64:
446
+ TemplatedVerify<int64_t>(stats, vector, sel, count);
447
+ break;
448
+ case PhysicalType::UINT8:
449
+ TemplatedVerify<uint8_t>(stats, vector, sel, count);
450
+ break;
451
+ case PhysicalType::UINT16:
452
+ TemplatedVerify<uint16_t>(stats, vector, sel, count);
453
+ break;
454
+ case PhysicalType::UINT32:
455
+ TemplatedVerify<uint32_t>(stats, vector, sel, count);
456
+ break;
457
+ case PhysicalType::UINT64:
458
+ TemplatedVerify<uint64_t>(stats, vector, sel, count);
459
+ break;
460
+ case PhysicalType::INT128:
461
+ TemplatedVerify<hugeint_t>(stats, vector, sel, count);
462
+ break;
463
+ case PhysicalType::FLOAT:
464
+ TemplatedVerify<float>(stats, vector, sel, count);
465
+ break;
466
+ case PhysicalType::DOUBLE:
467
+ TemplatedVerify<double>(stats, vector, sel, count);
468
+ break;
469
+ default:
470
+ throw InternalException("Unsupported type %s for numeric statistics verify", type.ToString());
471
+ }
472
+ }
473
+
474
+ template <>
475
+ int8_t &NumericValueUnion::GetReferenceUnsafe() {
476
+ return value_.tinyint;
477
+ }
478
+
479
+ template <>
480
+ int16_t &NumericValueUnion::GetReferenceUnsafe() {
481
+ return value_.smallint;
482
+ }
483
+
484
+ template <>
485
+ int32_t &NumericValueUnion::GetReferenceUnsafe() {
486
+ return value_.integer;
487
+ }
488
+
489
+ template <>
490
+ int64_t &NumericValueUnion::GetReferenceUnsafe() {
491
+ return value_.bigint;
492
+ }
493
+
494
+ template <>
495
+ hugeint_t &NumericValueUnion::GetReferenceUnsafe() {
496
+ return value_.hugeint;
497
+ }
498
+
499
+ template <>
500
+ uint8_t &NumericValueUnion::GetReferenceUnsafe() {
501
+ return value_.utinyint;
502
+ }
503
+
504
+ template <>
505
+ uint16_t &NumericValueUnion::GetReferenceUnsafe() {
506
+ return value_.usmallint;
507
+ }
508
+
509
+ template <>
510
+ uint32_t &NumericValueUnion::GetReferenceUnsafe() {
511
+ return value_.uinteger;
512
+ }
513
+
514
+ template <>
515
+ uint64_t &NumericValueUnion::GetReferenceUnsafe() {
516
+ return value_.ubigint;
517
+ }
518
+
519
+ template <>
520
+ float &NumericValueUnion::GetReferenceUnsafe() {
521
+ return value_.float_;
522
+ }
523
+
524
+ template <>
525
+ double &NumericValueUnion::GetReferenceUnsafe() {
526
+ return value_.double_;
527
+ }
528
+
529
+ } // namespace duckdb
@@ -4,19 +4,10 @@
4
4
 
5
5
  namespace duckdb {
6
6
 
7
- SegmentStatistics::SegmentStatistics(LogicalType type) : type(std::move(type)) {
8
- Reset();
7
+ SegmentStatistics::SegmentStatistics(LogicalType type) : statistics(BaseStatistics::CreateEmpty(std::move(type))) {
9
8
  }
10
9
 
11
- SegmentStatistics::SegmentStatistics(LogicalType type, unique_ptr<BaseStatistics> stats)
12
- : type(std::move(type)), statistics(std::move(stats)) {
13
- if (!statistics) {
14
- Reset();
15
- }
16
- }
17
-
18
- void SegmentStatistics::Reset() {
19
- statistics = BaseStatistics::CreateEmpty(type, StatisticsType::LOCAL_STATS);
10
+ SegmentStatistics::SegmentStatistics(BaseStatistics stats) : statistics(std::move(stats)) {
20
11
  }
21
12
 
22
13
  } // namespace duckdb