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
@@ -1,15 +1,14 @@
1
1
  #include "duckdb/optimizer/statistics_propagator.hpp"
2
2
  #include "duckdb/planner/expression/bound_comparison_expression.hpp"
3
3
  #include "duckdb/planner/expression/bound_constant_expression.hpp"
4
- #include "duckdb/storage/statistics/numeric_statistics.hpp"
5
4
  #include "duckdb/optimizer/expression_rewriter.hpp"
6
5
 
7
6
  namespace duckdb {
8
7
 
9
- FilterPropagateResult StatisticsPropagator::PropagateComparison(BaseStatistics &left, BaseStatistics &right,
8
+ FilterPropagateResult StatisticsPropagator::PropagateComparison(BaseStatistics &lstats, BaseStatistics &rstats,
10
9
  ExpressionType comparison) {
11
10
  // only handle numerics for now
12
- switch (left.type.InternalType()) {
11
+ switch (lstats.GetType().InternalType()) {
13
12
  case PhysicalType::BOOL:
14
13
  case PhysicalType::UINT8:
15
14
  case PhysicalType::UINT16:
@@ -26,9 +25,7 @@ FilterPropagateResult StatisticsPropagator::PropagateComparison(BaseStatistics &
26
25
  default:
27
26
  return FilterPropagateResult::NO_PRUNING_POSSIBLE;
28
27
  }
29
- auto &lstats = (NumericStatistics &)left;
30
- auto &rstats = (NumericStatistics &)right;
31
- if (lstats.min.IsNull() || lstats.max.IsNull() || rstats.min.IsNull() || rstats.max.IsNull()) {
28
+ if (!NumericStats::HasMinMax(lstats) || !NumericStats::HasMinMax(rstats)) {
32
29
  // no stats available: nothing to prune
33
30
  return FilterPropagateResult::NO_PRUNING_POSSIBLE;
34
31
  }
@@ -38,52 +35,53 @@ FilterPropagateResult StatisticsPropagator::PropagateComparison(BaseStatistics &
38
35
  switch (comparison) {
39
36
  case ExpressionType::COMPARE_EQUAL:
40
37
  // l = r, if l.min > r.max or r.min > l.max equality is not possible
41
- if (lstats.min > rstats.max || rstats.min > lstats.max) {
38
+ if (NumericStats::Min(lstats) > NumericStats::Max(rstats) ||
39
+ NumericStats::Min(rstats) > NumericStats::Max(lstats)) {
42
40
  return has_null ? FilterPropagateResult::FILTER_FALSE_OR_NULL : FilterPropagateResult::FILTER_ALWAYS_FALSE;
43
41
  } else {
44
42
  return FilterPropagateResult::NO_PRUNING_POSSIBLE;
45
43
  }
46
44
  case ExpressionType::COMPARE_GREATERTHAN:
47
45
  // l > r
48
- if (lstats.min > rstats.max) {
46
+ if (NumericStats::Min(lstats) > NumericStats::Max(rstats)) {
49
47
  // if l.min > r.max, it is always true ONLY if neither side contains nulls
50
48
  return has_null ? FilterPropagateResult::FILTER_TRUE_OR_NULL : FilterPropagateResult::FILTER_ALWAYS_TRUE;
51
49
  }
52
50
  // if r.min is bigger or equal to l.max, the filter is always false
53
- if (rstats.min >= lstats.max) {
51
+ if (NumericStats::Min(rstats) >= NumericStats::Max(lstats)) {
54
52
  return has_null ? FilterPropagateResult::FILTER_FALSE_OR_NULL : FilterPropagateResult::FILTER_ALWAYS_FALSE;
55
53
  }
56
54
  return FilterPropagateResult::NO_PRUNING_POSSIBLE;
57
55
  case ExpressionType::COMPARE_GREATERTHANOREQUALTO:
58
56
  // l >= r
59
- if (lstats.min >= rstats.max) {
57
+ if (NumericStats::Min(lstats) >= NumericStats::Max(rstats)) {
60
58
  // if l.min >= r.max, it is always true ONLY if neither side contains nulls
61
59
  return has_null ? FilterPropagateResult::FILTER_TRUE_OR_NULL : FilterPropagateResult::FILTER_ALWAYS_TRUE;
62
60
  }
63
61
  // if r.min > l.max, the filter is always false
64
- if (rstats.min > lstats.max) {
62
+ if (NumericStats::Min(rstats) > NumericStats::Max(lstats)) {
65
63
  return has_null ? FilterPropagateResult::FILTER_FALSE_OR_NULL : FilterPropagateResult::FILTER_ALWAYS_FALSE;
66
64
  }
67
65
  return FilterPropagateResult::NO_PRUNING_POSSIBLE;
68
66
  case ExpressionType::COMPARE_LESSTHAN:
69
67
  // l < r
70
- if (lstats.max < rstats.min) {
68
+ if (NumericStats::Max(lstats) < NumericStats::Min(rstats)) {
71
69
  // if l.max < r.min, it is always true ONLY if neither side contains nulls
72
70
  return has_null ? FilterPropagateResult::FILTER_TRUE_OR_NULL : FilterPropagateResult::FILTER_ALWAYS_TRUE;
73
71
  }
74
72
  // if l.min >= rstats.max, the filter is always false
75
- if (lstats.min >= rstats.max) {
73
+ if (NumericStats::Min(lstats) >= NumericStats::Max(rstats)) {
76
74
  return has_null ? FilterPropagateResult::FILTER_FALSE_OR_NULL : FilterPropagateResult::FILTER_ALWAYS_FALSE;
77
75
  }
78
76
  return FilterPropagateResult::NO_PRUNING_POSSIBLE;
79
77
  case ExpressionType::COMPARE_LESSTHANOREQUALTO:
80
78
  // l <= r
81
- if (lstats.max <= rstats.min) {
79
+ if (NumericStats::Max(lstats) <= NumericStats::Min(rstats)) {
82
80
  // if l.max <= r.min, it is always true ONLY if neither side contains nulls
83
81
  return has_null ? FilterPropagateResult::FILTER_TRUE_OR_NULL : FilterPropagateResult::FILTER_ALWAYS_TRUE;
84
82
  }
85
83
  // if l.min > rstats.max, the filter is always false
86
- if (lstats.min > rstats.max) {
84
+ if (NumericStats::Min(lstats) > NumericStats::Max(rstats)) {
87
85
  return has_null ? FilterPropagateResult::FILTER_FALSE_OR_NULL : FilterPropagateResult::FILTER_ALWAYS_FALSE;
88
86
  }
89
87
  return FilterPropagateResult::NO_PRUNING_POSSIBLE;
@@ -2,7 +2,6 @@
2
2
  #include "duckdb/optimizer/statistics_propagator.hpp"
3
3
  #include "duckdb/planner/expression/bound_conjunction_expression.hpp"
4
4
  #include "duckdb/planner/expression/bound_constant_expression.hpp"
5
- #include "duckdb/storage/statistics/numeric_statistics.hpp"
6
5
  #include "duckdb/optimizer/expression_rewriter.hpp"
7
6
  #include "duckdb/execution/expression_executor.hpp"
8
7
 
@@ -1,85 +1,13 @@
1
1
  #include "duckdb/optimizer/statistics_propagator.hpp"
2
2
  #include "duckdb/planner/expression/bound_constant_expression.hpp"
3
3
  #include "duckdb/storage/statistics/distinct_statistics.hpp"
4
- #include "duckdb/storage/statistics/list_statistics.hpp"
5
- #include "duckdb/storage/statistics/numeric_statistics.hpp"
6
- #include "duckdb/storage/statistics/string_statistics.hpp"
7
- #include "duckdb/storage/statistics/struct_statistics.hpp"
4
+ #include "duckdb/storage/statistics/list_stats.hpp"
5
+ #include "duckdb/storage/statistics/struct_stats.hpp"
8
6
 
9
7
  namespace duckdb {
10
8
 
11
- void UpdateDistinctStats(BaseStatistics &distinct_stats, const Value &input) {
12
- Vector v(input);
13
- auto &d_stats = (DistinctStatistics &)distinct_stats;
14
- d_stats.Update(v, 1);
15
- }
16
-
17
9
  unique_ptr<BaseStatistics> StatisticsPropagator::StatisticsFromValue(const Value &input) {
18
- switch (input.type().InternalType()) {
19
- case PhysicalType::BOOL:
20
- case PhysicalType::UINT8:
21
- case PhysicalType::UINT16:
22
- case PhysicalType::UINT32:
23
- case PhysicalType::UINT64:
24
- case PhysicalType::INT8:
25
- case PhysicalType::INT16:
26
- case PhysicalType::INT32:
27
- case PhysicalType::INT64:
28
- case PhysicalType::INT128:
29
- case PhysicalType::FLOAT:
30
- case PhysicalType::DOUBLE: {
31
- auto result = make_unique<NumericStatistics>(input.type(), input, input, StatisticsType::GLOBAL_STATS);
32
- result->validity_stats = make_unique<ValidityStatistics>(input.IsNull(), !input.IsNull());
33
- UpdateDistinctStats(*result->distinct_stats, input);
34
- return std::move(result);
35
- }
36
- case PhysicalType::VARCHAR: {
37
- auto result = make_unique<StringStatistics>(input.type(), StatisticsType::GLOBAL_STATS);
38
- result->validity_stats = make_unique<ValidityStatistics>(input.IsNull(), !input.IsNull());
39
- UpdateDistinctStats(*result->distinct_stats, input);
40
- if (!input.IsNull()) {
41
- auto &string_value = StringValue::Get(input);
42
- result->Update(string_t(string_value));
43
- }
44
- return std::move(result);
45
- }
46
- case PhysicalType::STRUCT: {
47
- auto result = make_unique<StructStatistics>(input.type());
48
- result->validity_stats = make_unique<ValidityStatistics>(input.IsNull(), !input.IsNull());
49
- if (input.IsNull()) {
50
- for (auto &child_stat : result->child_stats) {
51
- child_stat.reset();
52
- }
53
- } else {
54
- auto &struct_children = StructValue::GetChildren(input);
55
- D_ASSERT(result->child_stats.size() == struct_children.size());
56
- for (idx_t i = 0; i < result->child_stats.size(); i++) {
57
- result->child_stats[i] = StatisticsFromValue(struct_children[i]);
58
- }
59
- }
60
- return std::move(result);
61
- }
62
- case PhysicalType::LIST: {
63
- auto result = make_unique<ListStatistics>(input.type());
64
- result->validity_stats = make_unique<ValidityStatistics>(input.IsNull(), !input.IsNull());
65
- if (input.IsNull()) {
66
- result->child_stats.reset();
67
- } else {
68
- auto &list_children = ListValue::GetChildren(input);
69
- for (auto &child_element : list_children) {
70
- auto child_element_stats = StatisticsFromValue(child_element);
71
- if (child_element_stats) {
72
- result->child_stats->Merge(*child_element_stats);
73
- } else {
74
- result->child_stats.reset();
75
- }
76
- }
77
- }
78
- return std::move(result);
79
- }
80
- default:
81
- return nullptr;
82
- }
10
+ return BaseStatistics::FromConstant(input).ToUnique();
83
11
  }
84
12
 
85
13
  unique_ptr<BaseStatistics> StatisticsPropagator::PropagateExpression(BoundConstantExpression &constant,
@@ -5,10 +5,15 @@ namespace duckdb {
5
5
 
6
6
  unique_ptr<BaseStatistics> StatisticsPropagator::PropagateExpression(BoundFunctionExpression &func,
7
7
  unique_ptr<Expression> *expr_ptr) {
8
- vector<unique_ptr<BaseStatistics>> stats;
8
+ vector<BaseStatistics> stats;
9
9
  stats.reserve(func.children.size());
10
10
  for (idx_t i = 0; i < func.children.size(); i++) {
11
- stats.push_back(PropagateExpression(func.children[i]));
11
+ auto stat = PropagateExpression(func.children[i]);
12
+ if (!stat) {
13
+ stats.push_back(BaseStatistics::CreateUnknown(func.children[i]->return_type));
14
+ } else {
15
+ stats.push_back(stat->Copy());
16
+ }
12
17
  }
13
18
  if (!func.function.statistics) {
14
19
  return nullptr;
@@ -62,6 +62,11 @@ unique_ptr<BaseStatistics> StatisticsPropagator::PropagateExpression(BoundOperat
62
62
  *expr_ptr = make_unique<BoundConstantExpression>(Value::BOOLEAN(false));
63
63
  return PropagateExpression(*expr_ptr);
64
64
  }
65
+ if (!child_stats[0]->CanHaveNoNull()) {
66
+ // child has no valid values: x IS NULL will always be true
67
+ *expr_ptr = make_unique<BoundConstantExpression>(Value::BOOLEAN(true));
68
+ return PropagateExpression(*expr_ptr);
69
+ }
65
70
  return nullptr;
66
71
  case ExpressionType::OPERATOR_IS_NOT_NULL:
67
72
  if (!child_stats[0]->CanHaveNull()) {
@@ -69,6 +74,11 @@ unique_ptr<BaseStatistics> StatisticsPropagator::PropagateExpression(BoundOperat
69
74
  *expr_ptr = make_unique<BoundConstantExpression>(Value::BOOLEAN(true));
70
75
  return PropagateExpression(*expr_ptr);
71
76
  }
77
+ if (!child_stats[0]->CanHaveNoNull()) {
78
+ // child has no valid values: x IS NOT NULL will always be false
79
+ *expr_ptr = make_unique<BoundConstantExpression>(Value::BOOLEAN(false));
80
+ return PropagateExpression(*expr_ptr);
81
+ }
72
82
  return nullptr;
73
83
  default:
74
84
  return nullptr;
@@ -1,6 +1,5 @@
1
1
  #include "duckdb/optimizer/statistics_propagator.hpp"
2
2
  #include "duckdb/planner/operator/logical_aggregate.hpp"
3
- #include "duckdb/storage/statistics/validity_statistics.hpp"
4
3
 
5
4
  namespace duckdb {
6
5
 
@@ -13,14 +12,14 @@ unique_ptr<NodeStatistics> StatisticsPropagator::PropagateStatistics(LogicalAggr
13
12
  aggr.group_stats.resize(aggr.groups.size());
14
13
  for (idx_t group_idx = 0; group_idx < aggr.groups.size(); group_idx++) {
15
14
  auto stats = PropagateExpression(aggr.groups[group_idx]);
16
- aggr.group_stats[group_idx] = stats ? stats->Copy() : nullptr;
15
+ aggr.group_stats[group_idx] = stats ? stats->ToUnique() : nullptr;
17
16
  if (!stats) {
18
17
  continue;
19
18
  }
20
19
  if (aggr.grouping_sets.size() > 1) {
21
20
  // aggregates with multiple grouping sets can introduce NULL values to certain groups
22
21
  // FIXME: actually figure out WHICH groups can have null values introduced
23
- stats->validity_stats = make_unique<ValidityStatistics>(true, true);
22
+ stats->Set(StatsInfo::CAN_HAVE_NULL_VALUES);
24
23
  continue;
25
24
  }
26
25
  ColumnBinding group_binding(aggr.group_index, group_idx);
@@ -5,7 +5,7 @@
5
5
  #include "duckdb/planner/expression/bound_comparison_expression.hpp"
6
6
  #include "duckdb/planner/expression/bound_constant_expression.hpp"
7
7
  #include "duckdb/planner/operator/logical_filter.hpp"
8
- #include "duckdb/storage/statistics/numeric_statistics.hpp"
8
+ #include "duckdb/storage/statistics/base_statistics.hpp"
9
9
 
10
10
  namespace duckdb {
11
11
 
@@ -35,21 +35,20 @@ void StatisticsPropagator::SetStatisticsNotNull(ColumnBinding binding) {
35
35
  if (entry == statistics_map.end()) {
36
36
  return;
37
37
  }
38
- entry->second->validity_stats = make_unique<ValidityStatistics>(false);
38
+ entry->second->Set(StatsInfo::CANNOT_HAVE_NULL_VALUES);
39
39
  }
40
40
 
41
41
  void StatisticsPropagator::UpdateFilterStatistics(BaseStatistics &stats, ExpressionType comparison_type,
42
42
  const Value &constant) {
43
43
  // regular comparisons removes all null values
44
44
  if (!IsCompareDistinct(comparison_type)) {
45
- stats.validity_stats = make_unique<ValidityStatistics>(false);
45
+ stats.Set(StatsInfo::CANNOT_HAVE_NULL_VALUES);
46
46
  }
47
- if (!stats.type.IsNumeric()) {
47
+ if (!stats.GetType().IsNumeric()) {
48
48
  // don't handle non-numeric columns here (yet)
49
49
  return;
50
50
  }
51
- auto &numeric_stats = (NumericStatistics &)stats;
52
- if (numeric_stats.min.IsNull() || numeric_stats.max.IsNull()) {
51
+ if (!NumericStats::HasMinMax(stats)) {
53
52
  // no stats available: skip this
54
53
  return;
55
54
  }
@@ -58,19 +57,19 @@ void StatisticsPropagator::UpdateFilterStatistics(BaseStatistics &stats, Express
58
57
  case ExpressionType::COMPARE_LESSTHANOREQUALTO:
59
58
  // X < constant OR X <= constant
60
59
  // max becomes the constant
61
- numeric_stats.max = constant;
60
+ NumericStats::SetMax(stats, constant);
62
61
  break;
63
62
  case ExpressionType::COMPARE_GREATERTHAN:
64
63
  case ExpressionType::COMPARE_GREATERTHANOREQUALTO:
65
64
  // X > constant OR X >= constant
66
65
  // min becomes the constant
67
- numeric_stats.min = constant;
66
+ NumericStats::SetMin(stats, constant);
68
67
  break;
69
68
  case ExpressionType::COMPARE_EQUAL:
70
69
  // X = constant
71
70
  // both min and max become the constant
72
- numeric_stats.min = constant;
73
- numeric_stats.max = constant;
71
+ NumericStats::SetMin(stats, constant);
72
+ NumericStats::SetMax(stats, constant);
74
73
  break;
75
74
  default:
76
75
  break;
@@ -81,17 +80,15 @@ void StatisticsPropagator::UpdateFilterStatistics(BaseStatistics &lstats, BaseSt
81
80
  ExpressionType comparison_type) {
82
81
  // regular comparisons removes all null values
83
82
  if (!IsCompareDistinct(comparison_type)) {
84
- lstats.validity_stats = make_unique<ValidityStatistics>(false);
85
- rstats.validity_stats = make_unique<ValidityStatistics>(false);
83
+ lstats.Set(StatsInfo::CANNOT_HAVE_NULL_VALUES);
84
+ rstats.Set(StatsInfo::CANNOT_HAVE_NULL_VALUES);
86
85
  }
87
- D_ASSERT(lstats.type == rstats.type);
88
- if (!lstats.type.IsNumeric()) {
86
+ D_ASSERT(lstats.GetType() == rstats.GetType());
87
+ if (!lstats.GetType().IsNumeric()) {
89
88
  // don't handle non-numeric columns here (yet)
90
89
  return;
91
90
  }
92
- auto &left_stats = (NumericStatistics &)lstats;
93
- auto &right_stats = (NumericStatistics &)rstats;
94
- if (left_stats.min.IsNull() || left_stats.max.IsNull() || right_stats.min.IsNull() || right_stats.max.IsNull()) {
91
+ if (!NumericStats::HasMinMax(lstats) || !NumericStats::HasMinMax(rstats)) {
95
92
  // no stats available: skip this
96
93
  return;
97
94
  }
@@ -104,14 +101,14 @@ void StatisticsPropagator::UpdateFilterStatistics(BaseStatistics &lstats, BaseSt
104
101
 
105
102
  // we know that left.max is AT MOST equal to right.max
106
103
  // because any value in left that is BIGGER than right.max will not pass the filter
107
- if (left_stats.max > right_stats.max) {
108
- left_stats.max = right_stats.max;
104
+ if (NumericStats::Max(lstats) > NumericStats::Max(rstats)) {
105
+ NumericStats::SetMax(lstats, NumericStats::Max(rstats));
109
106
  }
110
107
 
111
108
  // we also know that right.min is AT MOST equal to left.min
112
109
  // because any value in right that is SMALLER than left.min will not pass the filter
113
- if (right_stats.min < left_stats.min) {
114
- right_stats.min = left_stats.min;
110
+ if (NumericStats::Min(rstats) < NumericStats::Min(lstats)) {
111
+ NumericStats::SetMin(rstats, NumericStats::Min(lstats));
115
112
  }
116
113
  // so in our example, the bounds get updated as follows:
117
114
  // left: [-50, 100], right: [-50, 100]
@@ -121,11 +118,11 @@ void StatisticsPropagator::UpdateFilterStatistics(BaseStatistics &lstats, BaseSt
121
118
  // LEFT > RIGHT OR LEFT >= RIGHT
122
119
  // we know that every value of left is bigger (or equal to) every value in right
123
120
  // this is essentially the inverse of the less than (or equal to) scenario
124
- if (right_stats.max > left_stats.max) {
125
- right_stats.max = left_stats.max;
121
+ if (NumericStats::Max(rstats) > NumericStats::Max(lstats)) {
122
+ NumericStats::SetMax(rstats, NumericStats::Max(lstats));
126
123
  }
127
- if (left_stats.min < right_stats.min) {
128
- left_stats.min = right_stats.min;
124
+ if (NumericStats::Min(lstats) < NumericStats::Min(rstats)) {
125
+ NumericStats::SetMin(lstats, NumericStats::Min(rstats));
129
126
  }
130
127
  break;
131
128
  case ExpressionType::COMPARE_EQUAL:
@@ -135,16 +132,16 @@ void StatisticsPropagator::UpdateFilterStatistics(BaseStatistics &lstats, BaseSt
135
132
  // so if we have e.g. left = [-50, 250] and right = [-100, 100]
136
133
  // the tighest bounds are [-50, 100]
137
134
  // select the highest min
138
- if (left_stats.min > right_stats.min) {
139
- right_stats.min = left_stats.min;
135
+ if (NumericStats::Min(lstats) > NumericStats::Min(rstats)) {
136
+ NumericStats::SetMin(rstats, NumericStats::Min(lstats));
140
137
  } else {
141
- left_stats.min = right_stats.min;
138
+ NumericStats::SetMin(lstats, NumericStats::Min(rstats));
142
139
  }
143
140
  // select the lowest max
144
- if (left_stats.max < right_stats.max) {
145
- right_stats.max = left_stats.max;
141
+ if (NumericStats::Max(lstats) < NumericStats::Max(rstats)) {
142
+ NumericStats::SetMax(rstats, NumericStats::Max(lstats));
146
143
  } else {
147
- left_stats.max = right_stats.max;
144
+ NumericStats::SetMax(lstats, NumericStats::Max(rstats));
148
145
  }
149
146
  break;
150
147
  default:
@@ -7,7 +7,6 @@
7
7
  #include "duckdb/planner/operator/logical_join.hpp"
8
8
  #include "duckdb/planner/operator/logical_limit.hpp"
9
9
  #include "duckdb/planner/operator/logical_positional_join.hpp"
10
- #include "duckdb/storage/statistics/validity_statistics.hpp"
11
10
 
12
11
  namespace duckdb {
13
12
 
@@ -210,7 +209,7 @@ unique_ptr<NodeStatistics> StatisticsPropagator::PropagateStatistics(LogicalJoin
210
209
  for (auto &binding : right_bindings) {
211
210
  auto stats = statistics_map.find(binding);
212
211
  if (stats != statistics_map.end()) {
213
- stats->second->validity_stats = make_unique<ValidityStatistics>(true);
212
+ stats->second->Set(StatsInfo::CAN_HAVE_NULL_VALUES);
214
213
  }
215
214
  }
216
215
  }
@@ -219,7 +218,7 @@ unique_ptr<NodeStatistics> StatisticsPropagator::PropagateStatistics(LogicalJoin
219
218
  for (auto &binding : left_bindings) {
220
219
  auto stats = statistics_map.find(binding);
221
220
  if (stats != statistics_map.end()) {
222
- stats->second->validity_stats = make_unique<ValidityStatistics>(true);
221
+ stats->second->Set(StatsInfo::CAN_HAVE_NULL_VALUES);
223
222
  }
224
223
  }
225
224
  }
@@ -265,7 +264,7 @@ unique_ptr<NodeStatistics> StatisticsPropagator::PropagateStatistics(LogicalPosi
265
264
  for (auto &binding : left_bindings) {
266
265
  auto stats = statistics_map.find(binding);
267
266
  if (stats != statistics_map.end()) {
268
- stats->second->validity_stats = make_unique<ValidityStatistics>(true);
267
+ stats->second->Set(StatsInfo::CAN_HAVE_NULL_VALUES);
269
268
  }
270
269
  }
271
270
 
@@ -274,7 +273,7 @@ unique_ptr<NodeStatistics> StatisticsPropagator::PropagateStatistics(LogicalPosi
274
273
  for (auto &binding : right_bindings) {
275
274
  auto stats = statistics_map.find(binding);
276
275
  if (stats != statistics_map.end()) {
277
- stats->second->validity_stats = make_unique<ValidityStatistics>(true);
276
+ stats->second->Set(StatsInfo::CAN_HAVE_NULL_VALUES);
278
277
  }
279
278
  }
280
279
 
@@ -47,18 +47,18 @@ unique_ptr<NodeStatistics> StatisticsPropagator::PropagateStatistics(LogicalSetO
47
47
  switch (setop.type) {
48
48
  case LogicalOperatorType::LOGICAL_UNION:
49
49
  // union: merge the stats of the LHS and RHS together
50
- new_stats = left_entry->second->Copy();
50
+ new_stats = left_entry->second->ToUnique();
51
51
  new_stats->Merge(*right_entry->second);
52
52
  break;
53
53
  case LogicalOperatorType::LOGICAL_EXCEPT:
54
54
  // except: use the stats of the LHS
55
- new_stats = left_entry->second->Copy();
55
+ new_stats = left_entry->second->ToUnique();
56
56
  break;
57
57
  case LogicalOperatorType::LOGICAL_INTERSECT:
58
58
  // intersect: intersect the two stats
59
59
  // FIXME: for now we just use the stats of the LHS, as this is correct
60
60
  // however, the stats can be further refined to the minimal subset of the LHS and RHS
61
- new_stats = left_entry->second->Copy();
61
+ new_stats = left_entry->second->ToUnique();
62
62
  break;
63
63
  default:
64
64
  throw InternalException("Unsupported setop type");
@@ -92,7 +92,7 @@ unique_ptr<BaseStatistics> StatisticsPropagator::PropagateExpression(Expression
92
92
  unique_ptr<BaseStatistics> StatisticsPropagator::PropagateExpression(unique_ptr<Expression> &expr) {
93
93
  auto stats = PropagateExpression(*expr, &expr);
94
94
  if (ClientConfig::GetConfig(context).query_verification_enabled && stats) {
95
- expr->verification_stats = stats->Copy();
95
+ expr->verification_stats = stats->ToUnique();
96
96
  }
97
97
  return stats;
98
98
  }
@@ -1,6 +1,7 @@
1
1
  #include "duckdb/parser/parsed_data/alter_info.hpp"
2
2
  #include "duckdb/parser/parsed_data/alter_table_info.hpp"
3
- #include "duckdb/parser/parsed_data/alter_function_info.hpp"
3
+ #include "duckdb/parser/parsed_data/alter_scalar_function_info.hpp"
4
+ #include "duckdb/parser/parsed_data/alter_table_function_info.hpp"
4
5
 
5
6
  #include "duckdb/common/field_writer.hpp"
6
7
 
@@ -33,8 +34,11 @@ unique_ptr<AlterInfo> AlterInfo::Deserialize(Deserializer &source) {
33
34
  case AlterType::ALTER_VIEW:
34
35
  result = AlterViewInfo::Deserialize(reader);
35
36
  break;
36
- case AlterType::ALTER_FUNCTION:
37
- result = AlterFunctionInfo::Deserialize(reader);
37
+ case AlterType::ALTER_SCALAR_FUNCTION:
38
+ result = AlterScalarFunctionInfo::Deserialize(reader);
39
+ break;
40
+ case AlterType::ALTER_TABLE_FUNCTION:
41
+ result = AlterTableFunctionInfo::Deserialize(reader);
38
42
  break;
39
43
  default:
40
44
  throw SerializationException("Unknown alter type for deserialization!");
@@ -0,0 +1,56 @@
1
+ #include "duckdb/parser/parsed_data/alter_scalar_function_info.hpp"
2
+
3
+ #include "duckdb/common/field_writer.hpp"
4
+ #include "duckdb/parser/constraint.hpp"
5
+
6
+ namespace duckdb {
7
+
8
+ //===--------------------------------------------------------------------===//
9
+ // AlterScalarFunctionInfo
10
+ //===--------------------------------------------------------------------===//
11
+ AlterScalarFunctionInfo::AlterScalarFunctionInfo(AlterScalarFunctionType type, AlterEntryData data)
12
+ : AlterInfo(AlterType::ALTER_SCALAR_FUNCTION, std::move(data.catalog), std::move(data.schema), std::move(data.name),
13
+ data.if_exists),
14
+ alter_scalar_function_type(type) {
15
+ }
16
+ AlterScalarFunctionInfo::~AlterScalarFunctionInfo() {
17
+ }
18
+
19
+ CatalogType AlterScalarFunctionInfo::GetCatalogType() const {
20
+ return CatalogType::SCALAR_FUNCTION_ENTRY;
21
+ }
22
+
23
+ void AlterScalarFunctionInfo::Serialize(FieldWriter &writer) const {
24
+ writer.WriteField<AlterScalarFunctionType>(alter_scalar_function_type);
25
+ writer.WriteString(catalog);
26
+ writer.WriteString(schema);
27
+ writer.WriteString(name);
28
+ writer.WriteField(if_exists);
29
+ }
30
+
31
+ unique_ptr<AlterInfo> AlterScalarFunctionInfo::Deserialize(FieldReader &reader) {
32
+ // auto type = reader.ReadRequired<AlterScalarFunctionType>();
33
+ // auto schema = reader.ReadRequired<string>();
34
+ // auto table = reader.ReadRequired<string>();
35
+ // auto if_exists = reader.ReadRequired<bool>();
36
+
37
+ throw NotImplementedException("AlterScalarFunctionInfo cannot be deserialized");
38
+ }
39
+
40
+ //===--------------------------------------------------------------------===//
41
+ // AddScalarFunctionOverloadInfo
42
+ //===--------------------------------------------------------------------===//
43
+ AddScalarFunctionOverloadInfo::AddScalarFunctionOverloadInfo(AlterEntryData data, ScalarFunctionSet new_overloads_p)
44
+ : AlterScalarFunctionInfo(AlterScalarFunctionType::ADD_FUNCTION_OVERLOADS, std::move(data)),
45
+ new_overloads(std::move(new_overloads_p)) {
46
+ this->allow_internal = true;
47
+ }
48
+
49
+ AddScalarFunctionOverloadInfo::~AddScalarFunctionOverloadInfo() {
50
+ }
51
+
52
+ unique_ptr<AlterInfo> AddScalarFunctionOverloadInfo::Copy() const {
53
+ return make_unique_base<AlterInfo, AddScalarFunctionOverloadInfo>(GetAlterEntryData(), new_overloads);
54
+ }
55
+
56
+ } // namespace duckdb
@@ -0,0 +1,51 @@
1
+ #include "duckdb/parser/parsed_data/alter_table_function_info.hpp"
2
+
3
+ #include "duckdb/common/field_writer.hpp"
4
+ #include "duckdb/parser/constraint.hpp"
5
+
6
+ namespace duckdb {
7
+
8
+ //===--------------------------------------------------------------------===//
9
+ // AlterTableFunctionInfo
10
+ //===--------------------------------------------------------------------===//
11
+ AlterTableFunctionInfo::AlterTableFunctionInfo(AlterTableFunctionType type, AlterEntryData data)
12
+ : AlterInfo(AlterType::ALTER_TABLE_FUNCTION, std::move(data.catalog), std::move(data.schema), std::move(data.name),
13
+ data.if_exists),
14
+ alter_table_function_type(type) {
15
+ }
16
+ AlterTableFunctionInfo::~AlterTableFunctionInfo() {
17
+ }
18
+
19
+ CatalogType AlterTableFunctionInfo::GetCatalogType() const {
20
+ return CatalogType::TABLE_FUNCTION_ENTRY;
21
+ }
22
+
23
+ void AlterTableFunctionInfo::Serialize(FieldWriter &writer) const {
24
+ writer.WriteField<AlterTableFunctionType>(alter_table_function_type);
25
+ writer.WriteString(catalog);
26
+ writer.WriteString(schema);
27
+ writer.WriteString(name);
28
+ writer.WriteField(if_exists);
29
+ }
30
+
31
+ unique_ptr<AlterInfo> AlterTableFunctionInfo::Deserialize(FieldReader &reader) {
32
+ throw NotImplementedException("AlterTableFunctionInfo cannot be deserialized");
33
+ }
34
+
35
+ //===--------------------------------------------------------------------===//
36
+ // AddTableFunctionOverloadInfo
37
+ //===--------------------------------------------------------------------===//
38
+ AddTableFunctionOverloadInfo::AddTableFunctionOverloadInfo(AlterEntryData data, TableFunctionSet new_overloads_p)
39
+ : AlterTableFunctionInfo(AlterTableFunctionType::ADD_FUNCTION_OVERLOADS, std::move(data)),
40
+ new_overloads(std::move(new_overloads_p)) {
41
+ this->allow_internal = true;
42
+ }
43
+
44
+ AddTableFunctionOverloadInfo::~AddTableFunctionOverloadInfo() {
45
+ }
46
+
47
+ unique_ptr<AlterInfo> AddTableFunctionOverloadInfo::Copy() const {
48
+ return make_unique_base<AlterInfo, AddTableFunctionOverloadInfo>(GetAlterEntryData(), new_overloads);
49
+ }
50
+
51
+ } // namespace duckdb
@@ -1,5 +1,5 @@
1
1
  #include "duckdb/parser/parsed_data/create_scalar_function_info.hpp"
2
- #include "duckdb/parser/parsed_data/alter_function_info.hpp"
2
+ #include "duckdb/parser/parsed_data/alter_scalar_function_info.hpp"
3
3
 
4
4
  namespace duckdb {
5
5
 
@@ -27,7 +27,8 @@ unique_ptr<CreateInfo> CreateScalarFunctionInfo::Copy() const {
27
27
  }
28
28
 
29
29
  unique_ptr<AlterInfo> CreateScalarFunctionInfo::GetAlterInfo() const {
30
- return make_unique_base<AlterInfo, AddFunctionOverloadInfo>(AlterEntryData(catalog, schema, name, true), functions);
30
+ return make_unique_base<AlterInfo, AddScalarFunctionOverloadInfo>(AlterEntryData(catalog, schema, name, true),
31
+ functions);
31
32
  }
32
33
 
33
34
  } // namespace duckdb
@@ -1,4 +1,5 @@
1
1
  #include "duckdb/parser/parsed_data/create_table_function_info.hpp"
2
+ #include "duckdb/parser/parsed_data/alter_table_function_info.hpp"
2
3
 
3
4
  namespace duckdb {
4
5
 
@@ -25,4 +26,9 @@ unique_ptr<CreateInfo> CreateTableFunctionInfo::Copy() const {
25
26
  return std::move(result);
26
27
  }
27
28
 
29
+ unique_ptr<AlterInfo> CreateTableFunctionInfo::GetAlterInfo() const {
30
+ return make_unique_base<AlterInfo, AddTableFunctionOverloadInfo>(AlterEntryData(catalog, schema, name, true),
31
+ functions);
32
+ }
33
+
28
34
  } // namespace duckdb
@@ -213,6 +213,14 @@ void ParsedExpressionIterator::EnumerateTableRefChildren(
213
213
  }
214
214
  break;
215
215
  }
216
+ case TableReferenceType::PIVOT: {
217
+ auto &p_ref = (PivotRef &)ref;
218
+ EnumerateTableRefChildren(*p_ref.source, callback);
219
+ for (auto &aggr : p_ref.aggregates) {
220
+ callback(aggr);
221
+ }
222
+ break;
223
+ }
216
224
  case TableReferenceType::SUBQUERY: {
217
225
  auto &sq_ref = (SubqueryRef &)ref;
218
226
  EnumerateQueryNodeChildren(*sq_ref.subquery->node, callback);