duckdb 0.8.2-dev1.0 → 0.8.2-dev1182.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 (385) hide show
  1. package/binding.gyp +16 -14
  2. package/binding.gyp.in +1 -1
  3. package/configure.py +1 -1
  4. package/duckdb_extension_config.cmake +10 -0
  5. package/lib/duckdb.d.ts +59 -0
  6. package/lib/duckdb.js +21 -0
  7. package/package.json +1 -1
  8. package/src/duckdb/extension/icu/icu-dateadd.cpp +2 -2
  9. package/src/duckdb/extension/icu/icu-datefunc.cpp +1 -1
  10. package/src/duckdb/extension/icu/icu-datepart.cpp +2 -2
  11. package/src/duckdb/extension/icu/icu-datesub.cpp +2 -2
  12. package/src/duckdb/extension/icu/icu-datetrunc.cpp +1 -1
  13. package/src/duckdb/extension/icu/icu-list-range.cpp +1 -1
  14. package/src/duckdb/extension/icu/icu-makedate.cpp +7 -0
  15. package/src/duckdb/extension/icu/icu-strptime.cpp +4 -4
  16. package/src/duckdb/extension/icu/icu-table-range.cpp +5 -5
  17. package/src/duckdb/extension/icu/icu-timebucket.cpp +16 -16
  18. package/src/duckdb/extension/icu/icu-timezone.cpp +8 -8
  19. package/src/duckdb/extension/icu/{icu-extension.cpp → icu_extension.cpp} +29 -34
  20. package/src/duckdb/extension/icu/include/{icu-extension.hpp → icu_extension.hpp} +2 -2
  21. package/src/duckdb/extension/json/include/json_common.hpp +47 -231
  22. package/src/duckdb/extension/json/include/json_executors.hpp +49 -13
  23. package/src/duckdb/extension/json/include/{json-extension.hpp → json_extension.hpp} +2 -2
  24. package/src/duckdb/extension/json/include/json_functions.hpp +2 -1
  25. package/src/duckdb/extension/json/json_common.cpp +272 -40
  26. package/src/duckdb/extension/json/{json-extension.cpp → json_extension.cpp} +4 -4
  27. package/src/duckdb/extension/json/json_functions/json_structure.cpp +1 -1
  28. package/src/duckdb/extension/json/json_functions/json_transform.cpp +17 -37
  29. package/src/duckdb/extension/json/json_functions/json_type.cpp +1 -1
  30. package/src/duckdb/extension/json/json_functions.cpp +24 -24
  31. package/src/duckdb/extension/json/json_scan.cpp +3 -6
  32. package/src/duckdb/extension/parquet/column_reader.cpp +19 -21
  33. package/src/duckdb/extension/parquet/column_writer.cpp +77 -61
  34. package/src/duckdb/extension/parquet/include/cast_column_reader.hpp +2 -2
  35. package/src/duckdb/extension/parquet/include/column_reader.hpp +14 -16
  36. package/src/duckdb/extension/parquet/include/column_writer.hpp +9 -7
  37. package/src/duckdb/extension/parquet/include/list_column_reader.hpp +2 -2
  38. package/src/duckdb/extension/parquet/include/parquet_dbp_decoder.hpp +3 -3
  39. package/src/duckdb/extension/parquet/include/parquet_decimal_utils.hpp +3 -3
  40. package/src/duckdb/extension/parquet/include/parquet_file_metadata_cache.hpp +2 -2
  41. package/src/duckdb/extension/parquet/include/parquet_statistics.hpp +2 -2
  42. package/src/duckdb/extension/parquet/include/parquet_support.hpp +9 -11
  43. package/src/duckdb/extension/parquet/include/parquet_writer.hpp +24 -5
  44. package/src/duckdb/extension/parquet/include/string_column_reader.hpp +1 -1
  45. package/src/duckdb/extension/parquet/include/struct_column_reader.hpp +2 -3
  46. package/src/duckdb/extension/parquet/include/zstd_file_system.hpp +2 -2
  47. package/src/duckdb/extension/parquet/{parquet-extension.cpp → parquet_extension.cpp} +190 -19
  48. package/src/duckdb/extension/parquet/parquet_reader.cpp +5 -5
  49. package/src/duckdb/extension/parquet/parquet_statistics.cpp +7 -6
  50. package/src/duckdb/extension/parquet/parquet_writer.cpp +79 -16
  51. package/src/duckdb/extension/parquet/zstd_file_system.cpp +2 -2
  52. package/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp +1 -1
  53. package/src/duckdb/src/catalog/default/default_functions.cpp +16 -0
  54. package/src/duckdb/src/common/adbc/adbc.cpp +75 -10
  55. package/src/duckdb/src/common/adbc/driver_manager.cpp +6 -11
  56. package/src/duckdb/src/common/allocator.cpp +16 -4
  57. package/src/duckdb/src/common/arrow/arrow_appender.cpp +5 -10
  58. package/src/duckdb/src/common/arrow/arrow_wrapper.cpp +0 -12
  59. package/src/duckdb/src/common/assert.cpp +3 -0
  60. package/src/duckdb/src/common/enum_util.cpp +42 -5
  61. package/src/duckdb/src/common/enums/logical_operator_type.cpp +4 -0
  62. package/src/duckdb/src/common/enums/optimizer_type.cpp +2 -0
  63. package/src/duckdb/src/common/enums/physical_operator_type.cpp +4 -0
  64. package/src/duckdb/src/common/file_system.cpp +15 -0
  65. package/src/duckdb/src/common/local_file_system.cpp +1 -1
  66. package/src/duckdb/src/common/multi_file_reader.cpp +181 -18
  67. package/src/duckdb/src/common/radix_partitioning.cpp +27 -9
  68. package/src/duckdb/src/common/row_operations/row_external.cpp +1 -1
  69. package/src/duckdb/src/common/sort/merge_sorter.cpp +9 -16
  70. package/src/duckdb/src/common/sort/partition_state.cpp +44 -11
  71. package/src/duckdb/src/common/types/batched_data_collection.cpp +7 -2
  72. package/src/duckdb/src/common/types/column/column_data_allocator.cpp +9 -6
  73. package/src/duckdb/src/common/types/column/column_data_collection.cpp +17 -2
  74. package/src/duckdb/src/common/types/column/column_data_collection_segment.cpp +15 -6
  75. package/src/duckdb/src/common/types/column/partitioned_column_data.cpp +2 -2
  76. package/src/duckdb/src/common/types/data_chunk.cpp +2 -2
  77. package/src/duckdb/src/common/types/date.cpp +9 -0
  78. package/src/duckdb/src/common/types/list_segment.cpp +24 -74
  79. package/src/duckdb/src/common/types/row/partitioned_tuple_data.cpp +3 -9
  80. package/src/duckdb/src/common/types/row/tuple_data_collection.cpp +2 -0
  81. package/src/duckdb/src/common/types/row/tuple_data_scatter_gather.cpp +2 -2
  82. package/src/duckdb/src/common/types/validity_mask.cpp +33 -0
  83. package/src/duckdb/src/common/types/vector.cpp +15 -14
  84. package/src/duckdb/src/common/vector_operations/is_distinct_from.cpp +6 -4
  85. package/src/duckdb/src/core_functions/aggregate/nested/list.cpp +2 -2
  86. package/src/duckdb/src/core_functions/aggregate/regression/regr_avg.cpp +4 -4
  87. package/src/duckdb/src/core_functions/aggregate/regression/regr_intercept.cpp +4 -4
  88. package/src/duckdb/src/core_functions/aggregate/regression/regr_r2.cpp +5 -4
  89. package/src/duckdb/src/core_functions/aggregate/regression/regr_sxx_syy.cpp +8 -8
  90. package/src/duckdb/src/core_functions/aggregate/regression/regr_sxy.cpp +4 -3
  91. package/src/duckdb/src/core_functions/function_list.cpp +4 -2
  92. package/src/duckdb/src/core_functions/scalar/date/date_part.cpp +208 -42
  93. package/src/duckdb/src/core_functions/scalar/date/epoch.cpp +0 -17
  94. package/src/duckdb/src/core_functions/scalar/date/make_date.cpp +19 -4
  95. package/src/duckdb/src/core_functions/scalar/list/list_aggregates.cpp +4 -2
  96. package/src/duckdb/src/execution/aggregate_hashtable.cpp +34 -18
  97. package/src/duckdb/src/execution/index/art/art.cpp +149 -139
  98. package/src/duckdb/src/execution/index/art/fixed_size_allocator.cpp +1 -1
  99. package/src/duckdb/src/execution/index/art/iterator.cpp +129 -207
  100. package/src/duckdb/src/execution/index/art/leaf.cpp +8 -37
  101. package/src/duckdb/src/execution/index/art/node.cpp +113 -120
  102. package/src/duckdb/src/execution/index/art/node16.cpp +1 -10
  103. package/src/duckdb/src/execution/index/art/node256.cpp +1 -9
  104. package/src/duckdb/src/execution/index/art/node4.cpp +12 -13
  105. package/src/duckdb/src/execution/index/art/node48.cpp +1 -11
  106. package/src/duckdb/src/execution/index/art/prefix.cpp +228 -350
  107. package/src/duckdb/src/execution/join_hashtable.cpp +4 -4
  108. package/src/duckdb/src/execution/operator/aggregate/aggregate_object.cpp +1 -0
  109. package/src/duckdb/src/execution/operator/aggregate/physical_streaming_window.cpp +8 -3
  110. package/src/duckdb/src/execution/operator/aggregate/physical_ungrouped_aggregate.cpp +32 -22
  111. package/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +512 -300
  112. package/src/duckdb/src/execution/operator/helper/physical_batch_collector.cpp +4 -3
  113. package/src/duckdb/src/execution/operator/helper/physical_limit.cpp +5 -5
  114. package/src/duckdb/src/execution/operator/join/physical_asof_join.cpp +413 -282
  115. package/src/duckdb/src/execution/operator/join/physical_comparison_join.cpp +1 -1
  116. package/src/duckdb/src/execution/operator/join/physical_hash_join.cpp +21 -10
  117. package/src/duckdb/src/execution/operator/join/physical_join.cpp +1 -1
  118. package/src/duckdb/src/execution/operator/join/physical_piecewise_merge_join.cpp +22 -3
  119. package/src/duckdb/src/execution/operator/persistent/base_csv_reader.cpp +100 -13
  120. package/src/duckdb/src/execution/operator/persistent/csv_reader_options.cpp +20 -0
  121. package/src/duckdb/src/execution/operator/persistent/csv_rejects_table.cpp +48 -0
  122. package/src/duckdb/src/execution/operator/persistent/parallel_csv_reader.cpp +2 -3
  123. package/src/duckdb/src/execution/operator/persistent/physical_batch_copy_to_file.cpp +6 -4
  124. package/src/duckdb/src/execution/operator/persistent/physical_batch_insert.cpp +3 -2
  125. package/src/duckdb/src/execution/operator/persistent/physical_fixed_batch_copy.cpp +3 -3
  126. package/src/duckdb/src/execution/operator/projection/physical_pivot.cpp +2 -1
  127. package/src/duckdb/src/execution/operator/scan/physical_column_data_scan.cpp +19 -0
  128. package/src/duckdb/src/execution/operator/set/physical_cte.cpp +160 -0
  129. package/src/duckdb/src/execution/operator/set/physical_recursive_cte.cpp +15 -5
  130. package/src/duckdb/src/execution/partitionable_hashtable.cpp +41 -6
  131. package/src/duckdb/src/execution/perfect_aggregate_hashtable.cpp +30 -5
  132. package/src/duckdb/src/execution/physical_operator.cpp +17 -14
  133. package/src/duckdb/src/execution/physical_plan/plan_aggregate.cpp +43 -10
  134. package/src/duckdb/src/execution/physical_plan/plan_cte.cpp +33 -0
  135. package/src/duckdb/src/execution/physical_plan/plan_recursive_cte.cpp +25 -4
  136. package/src/duckdb/src/execution/physical_plan_generator.cpp +4 -0
  137. package/src/duckdb/src/execution/radix_partitioned_hashtable.cpp +290 -43
  138. package/src/duckdb/src/execution/window_segment_tree.cpp +286 -129
  139. package/src/duckdb/src/function/aggregate/sorted_aggregate_function.cpp +2 -1
  140. package/src/duckdb/src/function/function.cpp +2 -0
  141. package/src/duckdb/src/function/scalar/compressed_materialization/compress_integral.cpp +212 -0
  142. package/src/duckdb/src/function/scalar/compressed_materialization/compress_string.cpp +249 -0
  143. package/src/duckdb/src/function/scalar/compressed_materialization_functions.cpp +29 -0
  144. package/src/duckdb/src/function/scalar/list/list_resize.cpp +162 -0
  145. package/src/duckdb/src/function/scalar/nested_functions.cpp +1 -0
  146. package/src/duckdb/src/function/scalar/string/like.cpp +12 -4
  147. package/src/duckdb/src/function/scalar/system/aggregate_export.cpp +12 -5
  148. package/src/duckdb/src/function/table/copy_csv.cpp +8 -1
  149. package/src/duckdb/src/function/table/read_csv.cpp +100 -17
  150. package/src/duckdb/src/function/table/system/test_all_types.cpp +38 -18
  151. package/src/duckdb/src/function/table/table_scan.cpp +9 -0
  152. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  153. package/src/duckdb/src/include/duckdb/common/adbc/adbc.hpp +1 -0
  154. package/src/duckdb/src/include/duckdb/common/allocator.hpp +2 -0
  155. package/src/duckdb/src/include/duckdb/common/bswap.hpp +42 -0
  156. package/src/duckdb/src/include/duckdb/common/enum_util.hpp +8 -0
  157. package/src/duckdb/src/include/duckdb/common/enums/cte_materialize.hpp +21 -0
  158. package/src/duckdb/src/include/duckdb/common/enums/joinref_type.hpp +2 -1
  159. package/src/duckdb/src/include/duckdb/common/enums/logical_operator_type.hpp +2 -0
  160. package/src/duckdb/src/include/duckdb/common/enums/optimizer_type.hpp +2 -0
  161. package/src/duckdb/src/include/duckdb/common/enums/physical_operator_type.hpp +2 -0
  162. package/src/duckdb/src/include/duckdb/common/multi_file_reader.hpp +6 -4
  163. package/src/duckdb/src/include/duckdb/common/multi_file_reader_options.hpp +10 -42
  164. package/src/duckdb/src/include/duckdb/common/mutex.hpp +3 -0
  165. package/src/duckdb/src/include/duckdb/common/radix.hpp +9 -20
  166. package/src/duckdb/src/include/duckdb/common/radix_partitioning.hpp +6 -21
  167. package/src/duckdb/src/include/duckdb/common/row_operations/row_operations.hpp +3 -3
  168. package/src/duckdb/src/include/duckdb/common/sort/partition_state.hpp +13 -0
  169. package/src/duckdb/src/include/duckdb/common/types/batched_data_collection.hpp +3 -1
  170. package/src/duckdb/src/include/duckdb/common/types/column/column_data_allocator.hpp +1 -1
  171. package/src/duckdb/src/include/duckdb/common/types/column/column_data_collection.hpp +6 -1
  172. package/src/duckdb/src/include/duckdb/common/types/column/column_data_collection_segment.hpp +1 -1
  173. package/src/duckdb/src/include/duckdb/common/types/column/column_data_scan_states.hpp +3 -1
  174. package/src/duckdb/src/include/duckdb/common/types/data_chunk.hpp +1 -1
  175. package/src/duckdb/src/include/duckdb/common/types/date.hpp +7 -5
  176. package/src/duckdb/src/include/duckdb/common/types/list_segment.hpp +6 -8
  177. package/src/duckdb/src/include/duckdb/common/types/row/partitioned_tuple_data.hpp +0 -1
  178. package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_collection.hpp +1 -0
  179. package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_states.hpp +3 -0
  180. package/src/duckdb/src/include/duckdb/common/types/string_type.hpp +9 -0
  181. package/src/duckdb/src/include/duckdb/core_functions/aggregate/algebraic/corr.hpp +4 -4
  182. package/src/duckdb/src/include/duckdb/core_functions/aggregate/algebraic/covar.hpp +3 -1
  183. package/src/duckdb/src/include/duckdb/core_functions/aggregate/regression/regr_count.hpp +1 -0
  184. package/src/duckdb/src/include/duckdb/core_functions/aggregate/regression/regr_slope.hpp +3 -3
  185. package/src/duckdb/src/include/duckdb/core_functions/scalar/date_functions.hpp +24 -6
  186. package/src/duckdb/src/include/duckdb/execution/aggregate_hashtable.hpp +21 -3
  187. package/src/duckdb/src/include/duckdb/execution/executor.hpp +3 -0
  188. package/src/duckdb/src/include/duckdb/execution/index/art/art.hpp +4 -5
  189. package/src/duckdb/src/include/duckdb/execution/index/art/iterator.hpp +31 -27
  190. package/src/duckdb/src/include/duckdb/execution/index/art/leaf.hpp +6 -14
  191. package/src/duckdb/src/include/duckdb/execution/index/art/node.hpp +4 -10
  192. package/src/duckdb/src/include/duckdb/execution/index/art/node16.hpp +3 -6
  193. package/src/duckdb/src/include/duckdb/execution/index/art/node256.hpp +3 -6
  194. package/src/duckdb/src/include/duckdb/execution/index/art/node4.hpp +5 -8
  195. package/src/duckdb/src/include/duckdb/execution/index/art/node48.hpp +3 -6
  196. package/src/duckdb/src/include/duckdb/execution/index/art/prefix.hpp +63 -52
  197. package/src/duckdb/src/include/duckdb/execution/operator/join/physical_asof_join.hpp +2 -10
  198. package/src/duckdb/src/include/duckdb/execution/operator/persistent/base_csv_reader.hpp +1 -1
  199. package/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_line_info.hpp +4 -3
  200. package/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_reader_options.hpp +8 -1
  201. package/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_rejects_table.hpp +36 -0
  202. package/src/duckdb/src/include/duckdb/execution/operator/persistent/parallel_csv_reader.hpp +1 -1
  203. package/src/duckdb/src/include/duckdb/execution/operator/scan/physical_column_data_scan.hpp +10 -0
  204. package/src/duckdb/src/include/duckdb/execution/operator/set/physical_cte.hpp +62 -0
  205. package/src/duckdb/src/include/duckdb/execution/operator/set/physical_recursive_cte.hpp +8 -2
  206. package/src/duckdb/src/include/duckdb/execution/partitionable_hashtable.hpp +5 -1
  207. package/src/duckdb/src/include/duckdb/execution/physical_operator.hpp +3 -0
  208. package/src/duckdb/src/include/duckdb/execution/physical_plan_generator.hpp +3 -0
  209. package/src/duckdb/src/include/duckdb/execution/radix_partitioned_hashtable.hpp +10 -3
  210. package/src/duckdb/src/include/duckdb/execution/window_segment_tree.hpp +51 -40
  211. package/src/duckdb/src/include/duckdb/function/aggregate_function.hpp +1 -1
  212. package/src/duckdb/src/include/duckdb/function/aggregate_state.hpp +2 -2
  213. package/src/duckdb/src/include/duckdb/function/built_in_functions.hpp +1 -0
  214. package/src/duckdb/src/include/duckdb/function/scalar/compressed_materialization_functions.hpp +49 -0
  215. package/src/duckdb/src/include/duckdb/function/scalar/list/contains_or_position.hpp +1 -1
  216. package/src/duckdb/src/include/duckdb/function/scalar/nested_functions.hpp +5 -0
  217. package/src/duckdb/src/include/duckdb/function/scalar/string_functions.hpp +2 -0
  218. package/src/duckdb/src/include/duckdb/function/table/system_functions.hpp +1 -1
  219. package/src/duckdb/src/include/duckdb/main/client_config.hpp +3 -0
  220. package/src/duckdb/src/include/duckdb/main/config.hpp +2 -0
  221. package/src/duckdb/src/include/duckdb/main/settings.hpp +21 -1
  222. package/src/duckdb/src/include/duckdb/optimizer/column_binding_replacer.hpp +47 -0
  223. package/src/duckdb/src/include/duckdb/optimizer/compressed_materialization.hpp +132 -0
  224. package/src/duckdb/src/include/duckdb/optimizer/deliminator.hpp +13 -16
  225. package/src/duckdb/src/include/duckdb/optimizer/filter_pushdown.hpp +3 -0
  226. package/src/duckdb/src/include/duckdb/optimizer/join_order/estimated_properties.hpp +10 -1
  227. package/src/duckdb/src/include/duckdb/optimizer/join_order/join_order_optimizer.hpp +1 -1
  228. package/src/duckdb/src/include/duckdb/optimizer/join_order/join_relation.hpp +1 -1
  229. package/src/duckdb/src/include/duckdb/optimizer/join_order/query_graph.hpp +3 -0
  230. package/src/duckdb/src/include/duckdb/optimizer/matcher/set_matcher.hpp +13 -0
  231. package/src/duckdb/src/include/duckdb/optimizer/optimizer.hpp +3 -0
  232. package/src/duckdb/src/include/duckdb/optimizer/remove_duplicate_groups.hpp +40 -0
  233. package/src/duckdb/src/include/duckdb/optimizer/statistics_propagator.hpp +11 -3
  234. package/src/duckdb/src/include/duckdb/optimizer/topn_optimizer.hpp +2 -0
  235. package/src/duckdb/src/include/duckdb/parallel/pipeline.hpp +2 -0
  236. package/src/duckdb/src/include/duckdb/parallel/task_scheduler.hpp +5 -0
  237. package/src/duckdb/src/include/duckdb/parser/common_table_expression_info.hpp +2 -0
  238. package/src/duckdb/src/include/duckdb/parser/query_node/cte_node.hpp +54 -0
  239. package/src/duckdb/src/include/duckdb/parser/query_node/list.hpp +1 -0
  240. package/src/duckdb/src/include/duckdb/parser/query_node.hpp +2 -1
  241. package/src/duckdb/src/include/duckdb/parser/tokens.hpp +1 -0
  242. package/src/duckdb/src/include/duckdb/parser/transformer.hpp +15 -8
  243. package/src/duckdb/src/include/duckdb/planner/binder.hpp +8 -5
  244. package/src/duckdb/src/include/duckdb/planner/bound_tokens.hpp +1 -0
  245. package/src/duckdb/src/include/duckdb/planner/column_binding.hpp +4 -0
  246. package/src/duckdb/src/include/duckdb/planner/expression_binder/lateral_binder.hpp +0 -2
  247. package/src/duckdb/src/include/duckdb/planner/logical_tokens.hpp +1 -0
  248. package/src/duckdb/src/include/duckdb/planner/operator/list.hpp +2 -1
  249. package/src/duckdb/src/include/duckdb/planner/operator/logical_comparison_join.hpp +5 -5
  250. package/src/duckdb/src/include/duckdb/planner/operator/logical_cteref.hpp +7 -2
  251. package/src/duckdb/src/include/duckdb/planner/operator/logical_dependent_join.hpp +43 -0
  252. package/src/duckdb/src/include/duckdb/planner/operator/logical_materialized_cte.hpp +49 -0
  253. package/src/duckdb/src/include/duckdb/planner/operator/logical_recursive_cte.hpp +5 -4
  254. package/src/duckdb/src/include/duckdb/planner/query_node/bound_cte_node.hpp +44 -0
  255. package/src/duckdb/src/include/duckdb/planner/query_node/list.hpp +1 -0
  256. package/src/duckdb/src/include/duckdb/planner/subquery/flatten_dependent_join.hpp +2 -2
  257. package/src/duckdb/src/include/duckdb/planner/subquery/has_correlated_expressions.hpp +4 -1
  258. package/src/duckdb/src/include/duckdb/planner/subquery/recursive_dependent_join_planner.hpp +31 -0
  259. package/src/duckdb/src/include/duckdb/planner/subquery/rewrite_correlated_expressions.hpp +8 -2
  260. package/src/duckdb/src/include/duckdb/planner/tableref/bound_cteref.hpp +5 -2
  261. package/src/duckdb/src/include/duckdb/storage/arena_allocator.hpp +1 -1
  262. package/src/duckdb/src/include/duckdb/storage/block_manager.hpp +3 -3
  263. package/src/duckdb/src/include/duckdb/storage/data_table.hpp +1 -1
  264. package/src/duckdb/src/include/duckdb/storage/object_cache.hpp +22 -0
  265. package/src/duckdb/src/include/duckdb/storage/single_file_block_manager.hpp +2 -0
  266. package/src/duckdb/src/include/duckdb/storage/statistics/string_stats.hpp +4 -0
  267. package/src/duckdb/src/include/duckdb/storage/table/chunk_info.hpp +3 -0
  268. package/src/duckdb/src/include/duckdb/storage/table/row_group.hpp +3 -2
  269. package/src/duckdb/src/include/duckdb/storage/table/row_group_collection.hpp +1 -3
  270. package/src/duckdb/src/include/duckdb/transaction/local_storage.hpp +2 -3
  271. package/src/duckdb/src/include/duckdb.h +28 -0
  272. package/src/duckdb/src/main/capi/arrow-c.cpp +155 -1
  273. package/src/duckdb/src/main/config.cpp +2 -0
  274. package/src/duckdb/src/main/extension/extension_helper.cpp +106 -99
  275. package/src/duckdb/src/main/settings/settings.cpp +40 -18
  276. package/src/duckdb/src/optimizer/column_binding_replacer.cpp +43 -0
  277. package/src/duckdb/src/optimizer/column_lifetime_analyzer.cpp +1 -2
  278. package/src/duckdb/src/optimizer/compressed_materialization/compress_aggregate.cpp +140 -0
  279. package/src/duckdb/src/optimizer/compressed_materialization/compress_distinct.cpp +42 -0
  280. package/src/duckdb/src/optimizer/compressed_materialization/compress_order.cpp +65 -0
  281. package/src/duckdb/src/optimizer/compressed_materialization.cpp +478 -0
  282. package/src/duckdb/src/optimizer/deliminator.cpp +176 -321
  283. package/src/duckdb/src/optimizer/filter_pushdown.cpp +9 -0
  284. package/src/duckdb/src/optimizer/join_order/estimated_properties.cpp +7 -0
  285. package/src/duckdb/src/optimizer/join_order/join_node.cpp +2 -2
  286. package/src/duckdb/src/optimizer/join_order/join_order_optimizer.cpp +113 -82
  287. package/src/duckdb/src/optimizer/join_order/join_relation_set.cpp +2 -6
  288. package/src/duckdb/src/optimizer/join_order/query_graph.cpp +22 -14
  289. package/src/duckdb/src/optimizer/optimizer.cpp +51 -14
  290. package/src/duckdb/src/optimizer/pushdown/pushdown_cross_product.cpp +5 -5
  291. package/src/duckdb/src/optimizer/pushdown/pushdown_get.cpp +0 -1
  292. package/src/duckdb/src/optimizer/remove_duplicate_groups.cpp +127 -0
  293. package/src/duckdb/src/optimizer/remove_unused_columns.cpp +4 -0
  294. package/src/duckdb/src/optimizer/rule/regex_optimizations.cpp +154 -15
  295. package/src/duckdb/src/optimizer/statistics/operator/propagate_join.cpp +65 -8
  296. package/src/duckdb/src/optimizer/statistics/operator/propagate_order.cpp +1 -1
  297. package/src/duckdb/src/optimizer/statistics_propagator.cpp +7 -5
  298. package/src/duckdb/src/optimizer/topn_optimizer.cpp +20 -10
  299. package/src/duckdb/src/parallel/executor.cpp +15 -0
  300. package/src/duckdb/src/parallel/pipeline_executor.cpp +7 -6
  301. package/src/duckdb/src/parallel/task_scheduler.cpp +11 -2
  302. package/src/duckdb/src/parser/common_table_expression_info.cpp +2 -0
  303. package/src/duckdb/src/parser/expression/lambda_expression.cpp +1 -1
  304. package/src/duckdb/src/parser/parsed_expression_iterator.cpp +7 -0
  305. package/src/duckdb/src/parser/query_node/cte_node.cpp +75 -0
  306. package/src/duckdb/src/parser/query_node.cpp +18 -1
  307. package/src/duckdb/src/parser/tableref/joinref.cpp +3 -0
  308. package/src/duckdb/src/parser/transform/expression/transform_constant.cpp +55 -3
  309. package/src/duckdb/src/parser/transform/expression/transform_expression.cpp +2 -0
  310. package/src/duckdb/src/parser/transform/expression/transform_multi_assign_reference.cpp +44 -0
  311. package/src/duckdb/src/parser/transform/helpers/transform_cte.cpp +19 -1
  312. package/src/duckdb/src/parser/transform/statement/transform_copy.cpp +13 -0
  313. package/src/duckdb/src/parser/transform/statement/transform_delete.cpp +6 -1
  314. package/src/duckdb/src/parser/transform/statement/transform_insert.cpp +6 -1
  315. package/src/duckdb/src/parser/transform/statement/transform_pivot_stmt.cpp +7 -2
  316. package/src/duckdb/src/parser/transform/statement/transform_pragma.cpp +14 -11
  317. package/src/duckdb/src/parser/transform/statement/transform_select_node.cpp +11 -2
  318. package/src/duckdb/src/parser/transform/statement/transform_update.cpp +6 -1
  319. package/src/duckdb/src/parser/transformer.cpp +15 -0
  320. package/src/duckdb/src/planner/binder/query_node/bind_cte_node.cpp +64 -0
  321. package/src/duckdb/src/planner/binder/query_node/plan_cte_node.cpp +26 -0
  322. package/src/duckdb/src/planner/binder/query_node/plan_recursive_cte_node.cpp +5 -5
  323. package/src/duckdb/src/planner/binder/query_node/plan_setop.cpp +4 -4
  324. package/src/duckdb/src/planner/binder/query_node/plan_subquery.cpp +32 -29
  325. package/src/duckdb/src/planner/binder/tableref/bind_basetableref.cpp +11 -2
  326. package/src/duckdb/src/planner/binder/tableref/bind_joinref.cpp +32 -5
  327. package/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp +116 -50
  328. package/src/duckdb/src/planner/binder/tableref/plan_cteref.cpp +1 -1
  329. package/src/duckdb/src/planner/binder/tableref/plan_joinref.cpp +61 -26
  330. package/src/duckdb/src/planner/binder/tableref/plan_subqueryref.cpp +3 -3
  331. package/src/duckdb/src/planner/binder.cpp +5 -0
  332. package/src/duckdb/src/planner/expression_binder/lateral_binder.cpp +4 -31
  333. package/src/duckdb/src/planner/expression_binder.cpp +3 -0
  334. package/src/duckdb/src/planner/expression_iterator.cpp +6 -0
  335. package/src/duckdb/src/planner/logical_operator.cpp +5 -0
  336. package/src/duckdb/src/planner/logical_operator_visitor.cpp +2 -0
  337. package/src/duckdb/src/planner/operator/logical_cteref.cpp +3 -1
  338. package/src/duckdb/src/planner/operator/logical_dependent_join.cpp +26 -0
  339. package/src/duckdb/src/planner/operator/logical_materialized_cte.cpp +21 -0
  340. package/src/duckdb/src/planner/subquery/flatten_dependent_join.cpp +90 -38
  341. package/src/duckdb/src/planner/subquery/has_correlated_expressions.cpp +22 -7
  342. package/src/duckdb/src/planner/subquery/rewrite_correlated_expressions.cpp +65 -7
  343. package/src/duckdb/src/storage/arena_allocator.cpp +1 -2
  344. package/src/duckdb/src/storage/buffer/block_manager.cpp +3 -0
  345. package/src/duckdb/src/storage/checkpoint_manager.cpp +3 -0
  346. package/src/duckdb/src/storage/data_table.cpp +1 -1
  347. package/src/duckdb/src/storage/local_storage.cpp +3 -3
  348. package/src/duckdb/src/storage/single_file_block_manager.cpp +23 -0
  349. package/src/duckdb/src/storage/statistics/string_stats.cpp +21 -2
  350. package/src/duckdb/src/storage/storage_info.cpp +1 -1
  351. package/src/duckdb/src/storage/storage_manager.cpp +7 -2
  352. package/src/duckdb/src/storage/table/chunk_info.cpp +17 -0
  353. package/src/duckdb/src/storage/table/row_group.cpp +25 -9
  354. package/src/duckdb/src/storage/table/row_group_collection.cpp +19 -18
  355. package/src/duckdb/third_party/concurrentqueue/concurrentqueue.h +2 -2
  356. package/src/duckdb/third_party/concurrentqueue/lightweightsemaphore.h +76 -0
  357. package/src/duckdb/third_party/fast_float/fast_float/fast_float.h +2 -0
  358. package/src/duckdb/third_party/httplib/httplib.hpp +10 -1
  359. package/src/duckdb/third_party/libpg_query/include/nodes/parsenodes.hpp +9 -0
  360. package/src/duckdb/third_party/libpg_query/include/parser/gram.hpp +2 -1
  361. package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +12487 -12331
  362. package/src/duckdb/ub_extension_icu_third_party_icu_i18n.cpp +5 -5
  363. package/src/duckdb/ub_src_execution_index_art.cpp +0 -2
  364. package/src/duckdb/ub_src_execution_operator_persistent.cpp +2 -0
  365. package/src/duckdb/ub_src_execution_operator_set.cpp +2 -0
  366. package/src/duckdb/ub_src_execution_physical_plan.cpp +2 -0
  367. package/src/duckdb/ub_src_function_scalar.cpp +2 -0
  368. package/src/duckdb/ub_src_function_scalar_compressed_materialization.cpp +4 -0
  369. package/src/duckdb/ub_src_function_scalar_list.cpp +2 -0
  370. package/src/duckdb/ub_src_optimizer.cpp +6 -0
  371. package/src/duckdb/ub_src_optimizer_compressed_materialization.cpp +6 -0
  372. package/src/duckdb/ub_src_optimizer_statistics_expression.cpp +0 -2
  373. package/src/duckdb/ub_src_parser_query_node.cpp +2 -0
  374. package/src/duckdb/ub_src_parser_transform_expression.cpp +2 -0
  375. package/src/duckdb/ub_src_planner_binder_query_node.cpp +4 -0
  376. package/src/duckdb/ub_src_planner_operator.cpp +4 -0
  377. package/src/duckdb_node.hpp +1 -0
  378. package/src/statement.cpp +103 -4
  379. package/test/columns.test.ts +243 -0
  380. package/test/test_all_types.test.ts +233 -0
  381. package/tsconfig.json +1 -0
  382. package/src/duckdb/src/execution/index/art/prefix_segment.cpp +0 -42
  383. package/src/duckdb/src/include/duckdb/execution/index/art/prefix_segment.hpp +0 -40
  384. package/src/duckdb/src/optimizer/statistics/expression/propagate_and_compress.cpp +0 -118
  385. /package/src/duckdb/extension/parquet/include/{parquet-extension.hpp → parquet_extension.hpp} +0 -0
@@ -2,18 +2,18 @@
2
2
 
3
3
  #include "duckdb/catalog/catalog_search_path.hpp"
4
4
  #include "duckdb/common/string_util.hpp"
5
+ #include "duckdb/main/attached_database.hpp"
5
6
  #include "duckdb/main/client_context.hpp"
6
7
  #include "duckdb/main/client_data.hpp"
7
8
  #include "duckdb/main/config.hpp"
9
+ #include "duckdb/main/database.hpp"
10
+ #include "duckdb/main/database_manager.hpp"
8
11
  #include "duckdb/main/query_profiler.hpp"
9
12
  #include "duckdb/parallel/task_scheduler.hpp"
10
13
  #include "duckdb/parser/parser.hpp"
11
14
  #include "duckdb/planner/expression_binder.hpp"
12
15
  #include "duckdb/storage/buffer_manager.hpp"
13
16
  #include "duckdb/storage/storage_manager.hpp"
14
- #include "duckdb/main/database_manager.hpp"
15
- #include "duckdb/main/attached_database.hpp"
16
- #include "duckdb/main/database.hpp"
17
17
 
18
18
  namespace duckdb {
19
19
 
@@ -112,7 +112,6 @@ Value DebugCheckpointAbort::GetSetting(ClientContext &context) {
112
112
  //===--------------------------------------------------------------------===//
113
113
  // Debug Force External
114
114
  //===--------------------------------------------------------------------===//
115
-
116
115
  void DebugForceExternal::ResetLocal(ClientContext &context) {
117
116
  ClientConfig::GetConfig(context).force_external = ClientConfig().force_external;
118
117
  }
@@ -128,7 +127,6 @@ Value DebugForceExternal::GetSetting(ClientContext &context) {
128
127
  //===--------------------------------------------------------------------===//
129
128
  // Debug Force NoCrossProduct
130
129
  //===--------------------------------------------------------------------===//
131
-
132
130
  void DebugForceNoCrossProduct::ResetLocal(ClientContext &context) {
133
131
  ClientConfig::GetConfig(context).force_no_cross_product = ClientConfig().force_no_cross_product;
134
132
  }
@@ -144,7 +142,6 @@ Value DebugForceNoCrossProduct::GetSetting(ClientContext &context) {
144
142
  //===--------------------------------------------------------------------===//
145
143
  // Ordered Aggregate Threshold
146
144
  //===--------------------------------------------------------------------===//
147
-
148
145
  void OrderedAggregateThreshold::ResetLocal(ClientContext &context) {
149
146
  ClientConfig::GetConfig(context).ordered_aggregate_threshold = ClientConfig().ordered_aggregate_threshold;
150
147
  }
@@ -478,7 +475,6 @@ Value EnableProfilingSetting::GetSetting(ClientContext &context) {
478
475
  //===--------------------------------------------------------------------===//
479
476
  // Custom Extension Repository
480
477
  //===--------------------------------------------------------------------===//
481
-
482
478
  void CustomExtensionRepository::ResetLocal(ClientContext &context) {
483
479
  ClientConfig::GetConfig(context).custom_extension_repo = ClientConfig().custom_extension_repo;
484
480
  }
@@ -494,7 +490,6 @@ Value CustomExtensionRepository::GetSetting(ClientContext &context) {
494
490
  //===--------------------------------------------------------------------===//
495
491
  // Enable Progress Bar
496
492
  //===--------------------------------------------------------------------===//
497
-
498
493
  void EnableProgressBarSetting::ResetLocal(ClientContext &context) {
499
494
  auto &config = ClientConfig::GetConfig(context);
500
495
  ProgressBar::SystemOverrideCheck(config);
@@ -548,7 +543,6 @@ Value ExperimentalParallelCSVSetting::GetSetting(ClientContext &context) {
548
543
  //===--------------------------------------------------------------------===//
549
544
  // Explain Output
550
545
  //===--------------------------------------------------------------------===//
551
-
552
546
  void ExplainOutputSetting::ResetLocal(ClientContext &context) {
553
547
  ClientConfig::GetConfig(context).explain_output_type = ClientConfig().explain_output_type;
554
548
  }
@@ -686,7 +680,6 @@ Value ForceBitpackingModeSetting::GetSetting(ClientContext &context) {
686
680
  //===--------------------------------------------------------------------===//
687
681
  // Home Directory
688
682
  //===--------------------------------------------------------------------===//
689
-
690
683
  void HomeDirectorySetting::ResetLocal(ClientContext &context) {
691
684
  ClientConfig::GetConfig(context).home_directory = ClientConfig().home_directory;
692
685
  }
@@ -780,7 +773,6 @@ Value ImmediateTransactionModeSetting::GetSetting(ClientContext &context) {
780
773
  //===--------------------------------------------------------------------===//
781
774
  // Maximum Expression Depth
782
775
  //===--------------------------------------------------------------------===//
783
-
784
776
  void MaximumExpressionDepthSetting::ResetLocal(ClientContext &context) {
785
777
  ClientConfig::GetConfig(context).max_expression_depth = ClientConfig().max_expression_depth;
786
778
  }
@@ -830,7 +822,6 @@ Value PasswordSetting::GetSetting(ClientContext &context) {
830
822
  //===--------------------------------------------------------------------===//
831
823
  // Perfect Hash Threshold
832
824
  //===--------------------------------------------------------------------===//
833
-
834
825
  void PerfectHashThresholdSetting::ResetLocal(ClientContext &context) {
835
826
  ClientConfig::GetConfig(context).perfect_ht_threshold = ClientConfig().perfect_ht_threshold;
836
827
  }
@@ -848,9 +839,23 @@ Value PerfectHashThresholdSetting::GetSetting(ClientContext &context) {
848
839
  }
849
840
 
850
841
  //===--------------------------------------------------------------------===//
851
- // Pivot Limit
842
+ // Pivot Filter Threshold
852
843
  //===--------------------------------------------------------------------===//
844
+ void PivotFilterThreshold::ResetLocal(ClientContext &context) {
845
+ ClientConfig::GetConfig(context).pivot_filter_threshold = ClientConfig().pivot_filter_threshold;
846
+ }
847
+
848
+ void PivotFilterThreshold::SetLocal(ClientContext &context, const Value &input) {
849
+ ClientConfig::GetConfig(context).pivot_filter_threshold = input.GetValue<uint64_t>();
850
+ }
851
+
852
+ Value PivotFilterThreshold::GetSetting(ClientContext &context) {
853
+ return Value::BIGINT(ClientConfig::GetConfig(context).pivot_filter_threshold);
854
+ }
853
855
 
856
+ //===--------------------------------------------------------------------===//
857
+ // Pivot Limit
858
+ //===--------------------------------------------------------------------===//
854
859
  void PivotLimitSetting::ResetLocal(ClientContext &context) {
855
860
  ClientConfig::GetConfig(context).pivot_limit = ClientConfig().pivot_limit;
856
861
  }
@@ -866,7 +871,6 @@ Value PivotLimitSetting::GetSetting(ClientContext &context) {
866
871
  //===--------------------------------------------------------------------===//
867
872
  // PreserveIdentifierCase
868
873
  //===--------------------------------------------------------------------===//
869
-
870
874
  void PreserveIdentifierCase::ResetLocal(ClientContext &context) {
871
875
  ClientConfig::GetConfig(context).preserve_identifier_case = ClientConfig().preserve_identifier_case;
872
876
  }
@@ -917,7 +921,6 @@ Value ExportLargeBufferArrow::GetSetting(ClientContext &context) {
917
921
  //===--------------------------------------------------------------------===//
918
922
  // Profiler History Size
919
923
  //===--------------------------------------------------------------------===//
920
-
921
924
  void ProfilerHistorySize::ResetLocal(ClientContext &context) {
922
925
  auto &client_data = ClientData::Get(context);
923
926
  client_data.query_profiler_history->ResetProfilerHistorySize();
@@ -939,7 +942,6 @@ Value ProfilerHistorySize::GetSetting(ClientContext &context) {
939
942
  //===--------------------------------------------------------------------===//
940
943
  // Profile Output
941
944
  //===--------------------------------------------------------------------===//
942
-
943
945
  void ProfileOutputSetting::ResetLocal(ClientContext &context) {
944
946
  ClientConfig::GetConfig(context).profiler_save_location = ClientConfig().profiler_save_location;
945
947
  }
@@ -958,7 +960,6 @@ Value ProfileOutputSetting::GetSetting(ClientContext &context) {
958
960
  //===--------------------------------------------------------------------===//
959
961
  // Profiling Mode
960
962
  //===--------------------------------------------------------------------===//
961
-
962
963
  void ProfilingModeSetting::ResetLocal(ClientContext &context) {
963
964
  ClientConfig::GetConfig(context).enable_profiler = ClientConfig().enable_profiler;
964
965
  ClientConfig::GetConfig(context).enable_detailed_profiling = ClientConfig().enable_detailed_profiling;
@@ -992,7 +993,6 @@ Value ProfilingModeSetting::GetSetting(ClientContext &context) {
992
993
  //===--------------------------------------------------------------------===//
993
994
  // Progress Bar Time
994
995
  //===--------------------------------------------------------------------===//
995
-
996
996
  void ProgressBarTimeSetting::ResetLocal(ClientContext &context) {
997
997
  auto &config = ClientConfig::GetConfig(context);
998
998
  ProgressBar::SystemOverrideCheck(config);
@@ -1112,4 +1112,26 @@ Value UsernameSetting::GetSetting(ClientContext &context) {
1112
1112
  return Value();
1113
1113
  }
1114
1114
 
1115
+ //===--------------------------------------------------------------------===//
1116
+ // Allocator Flush Threshold
1117
+ //===--------------------------------------------------------------------===//
1118
+ void FlushAllocatorSetting::SetGlobal(DatabaseInstance *db, DBConfig &config, const Value &input) {
1119
+ config.options.allocator_flush_threshold = DBConfig::ParseMemoryLimit(input.ToString());
1120
+ if (db) {
1121
+ TaskScheduler::GetScheduler(*db).SetAllocatorFlushTreshold(config.options.allocator_flush_threshold);
1122
+ }
1123
+ }
1124
+
1125
+ void FlushAllocatorSetting::ResetGlobal(DatabaseInstance *db, DBConfig &config) {
1126
+ config.options.allocator_flush_threshold = DBConfig().options.allocator_flush_threshold;
1127
+ if (db) {
1128
+ TaskScheduler::GetScheduler(*db).SetAllocatorFlushTreshold(config.options.allocator_flush_threshold);
1129
+ }
1130
+ }
1131
+
1132
+ Value FlushAllocatorSetting::GetSetting(ClientContext &context) {
1133
+ auto &config = DBConfig::GetConfig(context);
1134
+ return Value(StringUtil::BytesToHumanReadableString(config.options.allocator_flush_threshold));
1135
+ }
1136
+
1115
1137
  } // namespace duckdb
@@ -0,0 +1,43 @@
1
+ #include "duckdb/optimizer/column_binding_replacer.hpp"
2
+
3
+ #include "duckdb/planner/expression/bound_columnref_expression.hpp"
4
+
5
+ namespace duckdb {
6
+
7
+ ReplacementBinding::ReplacementBinding(ColumnBinding old_binding, ColumnBinding new_binding)
8
+ : old_binding(old_binding), new_binding(new_binding), replace_type(false) {
9
+ }
10
+
11
+ ReplacementBinding::ReplacementBinding(ColumnBinding old_binding, ColumnBinding new_binding, LogicalType new_type)
12
+ : old_binding(old_binding), new_binding(new_binding), replace_type(true), new_type(std::move(new_type)) {
13
+ }
14
+
15
+ ColumnBindingReplacer::ColumnBindingReplacer() {
16
+ }
17
+
18
+ void ColumnBindingReplacer::VisitOperator(LogicalOperator &op) {
19
+ if (stop_operator && stop_operator.get() == &op) {
20
+ return;
21
+ }
22
+ VisitOperatorChildren(op);
23
+ VisitOperatorExpressions(op);
24
+ }
25
+
26
+ void ColumnBindingReplacer::VisitExpression(unique_ptr<Expression> *expression) {
27
+ auto &expr = *expression;
28
+ if (expr->expression_class == ExpressionClass::BOUND_COLUMN_REF) {
29
+ auto &bound_column_ref = expr->Cast<BoundColumnRefExpression>();
30
+ for (const auto &replace_binding : replacement_bindings) {
31
+ if (bound_column_ref.binding == replace_binding.old_binding) {
32
+ bound_column_ref.binding = replace_binding.new_binding;
33
+ if (replace_binding.replace_type) {
34
+ bound_column_ref.return_type = replace_binding.new_type;
35
+ }
36
+ }
37
+ }
38
+ }
39
+
40
+ VisitExpressionChildren(**expression);
41
+ }
42
+
43
+ } // namespace duckdb
@@ -1,7 +1,5 @@
1
1
  #include "duckdb/optimizer/column_lifetime_optimizer.hpp"
2
-
3
2
  #include "duckdb/planner/expression/bound_columnref_expression.hpp"
4
-
5
3
  #include "duckdb/planner/operator/logical_comparison_join.hpp"
6
4
  #include "duckdb/planner/operator/logical_delim_join.hpp"
7
5
  #include "duckdb/planner/operator/logical_filter.hpp"
@@ -20,6 +18,7 @@ void ColumnLifetimeAnalyzer::ExtractUnusedColumnBindings(vector<ColumnBinding> b
20
18
  void ColumnLifetimeAnalyzer::GenerateProjectionMap(vector<ColumnBinding> bindings,
21
19
  column_binding_set_t &unused_bindings,
22
20
  vector<idx_t> &projection_map) {
21
+ projection_map.clear();
23
22
  if (unused_bindings.empty()) {
24
23
  return;
25
24
  }
@@ -0,0 +1,140 @@
1
+ #include "duckdb/optimizer/compressed_materialization.hpp"
2
+ #include "duckdb/planner/expression/bound_aggregate_expression.hpp"
3
+ #include "duckdb/planner/expression/bound_columnref_expression.hpp"
4
+ #include "duckdb/planner/operator/logical_aggregate.hpp"
5
+
6
+ namespace duckdb {
7
+
8
+ void CompressedMaterialization::CompressAggregate(unique_ptr<LogicalOperator> &op) {
9
+ auto &aggregate = op->Cast<LogicalAggregate>();
10
+ auto &groups = aggregate.groups;
11
+ column_binding_set_t group_binding_set;
12
+ for (const auto &group : groups) {
13
+ if (group->type != ExpressionType::BOUND_COLUMN_REF) {
14
+ continue;
15
+ }
16
+ auto &colref = group->Cast<BoundColumnRefExpression>();
17
+ if (group_binding_set.find(colref.binding) != group_binding_set.end()) {
18
+ return; // Duplicate group - don't compress
19
+ }
20
+ group_binding_set.insert(colref.binding);
21
+ }
22
+ auto &group_stats = aggregate.group_stats;
23
+
24
+ // No need to compress if there are no groups/stats
25
+ if (groups.empty() || group_stats.empty()) {
26
+ return;
27
+ }
28
+ D_ASSERT(groups.size() == group_stats.size());
29
+
30
+ // Find all bindings referenced by non-colref expressions in the groups
31
+ // These are excluded from compression by projection
32
+ // But we can try to compress the expression directly
33
+ column_binding_set_t referenced_bindings;
34
+ vector<ColumnBinding> group_bindings(groups.size(), ColumnBinding());
35
+ vector<bool> needs_decompression(groups.size(), false);
36
+ vector<unique_ptr<BaseStatistics>> stored_group_stats;
37
+ stored_group_stats.resize(groups.size());
38
+ for (idx_t group_idx = 0; group_idx < groups.size(); group_idx++) {
39
+ auto &group_expr = *groups[group_idx];
40
+ if (group_expr.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) {
41
+ auto &colref = group_expr.Cast<BoundColumnRefExpression>();
42
+ group_bindings[group_idx] = colref.binding;
43
+ continue; // Will be compressed generically
44
+ }
45
+
46
+ // Mark the bindings referenced by the non-colref expression so they won't be modified
47
+ GetReferencedBindings(group_expr, referenced_bindings);
48
+
49
+ // The non-colref expression won't be compressed generically, so try to compress it here
50
+ if (!group_stats[group_idx]) {
51
+ continue; // Can't compress without stats
52
+ }
53
+
54
+ // Try to compress, if successful, replace the expression
55
+ auto compress_expr = GetCompressExpression(group_expr.Copy(), *group_stats[group_idx]);
56
+ if (compress_expr) {
57
+ needs_decompression[group_idx] = true;
58
+ stored_group_stats[group_idx] = std::move(group_stats[group_idx]);
59
+ groups[group_idx] = std::move(compress_expr->expression);
60
+ group_stats[group_idx] = std::move(compress_expr->stats);
61
+ }
62
+ }
63
+
64
+ // Anything referenced in the aggregate functions is also excluded
65
+ for (idx_t expr_idx = 0; expr_idx < aggregate.expressions.size(); expr_idx++) {
66
+ const auto &expr = *aggregate.expressions[expr_idx];
67
+ D_ASSERT(expr.type == ExpressionType::BOUND_AGGREGATE);
68
+ const auto &aggr_expr = expr.Cast<BoundAggregateExpression>();
69
+ for (const auto &child : aggr_expr.children) {
70
+ GetReferencedBindings(*child, referenced_bindings);
71
+ }
72
+ if (aggr_expr.filter) {
73
+ GetReferencedBindings(*aggr_expr.filter, referenced_bindings);
74
+ }
75
+ if (aggr_expr.order_bys) {
76
+ for (const auto &order : aggr_expr.order_bys->orders) {
77
+ const auto &order_expr = *order.expression;
78
+ if (order_expr.type != ExpressionType::BOUND_COLUMN_REF) {
79
+ GetReferencedBindings(order_expr, referenced_bindings);
80
+ }
81
+ }
82
+ }
83
+ }
84
+
85
+ // Create info for compression
86
+ CompressedMaterializationInfo info(*op, {0}, referenced_bindings);
87
+
88
+ // Create binding mapping
89
+ const auto bindings_out = aggregate.GetColumnBindings();
90
+ const auto &types = aggregate.types;
91
+ for (idx_t group_idx = 0; group_idx < groups.size(); group_idx++) {
92
+ // Aggregate changes bindings as it has a table idx
93
+ CMBindingInfo binding_info(bindings_out[group_idx], types[group_idx]);
94
+ binding_info.needs_decompression = needs_decompression[group_idx];
95
+ if (needs_decompression[group_idx]) {
96
+ // Compressed non-generically
97
+ auto entry = info.binding_map.emplace(bindings_out[group_idx], std::move(binding_info));
98
+ entry.first->second.stats = std::move(stored_group_stats[group_idx]);
99
+ } else if (group_bindings[group_idx] != ColumnBinding()) {
100
+ info.binding_map.emplace(group_bindings[group_idx], std::move(binding_info));
101
+ }
102
+ }
103
+
104
+ // Now try to compress
105
+ CreateProjections(op, info);
106
+
107
+ // Update aggregate statistics
108
+ UpdateAggregateStats(op);
109
+ }
110
+
111
+ void CompressedMaterialization::UpdateAggregateStats(unique_ptr<LogicalOperator> &op) {
112
+ if (op->type != LogicalOperatorType::LOGICAL_PROJECTION) {
113
+ return;
114
+ }
115
+
116
+ // Update aggregate group stats if compressed
117
+ auto &compressed_aggregate = op->children[0]->Cast<LogicalAggregate>();
118
+ auto &groups = compressed_aggregate.groups;
119
+ auto &group_stats = compressed_aggregate.group_stats;
120
+
121
+ for (idx_t group_idx = 0; group_idx < groups.size(); group_idx++) {
122
+ auto &group_expr = *groups[group_idx];
123
+ if (group_expr.GetExpressionType() != ExpressionType::BOUND_COLUMN_REF) {
124
+ continue;
125
+ }
126
+ auto &colref = group_expr.Cast<BoundColumnRefExpression>();
127
+ if (!group_stats[group_idx]) {
128
+ continue;
129
+ }
130
+ if (colref.return_type == group_stats[group_idx]->GetType()) {
131
+ continue;
132
+ }
133
+ auto it = statistics_map.find(colref.binding);
134
+ if (it != statistics_map.end() && it->second) {
135
+ group_stats[group_idx] = it->second->ToUnique();
136
+ }
137
+ }
138
+ }
139
+
140
+ } // namespace duckdb
@@ -0,0 +1,42 @@
1
+ #include "duckdb/optimizer/compressed_materialization.hpp"
2
+ #include "duckdb/planner/expression/bound_columnref_expression.hpp"
3
+ #include "duckdb/planner/operator/logical_distinct.hpp"
4
+
5
+ namespace duckdb {
6
+
7
+ void CompressedMaterialization::CompressDistinct(unique_ptr<LogicalOperator> &op) {
8
+ auto &distinct = op->Cast<LogicalDistinct>();
9
+ auto &distinct_targets = distinct.distinct_targets;
10
+
11
+ column_binding_set_t referenced_bindings;
12
+ for (auto &target : distinct_targets) {
13
+ if (target->type != ExpressionType::BOUND_COLUMN_REF) { // LCOV_EXCL_START
14
+ GetReferencedBindings(*target, referenced_bindings);
15
+ } // LCOV_EXCL_STOP
16
+ }
17
+
18
+ if (distinct.order_by) {
19
+ for (auto &order : distinct.order_by->orders) {
20
+ if (order.expression->type != ExpressionType::BOUND_COLUMN_REF) { // LCOV_EXCL_START
21
+ GetReferencedBindings(*order.expression, referenced_bindings);
22
+ } // LCOV_EXCL_STOP
23
+ }
24
+ }
25
+
26
+ // Create info for compression
27
+ CompressedMaterializationInfo info(*op, {0}, referenced_bindings);
28
+
29
+ // Create binding mapping
30
+ const auto bindings = distinct.GetColumnBindings();
31
+ const auto &types = distinct.types;
32
+ D_ASSERT(bindings.size() == types.size());
33
+ for (idx_t col_idx = 0; col_idx < bindings.size(); col_idx++) {
34
+ // Distinct does not change bindings, input binding is output binding
35
+ info.binding_map.emplace(bindings[col_idx], CMBindingInfo(bindings[col_idx], types[col_idx]));
36
+ }
37
+
38
+ // Now try to compress
39
+ CreateProjections(op, info);
40
+ }
41
+
42
+ } // namespace duckdb
@@ -0,0 +1,65 @@
1
+ #include "duckdb/optimizer/compressed_materialization.hpp"
2
+ #include "duckdb/planner/expression/bound_columnref_expression.hpp"
3
+ #include "duckdb/planner/operator/logical_order.hpp"
4
+
5
+ namespace duckdb {
6
+
7
+ void CompressedMaterialization::CompressOrder(unique_ptr<LogicalOperator> &op) {
8
+ auto &order = op->Cast<LogicalOrder>();
9
+
10
+ // Find all bindings referenced by non-colref expressions in the order nodes
11
+ // These are excluded from compression by projection
12
+ // But we can try to compress the expression directly
13
+ column_binding_set_t referenced_bindings;
14
+ for (idx_t order_node_idx = 0; order_node_idx < order.orders.size(); order_node_idx++) {
15
+ auto &bound_order = order.orders[order_node_idx];
16
+ auto &order_expression = *bound_order.expression;
17
+ if (order_expression.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) {
18
+ continue; // Will be compressed generically
19
+ }
20
+
21
+ // Mark the bindings referenced by the non-colref expression so they won't be modified
22
+ GetReferencedBindings(order_expression, referenced_bindings);
23
+ }
24
+
25
+ // Create info for compression
26
+ CompressedMaterializationInfo info(*op, {0}, referenced_bindings);
27
+
28
+ // Create binding mapping
29
+ const auto bindings = order.GetColumnBindings();
30
+ const auto &types = order.types;
31
+ D_ASSERT(bindings.size() == types.size());
32
+ for (idx_t col_idx = 0; col_idx < bindings.size(); col_idx++) {
33
+ // Order does not change bindings, input binding is output binding
34
+ info.binding_map.emplace(bindings[col_idx], CMBindingInfo(bindings[col_idx], types[col_idx]));
35
+ }
36
+
37
+ // Now try to compress
38
+ CreateProjections(op, info);
39
+
40
+ // Update order statistics
41
+ UpdateOrderStats(op);
42
+ }
43
+
44
+ void CompressedMaterialization::UpdateOrderStats(unique_ptr<LogicalOperator> &op) {
45
+ if (op->type != LogicalOperatorType::LOGICAL_PROJECTION) {
46
+ return;
47
+ }
48
+
49
+ // Update order stats if compressed
50
+ auto &compressed_order = op->children[0]->Cast<LogicalOrder>();
51
+ for (idx_t order_node_idx = 0; order_node_idx < compressed_order.orders.size(); order_node_idx++) {
52
+ auto &bound_order = compressed_order.orders[order_node_idx];
53
+ auto &order_expression = *bound_order.expression;
54
+ if (order_expression.GetExpressionType() != ExpressionType::BOUND_COLUMN_REF) {
55
+ continue;
56
+ }
57
+ auto &colref = order_expression.Cast<BoundColumnRefExpression>();
58
+ auto it = statistics_map.find(colref.binding);
59
+ if (it != statistics_map.end() && it->second) {
60
+ bound_order.stats = it->second->ToUnique();
61
+ }
62
+ }
63
+ }
64
+
65
+ } // namespace duckdb