duckdb 0.7.2-dev1901.0 → 0.7.2-dev2144.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 (179) hide show
  1. package/binding.gyp +2 -0
  2. package/package.json +1 -1
  3. package/src/duckdb/extension/parquet/include/parquet_writer.hpp +1 -1
  4. package/src/duckdb/extension/parquet/parquet_metadata.cpp +4 -2
  5. package/src/duckdb/src/catalog/catalog_entry/duck_index_entry.cpp +1 -1
  6. package/src/duckdb/src/common/arrow/arrow_appender.cpp +69 -44
  7. package/src/duckdb/src/common/arrow/arrow_converter.cpp +1 -1
  8. package/src/duckdb/src/common/arrow/arrow_wrapper.cpp +20 -2
  9. package/src/duckdb/src/common/box_renderer.cpp +4 -2
  10. package/src/duckdb/src/common/constants.cpp +10 -1
  11. package/src/duckdb/src/common/filename_pattern.cpp +41 -0
  12. package/src/duckdb/src/common/hive_partitioning.cpp +144 -15
  13. package/src/duckdb/src/common/radix_partitioning.cpp +101 -369
  14. package/src/duckdb/src/common/row_operations/row_aggregate.cpp +8 -9
  15. package/src/duckdb/src/common/row_operations/row_external.cpp +1 -1
  16. package/src/duckdb/src/common/row_operations/row_gather.cpp +5 -3
  17. package/src/duckdb/src/common/row_operations/row_match.cpp +117 -22
  18. package/src/duckdb/src/common/row_operations/row_scatter.cpp +2 -2
  19. package/src/duckdb/src/common/sort/partition_state.cpp +1 -1
  20. package/src/duckdb/src/common/sort/sort_state.cpp +2 -1
  21. package/src/duckdb/src/common/sort/sorted_block.cpp +1 -1
  22. package/src/duckdb/src/common/types/{column_data_allocator.cpp → column/column_data_allocator.cpp} +2 -2
  23. package/src/duckdb/src/common/types/{column_data_collection.cpp → column/column_data_collection.cpp} +22 -4
  24. package/src/duckdb/src/common/types/{column_data_collection_segment.cpp → column/column_data_collection_segment.cpp} +2 -1
  25. package/src/duckdb/src/common/types/{column_data_consumer.cpp → column/column_data_consumer.cpp} +1 -1
  26. package/src/duckdb/src/common/types/{partitioned_column_data.cpp → column/partitioned_column_data.cpp} +11 -9
  27. package/src/duckdb/src/common/types/row/partitioned_tuple_data.cpp +316 -0
  28. package/src/duckdb/src/common/types/{row_data_collection.cpp → row/row_data_collection.cpp} +1 -1
  29. package/src/duckdb/src/common/types/{row_data_collection_scanner.cpp → row/row_data_collection_scanner.cpp} +2 -2
  30. package/src/duckdb/src/common/types/{row_layout.cpp → row/row_layout.cpp} +1 -1
  31. package/src/duckdb/src/common/types/row/tuple_data_allocator.cpp +465 -0
  32. package/src/duckdb/src/common/types/row/tuple_data_collection.cpp +511 -0
  33. package/src/duckdb/src/common/types/row/tuple_data_iterator.cpp +96 -0
  34. package/src/duckdb/src/common/types/row/tuple_data_layout.cpp +119 -0
  35. package/src/duckdb/src/common/types/row/tuple_data_scatter_gather.cpp +1200 -0
  36. package/src/duckdb/src/common/types/row/tuple_data_segment.cpp +170 -0
  37. package/src/duckdb/src/common/types/vector.cpp +1 -1
  38. package/src/duckdb/src/execution/aggregate_hashtable.cpp +252 -290
  39. package/src/duckdb/src/execution/join_hashtable.cpp +192 -328
  40. package/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +4 -4
  41. package/src/duckdb/src/execution/operator/helper/physical_execute.cpp +3 -3
  42. package/src/duckdb/src/execution/operator/helper/physical_limit_percent.cpp +2 -3
  43. package/src/duckdb/src/execution/operator/helper/physical_result_collector.cpp +2 -3
  44. package/src/duckdb/src/execution/operator/join/perfect_hash_join_executor.cpp +36 -21
  45. package/src/duckdb/src/execution/operator/join/physical_blockwise_nl_join.cpp +2 -2
  46. package/src/duckdb/src/execution/operator/join/physical_cross_product.cpp +1 -1
  47. package/src/duckdb/src/execution/operator/join/physical_delim_join.cpp +2 -2
  48. package/src/duckdb/src/execution/operator/join/physical_hash_join.cpp +166 -144
  49. package/src/duckdb/src/execution/operator/join/physical_index_join.cpp +5 -5
  50. package/src/duckdb/src/execution/operator/join/physical_join.cpp +2 -10
  51. package/src/duckdb/src/execution/operator/join/physical_positional_join.cpp +0 -1
  52. package/src/duckdb/src/execution/operator/order/physical_top_n.cpp +2 -2
  53. package/src/duckdb/src/execution/operator/persistent/physical_copy_to_file.cpp +13 -11
  54. package/src/duckdb/src/execution/operator/persistent/physical_delete.cpp +3 -2
  55. package/src/duckdb/src/execution/operator/persistent/physical_export.cpp +25 -24
  56. package/src/duckdb/src/execution/operator/persistent/physical_insert.cpp +1 -1
  57. package/src/duckdb/src/execution/operator/persistent/physical_update.cpp +4 -3
  58. package/src/duckdb/src/execution/operator/schema/physical_create_type.cpp +1 -1
  59. package/src/duckdb/src/execution/operator/set/physical_recursive_cte.cpp +3 -3
  60. package/src/duckdb/src/execution/partitionable_hashtable.cpp +9 -37
  61. package/src/duckdb/src/execution/physical_operator.cpp +1 -1
  62. package/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp +19 -18
  63. package/src/duckdb/src/execution/physical_plan/plan_copy_to_file.cpp +2 -1
  64. package/src/duckdb/src/execution/physical_plan/plan_execute.cpp +2 -2
  65. package/src/duckdb/src/execution/physical_plan/plan_explain.cpp +5 -6
  66. package/src/duckdb/src/execution/physical_plan/plan_expression_get.cpp +2 -2
  67. package/src/duckdb/src/execution/physical_plan/plan_recursive_cte.cpp +3 -3
  68. package/src/duckdb/src/execution/physical_plan_generator.cpp +1 -1
  69. package/src/duckdb/src/execution/radix_partitioned_hashtable.cpp +39 -17
  70. package/src/duckdb/src/function/aggregate/sorted_aggregate_function.cpp +2 -2
  71. package/src/duckdb/src/function/table/pragma_detailed_profiling_output.cpp +5 -5
  72. package/src/duckdb/src/function/table/pragma_last_profiling_output.cpp +2 -2
  73. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  74. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/index_catalog_entry.hpp +1 -1
  75. package/src/duckdb/src/include/duckdb/common/arrow/arrow_appender.hpp +1 -1
  76. package/src/duckdb/src/include/duckdb/common/constants.hpp +2 -0
  77. package/src/duckdb/src/include/duckdb/common/exception.hpp +3 -0
  78. package/src/duckdb/src/include/duckdb/common/fast_mem.hpp +528 -0
  79. package/src/duckdb/src/include/duckdb/common/filename_pattern.hpp +34 -0
  80. package/src/duckdb/src/include/duckdb/common/helper.hpp +10 -0
  81. package/src/duckdb/src/include/duckdb/common/hive_partitioning.hpp +13 -3
  82. package/src/duckdb/src/include/duckdb/common/optional_ptr.hpp +8 -0
  83. package/src/duckdb/src/include/duckdb/common/perfect_map_set.hpp +34 -0
  84. package/src/duckdb/src/include/duckdb/common/radix_partitioning.hpp +80 -27
  85. package/src/duckdb/src/include/duckdb/common/reference_map.hpp +38 -0
  86. package/src/duckdb/src/include/duckdb/common/row_operations/row_operations.hpp +7 -6
  87. package/src/duckdb/src/include/duckdb/common/sort/comparators.hpp +1 -1
  88. package/src/duckdb/src/include/duckdb/common/sort/partition_state.hpp +1 -1
  89. package/src/duckdb/src/include/duckdb/common/sort/sort.hpp +1 -1
  90. package/src/duckdb/src/include/duckdb/common/sort/sorted_block.hpp +2 -2
  91. package/src/duckdb/src/include/duckdb/common/types/batched_data_collection.hpp +1 -1
  92. package/src/duckdb/src/include/duckdb/common/types/{column_data_allocator.hpp → column/column_data_allocator.hpp} +4 -4
  93. package/src/duckdb/src/include/duckdb/common/types/{column_data_collection.hpp → column/column_data_collection.hpp} +2 -2
  94. package/src/duckdb/src/include/duckdb/common/types/{column_data_collection_iterators.hpp → column/column_data_collection_iterators.hpp} +2 -2
  95. package/src/duckdb/src/include/duckdb/common/types/{column_data_collection_segment.hpp → column/column_data_collection_segment.hpp} +3 -3
  96. package/src/duckdb/src/include/duckdb/common/types/{column_data_consumer.hpp → column/column_data_consumer.hpp} +8 -4
  97. package/src/duckdb/src/include/duckdb/common/types/{column_data_scan_states.hpp → column/column_data_scan_states.hpp} +1 -1
  98. package/src/duckdb/src/include/duckdb/common/types/{partitioned_column_data.hpp → column/partitioned_column_data.hpp} +15 -7
  99. package/src/duckdb/src/include/duckdb/common/types/row/partitioned_tuple_data.hpp +140 -0
  100. package/src/duckdb/src/include/duckdb/common/types/{row_data_collection.hpp → row/row_data_collection.hpp} +1 -1
  101. package/src/duckdb/src/include/duckdb/common/types/{row_data_collection_scanner.hpp → row/row_data_collection_scanner.hpp} +2 -2
  102. package/src/duckdb/src/include/duckdb/common/types/{row_layout.hpp → row/row_layout.hpp} +3 -1
  103. package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_allocator.hpp +116 -0
  104. package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_collection.hpp +239 -0
  105. package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_iterator.hpp +64 -0
  106. package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_layout.hpp +113 -0
  107. package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_segment.hpp +124 -0
  108. package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_states.hpp +74 -0
  109. package/src/duckdb/src/include/duckdb/common/types/validity_mask.hpp +3 -0
  110. package/src/duckdb/src/include/duckdb/common/types/value.hpp +4 -12
  111. package/src/duckdb/src/include/duckdb/execution/aggregate_hashtable.hpp +34 -31
  112. package/src/duckdb/src/include/duckdb/execution/base_aggregate_hashtable.hpp +2 -2
  113. package/src/duckdb/src/include/duckdb/execution/execution_context.hpp +3 -2
  114. package/src/duckdb/src/include/duckdb/execution/expression_executor.hpp +1 -1
  115. package/src/duckdb/src/include/duckdb/execution/join_hashtable.hpp +41 -67
  116. package/src/duckdb/src/include/duckdb/execution/nested_loop_join.hpp +1 -1
  117. package/src/duckdb/src/include/duckdb/execution/operator/helper/physical_execute.hpp +2 -2
  118. package/src/duckdb/src/include/duckdb/execution/operator/helper/physical_result_collector.hpp +1 -1
  119. package/src/duckdb/src/include/duckdb/execution/operator/join/outer_join_marker.hpp +2 -2
  120. package/src/duckdb/src/include/duckdb/execution/operator/join/perfect_hash_join_executor.hpp +1 -1
  121. package/src/duckdb/src/include/duckdb/execution/operator/join/physical_cross_product.hpp +1 -1
  122. package/src/duckdb/src/include/duckdb/execution/operator/join/physical_hash_join.hpp +0 -2
  123. package/src/duckdb/src/include/duckdb/execution/operator/join/physical_index_join.hpp +2 -2
  124. package/src/duckdb/src/include/duckdb/execution/operator/join/physical_positional_join.hpp +1 -1
  125. package/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_copy_to_file.hpp +4 -1
  126. package/src/duckdb/src/include/duckdb/execution/operator/scan/physical_column_data_scan.hpp +1 -1
  127. package/src/duckdb/src/include/duckdb/execution/operator/set/physical_recursive_cte.hpp +1 -1
  128. package/src/duckdb/src/include/duckdb/execution/partitionable_hashtable.hpp +2 -2
  129. package/src/duckdb/src/include/duckdb/main/materialized_query_result.hpp +1 -1
  130. package/src/duckdb/src/include/duckdb/main/query_result.hpp +14 -1
  131. package/src/duckdb/src/include/duckdb/optimizer/expression_rewriter.hpp +3 -3
  132. package/src/duckdb/src/include/duckdb/optimizer/join_order/cardinality_estimator.hpp +16 -16
  133. package/src/duckdb/src/include/duckdb/optimizer/join_order/join_node.hpp +8 -8
  134. package/src/duckdb/src/include/duckdb/optimizer/join_order/join_order_optimizer.hpp +23 -15
  135. package/src/duckdb/src/include/duckdb/optimizer/join_order/join_relation.hpp +9 -10
  136. package/src/duckdb/src/include/duckdb/optimizer/join_order/query_graph.hpp +18 -11
  137. package/src/duckdb/src/include/duckdb/parallel/meta_pipeline.hpp +1 -1
  138. package/src/duckdb/src/include/duckdb/parser/parsed_data/exported_table_data.hpp +5 -1
  139. package/src/duckdb/src/include/duckdb/parser/parsed_data/vacuum_info.hpp +3 -2
  140. package/src/duckdb/src/include/duckdb/parser/query_error_context.hpp +4 -2
  141. package/src/duckdb/src/include/duckdb/parser/transformer.hpp +9 -35
  142. package/src/duckdb/src/include/duckdb/planner/binder.hpp +24 -23
  143. package/src/duckdb/src/include/duckdb/planner/expression_binder.hpp +3 -3
  144. package/src/duckdb/src/include/duckdb/planner/operator/logical_column_data_get.hpp +1 -1
  145. package/src/duckdb/src/include/duckdb/planner/operator/logical_copy_to_file.hpp +3 -1
  146. package/src/duckdb/src/include/duckdb/storage/table/table_index_list.hpp +1 -1
  147. package/src/duckdb/src/main/appender.cpp +6 -6
  148. package/src/duckdb/src/main/client_context.cpp +1 -1
  149. package/src/duckdb/src/main/connection.cpp +2 -2
  150. package/src/duckdb/src/main/query_result.cpp +13 -0
  151. package/src/duckdb/src/optimizer/expression_rewriter.cpp +4 -4
  152. package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +91 -105
  153. package/src/duckdb/src/optimizer/join_order/join_node.cpp +5 -8
  154. package/src/duckdb/src/optimizer/join_order/join_order_optimizer.cpp +163 -160
  155. package/src/duckdb/src/optimizer/join_order/join_relation_set.cpp +30 -30
  156. package/src/duckdb/src/optimizer/join_order/query_graph.cpp +37 -38
  157. package/src/duckdb/src/parallel/executor.cpp +1 -1
  158. package/src/duckdb/src/parallel/meta_pipeline.cpp +2 -2
  159. package/src/duckdb/src/parser/transform/helpers/transform_cte.cpp +1 -1
  160. package/src/duckdb/src/parser/transform/tableref/transform_subquery.cpp +1 -1
  161. package/src/duckdb/src/parser/transformer.cpp +50 -9
  162. package/src/duckdb/src/planner/binder/statement/bind_copy.cpp +15 -5
  163. package/src/duckdb/src/planner/binder/statement/bind_create.cpp +19 -17
  164. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +4 -4
  165. package/src/duckdb/src/planner/binder/statement/bind_export.cpp +20 -21
  166. package/src/duckdb/src/planner/binder/tableref/bind_basetableref.cpp +24 -22
  167. package/src/duckdb/src/planner/binder/tableref/bind_subqueryref.cpp +2 -2
  168. package/src/duckdb/src/planner/binder.cpp +16 -19
  169. package/src/duckdb/src/planner/expression_binder.cpp +8 -8
  170. package/src/duckdb/src/planner/operator/logical_copy_to_file.cpp +3 -3
  171. package/src/duckdb/src/storage/checkpoint_manager.cpp +23 -23
  172. package/src/duckdb/src/storage/standard_buffer_manager.cpp +1 -1
  173. package/src/duckdb/src/storage/table_index_list.cpp +3 -3
  174. package/src/duckdb/src/verification/statement_verifier.cpp +1 -1
  175. package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +5552 -5598
  176. package/src/duckdb/ub_src_common.cpp +2 -0
  177. package/src/duckdb/ub_src_common_types.cpp +0 -16
  178. package/src/duckdb/ub_src_common_types_column.cpp +10 -0
  179. package/src/duckdb/ub_src_common_types_row.cpp +20 -0
@@ -18,16 +18,16 @@ string JoinRelationSet::ToString() const {
18
18
  // LCOV_EXCL_STOP
19
19
 
20
20
  //! Returns true if sub is a subset of super
21
- bool JoinRelationSet::IsSubset(JoinRelationSet *super, JoinRelationSet *sub) {
22
- D_ASSERT(sub->count > 0);
23
- if (sub->count > super->count) {
21
+ bool JoinRelationSet::IsSubset(JoinRelationSet &super, JoinRelationSet &sub) {
22
+ D_ASSERT(sub.count > 0);
23
+ if (sub.count > super.count) {
24
24
  return false;
25
25
  }
26
26
  idx_t j = 0;
27
- for (idx_t i = 0; i < super->count; i++) {
28
- if (sub->relations[j] == super->relations[i]) {
27
+ for (idx_t i = 0; i < super.count; i++) {
28
+ if (sub.relations[j] == super.relations[i]) {
29
29
  j++;
30
- if (j == sub->count) {
30
+ if (j == sub.count) {
31
31
  return true;
32
32
  }
33
33
  }
@@ -35,29 +35,29 @@ bool JoinRelationSet::IsSubset(JoinRelationSet *super, JoinRelationSet *sub) {
35
35
  return false;
36
36
  }
37
37
 
38
- JoinRelationSet *JoinRelationSetManager::GetJoinRelation(unique_ptr<idx_t[]> relations, idx_t count) {
38
+ JoinRelationSet &JoinRelationSetManager::GetJoinRelation(unique_ptr<idx_t[]> relations, idx_t count) {
39
39
  // now look it up in the tree
40
- JoinRelationTreeNode *info = &root;
40
+ reference<JoinRelationTreeNode> info(root);
41
41
  for (idx_t i = 0; i < count; i++) {
42
- auto entry = info->children.find(relations[i]);
43
- if (entry == info->children.end()) {
42
+ auto entry = info.get().children.find(relations[i]);
43
+ if (entry == info.get().children.end()) {
44
44
  // node not found, create it
45
- auto insert_it = info->children.insert(make_pair(relations[i], make_uniq<JoinRelationTreeNode>()));
45
+ auto insert_it = info.get().children.insert(make_pair(relations[i], make_uniq<JoinRelationTreeNode>()));
46
46
  entry = insert_it.first;
47
47
  }
48
48
  // move to the next node
49
- info = entry->second.get();
49
+ info = *entry->second;
50
50
  }
51
51
  // now check if the JoinRelationSet has already been created
52
- if (!info->relation) {
52
+ if (!info.get().relation) {
53
53
  // if it hasn't we need to create it
54
- info->relation = make_uniq<JoinRelationSet>(std::move(relations), count);
54
+ info.get().relation = make_uniq<JoinRelationSet>(std::move(relations), count);
55
55
  }
56
- return info->relation.get();
56
+ return *info.get().relation;
57
57
  }
58
58
 
59
59
  //! Create or get a JoinRelationSet from a single node with the given index
60
- JoinRelationSet *JoinRelationSetManager::GetJoinRelation(idx_t index) {
60
+ JoinRelationSet &JoinRelationSetManager::GetJoinRelation(idx_t index) {
61
61
  // create a sorted vector of the relations
62
62
  auto relations = unique_ptr<idx_t[]>(new idx_t[1]);
63
63
  relations[0] = index;
@@ -65,7 +65,7 @@ JoinRelationSet *JoinRelationSetManager::GetJoinRelation(idx_t index) {
65
65
  return GetJoinRelation(std::move(relations), count);
66
66
  }
67
67
 
68
- JoinRelationSet *JoinRelationSetManager::GetJoinRelation(unordered_set<idx_t> &bindings) {
68
+ JoinRelationSet &JoinRelationSetManager::GetJoinRelation(unordered_set<idx_t> &bindings) {
69
69
  // create a sorted vector of the relations
70
70
  unique_ptr<idx_t[]> relations = bindings.empty() ? nullptr : unique_ptr<idx_t[]>(new idx_t[bindings.size()]);
71
71
  idx_t count = 0;
@@ -76,36 +76,36 @@ JoinRelationSet *JoinRelationSetManager::GetJoinRelation(unordered_set<idx_t> &b
76
76
  return GetJoinRelation(std::move(relations), count);
77
77
  }
78
78
 
79
- JoinRelationSet *JoinRelationSetManager::Union(JoinRelationSet *left, JoinRelationSet *right) {
80
- auto relations = unique_ptr<idx_t[]>(new idx_t[left->count + right->count]);
79
+ JoinRelationSet &JoinRelationSetManager::Union(JoinRelationSet &left, JoinRelationSet &right) {
80
+ auto relations = unique_ptr<idx_t[]>(new idx_t[left.count + right.count]);
81
81
  idx_t count = 0;
82
82
  // move through the left and right relations, eliminating duplicates
83
83
  idx_t i = 0, j = 0;
84
84
  while (true) {
85
- if (i == left->count) {
85
+ if (i == left.count) {
86
86
  // exhausted left relation, add remaining of right relation
87
- for (; j < right->count; j++) {
88
- relations[count++] = right->relations[j];
87
+ for (; j < right.count; j++) {
88
+ relations[count++] = right.relations[j];
89
89
  }
90
90
  break;
91
- } else if (j == right->count) {
91
+ } else if (j == right.count) {
92
92
  // exhausted right relation, add remaining of left
93
- for (; i < left->count; i++) {
94
- relations[count++] = left->relations[i];
93
+ for (; i < left.count; i++) {
94
+ relations[count++] = left.relations[i];
95
95
  }
96
96
  break;
97
- } else if (left->relations[i] == right->relations[j]) {
97
+ } else if (left.relations[i] == right.relations[j]) {
98
98
  // equivalent, add only one of the two pairs
99
- relations[count++] = left->relations[i];
99
+ relations[count++] = left.relations[i];
100
100
  i++;
101
101
  j++;
102
- } else if (left->relations[i] < right->relations[j]) {
102
+ } else if (left.relations[i] < right.relations[j]) {
103
103
  // left is smaller, progress left and add it to the set
104
- relations[count++] = left->relations[i];
104
+ relations[count++] = left.relations[i];
105
105
  i++;
106
106
  } else {
107
107
  // right is smaller, progress right and add it to the set
108
- relations[count++] = right->relations[j];
108
+ relations[count++] = right.relations[j];
109
109
  j++;
110
110
  }
111
111
  }
@@ -18,7 +18,7 @@ static string QueryEdgeToString(const QueryEdge *info, vector<idx_t> prefix) {
18
18
  }
19
19
  source += "]";
20
20
  for (auto &entry : info->neighbors) {
21
- result += StringUtil::Format("%s -> %s\n", source.c_str(), entry->neighbor->ToString().c_str());
21
+ result += StringUtil::Format("%s -> %s\n", source.c_str(), entry->neighbor.ToString().c_str());
22
22
  }
23
23
  for (auto &entry : info->children) {
24
24
  vector<idx_t> new_prefix = prefix;
@@ -37,59 +37,58 @@ void QueryGraph::Print() {
37
37
  }
38
38
  // LCOV_EXCL_STOP
39
39
 
40
- QueryEdge *QueryGraph::GetQueryEdge(JoinRelationSet *left) {
41
- D_ASSERT(left && left->count > 0);
40
+ QueryEdge &QueryGraph::GetQueryEdge(JoinRelationSet &left) {
41
+ D_ASSERT(left.count > 0);
42
42
  // find the EdgeInfo corresponding to the left set
43
- QueryEdge *info = &root;
44
- for (idx_t i = 0; i < left->count; i++) {
45
- auto entry = info->children.find(left->relations[i]);
46
- if (entry == info->children.end()) {
43
+ reference<QueryEdge> info(root);
44
+ for (idx_t i = 0; i < left.count; i++) {
45
+ auto entry = info.get().children.find(left.relations[i]);
46
+ if (entry == info.get().children.end()) {
47
47
  // node not found, create it
48
- auto insert_it = info->children.insert(make_pair(left->relations[i], make_uniq<QueryEdge>()));
48
+ auto insert_it = info.get().children.insert(make_pair(left.relations[i], make_uniq<QueryEdge>()));
49
49
  entry = insert_it.first;
50
50
  }
51
51
  // move to the next node
52
- info = entry->second.get();
52
+ info = *entry->second;
53
53
  }
54
54
  return info;
55
55
  }
56
56
 
57
- void QueryGraph::CreateEdge(JoinRelationSet *left, JoinRelationSet *right, FilterInfo *filter_info) {
58
- D_ASSERT(left && right && left->count > 0 && right->count > 0);
57
+ void QueryGraph::CreateEdge(JoinRelationSet &left, JoinRelationSet &right, optional_ptr<FilterInfo> filter_info) {
58
+ D_ASSERT(left.count > 0 && right.count > 0);
59
59
  // find the EdgeInfo corresponding to the left set
60
- auto info = GetQueryEdge(left);
60
+ auto &info = GetQueryEdge(left);
61
61
  // now insert the edge to the right relation, if it does not exist
62
- for (idx_t i = 0; i < info->neighbors.size(); i++) {
63
- if (info->neighbors[i]->neighbor == right) {
62
+ for (idx_t i = 0; i < info.neighbors.size(); i++) {
63
+ if (&info.neighbors[i]->neighbor == &right) {
64
64
  if (filter_info) {
65
65
  // neighbor already exists just add the filter, if we have any
66
- info->neighbors[i]->filters.push_back(filter_info);
66
+ info.neighbors[i]->filters.push_back(*filter_info);
67
67
  }
68
68
  return;
69
69
  }
70
70
  }
71
71
  // neighbor does not exist, create it
72
- auto n = make_uniq<NeighborInfo>();
72
+ auto n = make_uniq<NeighborInfo>(right);
73
73
  if (filter_info) {
74
- n->filters.push_back(filter_info);
74
+ n->filters.push_back(*filter_info);
75
75
  }
76
- n->neighbor = right;
77
- info->neighbors.push_back(std::move(n));
76
+ info.neighbors.push_back(std::move(n));
78
77
  }
79
78
 
80
- void QueryGraph::EnumerateNeighbors(JoinRelationSet *node, const std::function<bool(NeighborInfo *)> &callback) {
81
- for (idx_t j = 0; j < node->count; j++) {
82
- QueryEdge *info = &root;
83
- for (idx_t i = j; i < node->count; i++) {
84
- auto entry = info->children.find(node->relations[i]);
85
- if (entry == info->children.end()) {
79
+ void QueryGraph::EnumerateNeighbors(JoinRelationSet &node, const std::function<bool(NeighborInfo &)> &callback) {
80
+ for (idx_t j = 0; j < node.count; j++) {
81
+ reference<QueryEdge> info = root;
82
+ for (idx_t i = j; i < node.count; i++) {
83
+ auto entry = info.get().children.find(node.relations[i]);
84
+ if (entry == info.get().children.end()) {
86
85
  // node not found
87
86
  break;
88
87
  }
89
88
  // check if any subset of the other set is in this sets neighbors
90
- info = entry->second.get();
91
- for (auto &neighbor : info->neighbors) {
92
- if (callback(neighbor.get())) {
89
+ info = *entry->second;
90
+ for (auto &neighbor : info.get().neighbors) {
91
+ if (callback(*neighbor)) {
93
92
  return;
94
93
  }
95
94
  }
@@ -98,16 +97,16 @@ void QueryGraph::EnumerateNeighbors(JoinRelationSet *node, const std::function<b
98
97
  }
99
98
 
100
99
  //! Returns true if a JoinRelationSet is banned by the list of exclusion_set, false otherwise
101
- static bool JoinRelationSetIsExcluded(JoinRelationSet *node, unordered_set<idx_t> &exclusion_set) {
102
- return exclusion_set.find(node->relations[0]) != exclusion_set.end();
100
+ static bool JoinRelationSetIsExcluded(JoinRelationSet &node, unordered_set<idx_t> &exclusion_set) {
101
+ return exclusion_set.find(node.relations[0]) != exclusion_set.end();
103
102
  }
104
103
 
105
- vector<idx_t> QueryGraph::GetNeighbors(JoinRelationSet *node, unordered_set<idx_t> &exclusion_set) {
104
+ vector<idx_t> QueryGraph::GetNeighbors(JoinRelationSet &node, unordered_set<idx_t> &exclusion_set) {
106
105
  unordered_set<idx_t> result;
107
- EnumerateNeighbors(node, [&](NeighborInfo *info) -> bool {
108
- if (!JoinRelationSetIsExcluded(info->neighbor, exclusion_set)) {
106
+ EnumerateNeighbors(node, [&](NeighborInfo &info) -> bool {
107
+ if (!JoinRelationSetIsExcluded(info.neighbor, exclusion_set)) {
109
108
  // add the smallest node of the neighbor to the set
110
- result.insert(info->neighbor->relations[0]);
109
+ result.insert(info.neighbor.relations[0]);
111
110
  }
112
111
  return false;
113
112
  });
@@ -116,10 +115,10 @@ vector<idx_t> QueryGraph::GetNeighbors(JoinRelationSet *node, unordered_set<idx_
116
115
  return neighbors;
117
116
  }
118
117
 
119
- vector<NeighborInfo *> QueryGraph::GetConnections(JoinRelationSet *node, JoinRelationSet *other) {
120
- vector<NeighborInfo *> connections;
121
- EnumerateNeighbors(node, [&](NeighborInfo *info) -> bool {
122
- if (JoinRelationSet::IsSubset(other, info->neighbor)) {
118
+ vector<reference<NeighborInfo>> QueryGraph::GetConnections(JoinRelationSet &node, JoinRelationSet &other) {
119
+ vector<reference<NeighborInfo>> connections;
120
+ EnumerateNeighbors(node, [&](NeighborInfo &info) -> bool {
121
+ if (JoinRelationSet::IsSubset(other, info.neighbor)) {
123
122
  connections.push_back(info);
124
123
  }
125
124
  return false;
@@ -303,7 +303,7 @@ void Executor::InitializeInternal(PhysicalOperator *plan) {
303
303
  // build and ready the pipelines
304
304
  PipelineBuildState state;
305
305
  auto root_pipeline = make_shared<MetaPipeline>(*this, state, nullptr);
306
- root_pipeline->Build(physical_plan);
306
+ root_pipeline->Build(*physical_plan);
307
307
  root_pipeline->Ready();
308
308
 
309
309
  // ready recursive cte pipelines too
@@ -67,11 +67,11 @@ void MetaPipeline::AssignNextBatchIndex(Pipeline *pipeline) {
67
67
  pipeline->base_batch_index = next_batch_index++ * PipelineBuildState::BATCH_INCREMENT;
68
68
  }
69
69
 
70
- void MetaPipeline::Build(PhysicalOperator *op) {
70
+ void MetaPipeline::Build(PhysicalOperator &op) {
71
71
  D_ASSERT(pipelines.size() == 1);
72
72
  D_ASSERT(children.empty());
73
73
  D_ASSERT(final_pipelines.empty());
74
- op->BuildPipelines(*pipelines.back(), *this);
74
+ op.BuildPipelines(*pipelines.back(), *this);
75
75
  }
76
76
 
77
77
  void MetaPipeline::Ready() {
@@ -68,7 +68,7 @@ void Transformer::TransformCTE(duckdb_libpgquery::PGWithClause *de_with_clause,
68
68
  if (cte->cterecursive || de_with_clause->recursive) {
69
69
  info->query = TransformRecursiveCTE(cte, *info);
70
70
  } else {
71
- Transformer cte_transformer(this);
71
+ Transformer cte_transformer(*this);
72
72
  info->query = cte_transformer.TransformSelect(cte->ctequery);
73
73
  }
74
74
  D_ASSERT(info->query);
@@ -4,7 +4,7 @@
4
4
  namespace duckdb {
5
5
 
6
6
  unique_ptr<TableRef> Transformer::TransformRangeSubselect(duckdb_libpgquery::PGRangeSubselect *root) {
7
- Transformer subquery_transformer(this);
7
+ Transformer subquery_transformer(*this);
8
8
  auto subquery = subquery_transformer.TransformSelect(root->subquery);
9
9
  if (!subquery) {
10
10
  return nullptr;
@@ -26,8 +26,8 @@ Transformer::Transformer(ParserOptions &options)
26
26
  : parent(nullptr), options(options), stack_depth(DConstants::INVALID_INDEX) {
27
27
  }
28
28
 
29
- Transformer::Transformer(Transformer *parent)
30
- : parent(parent), options(parent->options), stack_depth(DConstants::INVALID_INDEX) {
29
+ Transformer::Transformer(Transformer &parent)
30
+ : parent(&parent), options(parent.options), stack_depth(DConstants::INVALID_INDEX) {
31
31
  }
32
32
 
33
33
  Transformer::~Transformer() {
@@ -59,17 +59,14 @@ void Transformer::InitializeStackCheck() {
59
59
  }
60
60
 
61
61
  StackChecker Transformer::StackCheck(idx_t extra_stack) {
62
- auto node = this;
63
- while (node->parent) {
64
- node = node->parent;
65
- }
66
- D_ASSERT(node->stack_depth != DConstants::INVALID_INDEX);
67
- if (node->stack_depth + extra_stack >= options.max_expression_depth) {
62
+ auto &root = RootTransformer();
63
+ D_ASSERT(root.stack_depth != DConstants::INVALID_INDEX);
64
+ if (root.stack_depth + extra_stack >= options.max_expression_depth) {
68
65
  throw ParserException("Max expression depth limit of %lld exceeded. Use \"SET max_expression_depth TO x\" to "
69
66
  "increase the maximum expression depth.",
70
67
  options.max_expression_depth);
71
68
  }
72
- return StackChecker(*node, extra_stack);
69
+ return StackChecker(root, extra_stack);
73
70
  }
74
71
 
75
72
  unique_ptr<SQLStatement> Transformer::TransformStatement(duckdb_libpgquery::PGNode *stmt) {
@@ -82,6 +79,50 @@ unique_ptr<SQLStatement> Transformer::TransformStatement(duckdb_libpgquery::PGNo
82
79
  return result;
83
80
  }
84
81
 
82
+ Transformer &Transformer::RootTransformer() {
83
+ reference<Transformer> node = *this;
84
+ while (node.get().parent) {
85
+ node = *node.get().parent;
86
+ }
87
+ return node.get();
88
+ }
89
+
90
+ const Transformer &Transformer::RootTransformer() const {
91
+ reference<const Transformer> node = *this;
92
+ while (node.get().parent) {
93
+ node = *node.get().parent;
94
+ }
95
+ return node.get();
96
+ }
97
+
98
+ idx_t Transformer::ParamCount() const {
99
+ auto &root = RootTransformer();
100
+ return root.prepared_statement_parameter_index;
101
+ }
102
+
103
+ void Transformer::SetParamCount(idx_t new_count) {
104
+ auto &root = RootTransformer();
105
+ root.prepared_statement_parameter_index = new_count;
106
+ }
107
+ void Transformer::SetNamedParam(const string &name, int32_t index) {
108
+ auto &root = RootTransformer();
109
+ D_ASSERT(!root.named_param_map.count(name));
110
+ root.named_param_map[name] = index;
111
+ }
112
+ bool Transformer::GetNamedParam(const string &name, int32_t &index) {
113
+ auto &root = RootTransformer();
114
+ auto entry = root.named_param_map.find(name);
115
+ if (entry == root.named_param_map.end()) {
116
+ return false;
117
+ }
118
+ index = entry->second;
119
+ return true;
120
+ }
121
+ bool Transformer::HasNamedParameters() const {
122
+ auto &root = RootTransformer();
123
+ return !root.named_param_map.empty();
124
+ }
125
+
85
126
  unique_ptr<SQLStatement> Transformer::TransformStatementInternal(duckdb_libpgquery::PGNode *stmt) {
86
127
  switch (stmt->type) {
87
128
  case duckdb_libpgquery::T_PGRawStmt: {
@@ -3,6 +3,7 @@
3
3
  #include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp"
4
4
  #include "duckdb/catalog/catalog_entry/table_function_catalog_entry.hpp"
5
5
  #include "duckdb/common/bind_helpers.hpp"
6
+ #include "duckdb/common/filename_pattern.hpp"
6
7
  #include "duckdb/common/local_file_system.hpp"
7
8
  #include "duckdb/execution/operator/persistent/parallel_csv_reader.hpp"
8
9
  #include "duckdb/function/table/read_csv.hpp"
@@ -76,7 +77,8 @@ BoundStatement Binder::BindCopyTo(CopyStatement &stmt) {
76
77
  throw NotImplementedException("COPY TO is not supported for FORMAT \"%s\"", stmt.info->format);
77
78
  }
78
79
  bool use_tmp_file = true;
79
- bool allow_overwrite = false;
80
+ bool overwrite_or_ignore = false;
81
+ FilenamePattern filename_pattern;
80
82
  bool user_set_use_tmp_file = false;
81
83
  bool per_thread_output = false;
82
84
  vector<idx_t> partition_cols;
@@ -92,11 +94,19 @@ BoundStatement Binder::BindCopyTo(CopyStatement &stmt) {
92
94
  user_set_use_tmp_file = true;
93
95
  continue;
94
96
  }
95
- if (loption == "allow_overwrite") {
96
- allow_overwrite =
97
+ if (loption == "overwrite_or_ignore") {
98
+ overwrite_or_ignore =
97
99
  option.second.empty() || option.second[0].CastAs(context, LogicalType::BOOLEAN).GetValue<bool>();
98
100
  continue;
99
101
  }
102
+ if (loption == "filename_pattern") {
103
+ if (option.second.empty()) {
104
+ throw IOException("FILENAME_PATTERN cannot be empty");
105
+ }
106
+ filename_pattern.SetFilenamePattern(
107
+ option.second[0].CastAs(context, LogicalType::VARCHAR).GetValue<string>());
108
+ continue;
109
+ }
100
110
 
101
111
  if (loption == "per_thread_output") {
102
112
  per_thread_output =
@@ -133,8 +143,8 @@ BoundStatement Binder::BindCopyTo(CopyStatement &stmt) {
133
143
  auto copy = make_uniq<LogicalCopyToFile>(copy_function->function, std::move(function_data));
134
144
  copy->file_path = stmt.info->file_path;
135
145
  copy->use_tmp_file = use_tmp_file;
136
- copy->allow_overwrite = allow_overwrite;
137
- copy->per_thread_output = per_thread_output;
146
+ copy->overwrite_or_ignore = overwrite_or_ignore;
147
+ copy->filename_pattern = filename_pattern;
138
148
  copy->per_thread_output = per_thread_output;
139
149
  copy->partition_output = !partition_cols.empty();
140
150
  copy->partition_columns = std::move(partition_cols);
@@ -66,7 +66,7 @@ void Binder::BindSchemaOrCatalog(string &catalog, string &schema) {
66
66
  BindSchemaOrCatalog(context, catalog, schema);
67
67
  }
68
68
 
69
- SchemaCatalogEntry *Binder::BindSchema(CreateInfo &info) {
69
+ SchemaCatalogEntry &Binder::BindSchema(CreateInfo &info) {
70
70
  BindSchemaOrCatalog(info.catalog, info.schema);
71
71
  if (IsInvalidCatalog(info.catalog) && info.temporary) {
72
72
  info.catalog = TEMP_CATALOG;
@@ -101,12 +101,12 @@ SchemaCatalogEntry *Binder::BindSchema(CreateInfo &info) {
101
101
  if (!info.temporary) {
102
102
  properties.modified_databases.insert(schema_obj->catalog->GetName());
103
103
  }
104
- return schema_obj;
104
+ return *schema_obj;
105
105
  }
106
106
 
107
- SchemaCatalogEntry *Binder::BindCreateSchema(CreateInfo &info) {
108
- auto schema = BindSchema(info);
109
- if (schema->catalog->IsSystemCatalog()) {
107
+ SchemaCatalogEntry &Binder::BindCreateSchema(CreateInfo &info) {
108
+ auto &schema = BindSchema(info);
109
+ if (schema.catalog->IsSystemCatalog()) {
110
110
  throw BinderException("Cannot create entry in system catalog");
111
111
  }
112
112
  return schema;
@@ -159,7 +159,7 @@ static void QualifyFunctionNames(ClientContext &context, unique_ptr<ParsedExpres
159
159
  *expr, [&](unique_ptr<ParsedExpression> &child) { QualifyFunctionNames(context, child); });
160
160
  }
161
161
 
162
- SchemaCatalogEntry *Binder::BindCreateFunctionInfo(CreateInfo &info) {
162
+ SchemaCatalogEntry &Binder::BindCreateFunctionInfo(CreateInfo &info) {
163
163
  auto &base = (CreateMacroInfo &)info;
164
164
  auto &scalar_function = (ScalarMacroFunction &)*base.function;
165
165
 
@@ -477,25 +477,27 @@ BoundStatement Binder::Bind(CreateStatement &stmt) {
477
477
  case CatalogType::VIEW_ENTRY: {
478
478
  auto &base = (CreateViewInfo &)*stmt.info;
479
479
  // bind the schema
480
- auto schema = BindCreateSchema(*stmt.info);
480
+ auto &schema = BindCreateSchema(*stmt.info);
481
481
  BindCreateViewInfo(base);
482
- result.plan = make_uniq<LogicalCreate>(LogicalOperatorType::LOGICAL_CREATE_VIEW, std::move(stmt.info), schema);
482
+ result.plan = make_uniq<LogicalCreate>(LogicalOperatorType::LOGICAL_CREATE_VIEW, std::move(stmt.info), &schema);
483
483
  break;
484
484
  }
485
485
  case CatalogType::SEQUENCE_ENTRY: {
486
- auto schema = BindCreateSchema(*stmt.info);
486
+ auto &schema = BindCreateSchema(*stmt.info);
487
487
  result.plan =
488
- make_uniq<LogicalCreate>(LogicalOperatorType::LOGICAL_CREATE_SEQUENCE, std::move(stmt.info), schema);
488
+ make_uniq<LogicalCreate>(LogicalOperatorType::LOGICAL_CREATE_SEQUENCE, std::move(stmt.info), &schema);
489
489
  break;
490
490
  }
491
491
  case CatalogType::TABLE_MACRO_ENTRY: {
492
- auto schema = BindCreateSchema(*stmt.info);
493
- result.plan = make_uniq<LogicalCreate>(LogicalOperatorType::LOGICAL_CREATE_MACRO, std::move(stmt.info), schema);
492
+ auto &schema = BindCreateSchema(*stmt.info);
493
+ result.plan =
494
+ make_uniq<LogicalCreate>(LogicalOperatorType::LOGICAL_CREATE_MACRO, std::move(stmt.info), &schema);
494
495
  break;
495
496
  }
496
497
  case CatalogType::MACRO_ENTRY: {
497
- auto schema = BindCreateFunctionInfo(*stmt.info);
498
- result.plan = make_uniq<LogicalCreate>(LogicalOperatorType::LOGICAL_CREATE_MACRO, std::move(stmt.info), schema);
498
+ auto &schema = BindCreateFunctionInfo(*stmt.info);
499
+ result.plan =
500
+ make_uniq<LogicalCreate>(LogicalOperatorType::LOGICAL_CREATE_MACRO, std::move(stmt.info), &schema);
499
501
  break;
500
502
  }
501
503
  case CatalogType::INDEX_ENTRY: {
@@ -589,9 +591,9 @@ BoundStatement Binder::Bind(CreateStatement &stmt) {
589
591
  break;
590
592
  }
591
593
  case CatalogType::TYPE_ENTRY: {
592
- auto schema = BindCreateSchema(*stmt.info);
594
+ auto &schema = BindCreateSchema(*stmt.info);
593
595
  auto &create_type_info = (CreateTypeInfo &)(*stmt.info);
594
- result.plan = make_uniq<LogicalCreate>(LogicalOperatorType::LOGICAL_CREATE_TYPE, std::move(stmt.info), schema);
596
+ result.plan = make_uniq<LogicalCreate>(LogicalOperatorType::LOGICAL_CREATE_TYPE, std::move(stmt.info), &schema);
595
597
  if (create_type_info.query) {
596
598
  // CREATE TYPE mood AS ENUM (SELECT 'happy')
597
599
  auto &select_stmt = create_type_info.query->Cast<SelectStatement>();
@@ -634,7 +636,7 @@ BoundStatement Binder::Bind(CreateStatement &stmt) {
634
636
  // 2: create a type alias with a custom type.
635
637
  // eg. CREATE TYPE a AS INT; CREATE TYPE b AS a;
636
638
  // We set b to be an alias for the underlying type of a
637
- auto inner_type = Catalog::GetType(context, schema->catalog->GetName(), schema->name,
639
+ auto inner_type = Catalog::GetType(context, schema.catalog->GetName(), schema.name,
638
640
  UserType::GetTypeName(create_type_info.type));
639
641
  // clear to nullptr, we don't need this
640
642
  LogicalType::SetCatalog(inner_type, nullptr);
@@ -251,10 +251,10 @@ static void ExtractDependencies(BoundCreateTableInfo &info) {
251
251
  }
252
252
  }
253
253
  }
254
- unique_ptr<BoundCreateTableInfo> Binder::BindCreateTableInfo(unique_ptr<CreateInfo> info, SchemaCatalogEntry *schema) {
254
+ unique_ptr<BoundCreateTableInfo> Binder::BindCreateTableInfo(unique_ptr<CreateInfo> info, SchemaCatalogEntry &schema) {
255
255
  auto &base = (CreateTableInfo &)*info;
256
256
  auto result = make_uniq<BoundCreateTableInfo>(std::move(info));
257
- result->schema = schema;
257
+ result->schema = &schema;
258
258
  if (base.query) {
259
259
  // construct the result object
260
260
  auto query_obj = Bind(*base.query);
@@ -300,14 +300,14 @@ unique_ptr<BoundCreateTableInfo> Binder::BindCreateTableInfo(unique_ptr<CreateIn
300
300
  result->dependencies.AddDependency(*type_dependency);
301
301
  }
302
302
  }
303
- result->dependencies.VerifyDependencies(*schema->catalog, result->Base().table);
303
+ result->dependencies.VerifyDependencies(*schema.catalog, result->Base().table);
304
304
  properties.allow_stream_result = false;
305
305
  return result;
306
306
  }
307
307
 
308
308
  unique_ptr<BoundCreateTableInfo> Binder::BindCreateTableInfo(unique_ptr<CreateInfo> info) {
309
309
  auto &base = (CreateTableInfo &)*info;
310
- auto schema = BindCreateSchema(base);
310
+ auto &schema = BindCreateSchema(base);
311
311
  return BindCreateTableInfo(std::move(info), schema);
312
312
  }
313
313