duckdb 0.7.2-dev1898.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 (181) hide show
  1. package/binding.gyp +2 -0
  2. package/package.json +1 -1
  3. package/src/data_chunk.cpp +13 -1
  4. package/src/duckdb/extension/parquet/include/parquet_writer.hpp +1 -1
  5. package/src/duckdb/extension/parquet/parquet_metadata.cpp +4 -2
  6. package/src/duckdb/src/catalog/catalog_entry/duck_index_entry.cpp +1 -1
  7. package/src/duckdb/src/common/arrow/arrow_appender.cpp +69 -44
  8. package/src/duckdb/src/common/arrow/arrow_converter.cpp +1 -1
  9. package/src/duckdb/src/common/arrow/arrow_wrapper.cpp +20 -2
  10. package/src/duckdb/src/common/box_renderer.cpp +4 -2
  11. package/src/duckdb/src/common/constants.cpp +10 -1
  12. package/src/duckdb/src/common/filename_pattern.cpp +41 -0
  13. package/src/duckdb/src/common/hive_partitioning.cpp +144 -15
  14. package/src/duckdb/src/common/radix_partitioning.cpp +101 -369
  15. package/src/duckdb/src/common/row_operations/row_aggregate.cpp +8 -9
  16. package/src/duckdb/src/common/row_operations/row_external.cpp +1 -1
  17. package/src/duckdb/src/common/row_operations/row_gather.cpp +5 -3
  18. package/src/duckdb/src/common/row_operations/row_match.cpp +117 -22
  19. package/src/duckdb/src/common/row_operations/row_scatter.cpp +2 -2
  20. package/src/duckdb/src/common/sort/partition_state.cpp +1 -1
  21. package/src/duckdb/src/common/sort/sort_state.cpp +2 -1
  22. package/src/duckdb/src/common/sort/sorted_block.cpp +1 -1
  23. package/src/duckdb/src/common/types/{column_data_allocator.cpp → column/column_data_allocator.cpp} +2 -2
  24. package/src/duckdb/src/common/types/{column_data_collection.cpp → column/column_data_collection.cpp} +22 -4
  25. package/src/duckdb/src/common/types/{column_data_collection_segment.cpp → column/column_data_collection_segment.cpp} +2 -1
  26. package/src/duckdb/src/common/types/{column_data_consumer.cpp → column/column_data_consumer.cpp} +1 -1
  27. package/src/duckdb/src/common/types/{partitioned_column_data.cpp → column/partitioned_column_data.cpp} +11 -9
  28. package/src/duckdb/src/common/types/row/partitioned_tuple_data.cpp +316 -0
  29. package/src/duckdb/src/common/types/{row_data_collection.cpp → row/row_data_collection.cpp} +1 -1
  30. package/src/duckdb/src/common/types/{row_data_collection_scanner.cpp → row/row_data_collection_scanner.cpp} +2 -2
  31. package/src/duckdb/src/common/types/{row_layout.cpp → row/row_layout.cpp} +1 -1
  32. package/src/duckdb/src/common/types/row/tuple_data_allocator.cpp +465 -0
  33. package/src/duckdb/src/common/types/row/tuple_data_collection.cpp +511 -0
  34. package/src/duckdb/src/common/types/row/tuple_data_iterator.cpp +96 -0
  35. package/src/duckdb/src/common/types/row/tuple_data_layout.cpp +119 -0
  36. package/src/duckdb/src/common/types/row/tuple_data_scatter_gather.cpp +1200 -0
  37. package/src/duckdb/src/common/types/row/tuple_data_segment.cpp +170 -0
  38. package/src/duckdb/src/common/types/vector.cpp +1 -1
  39. package/src/duckdb/src/execution/aggregate_hashtable.cpp +252 -290
  40. package/src/duckdb/src/execution/join_hashtable.cpp +192 -328
  41. package/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +4 -4
  42. package/src/duckdb/src/execution/operator/helper/physical_execute.cpp +3 -3
  43. package/src/duckdb/src/execution/operator/helper/physical_limit_percent.cpp +2 -3
  44. package/src/duckdb/src/execution/operator/helper/physical_result_collector.cpp +2 -3
  45. package/src/duckdb/src/execution/operator/join/perfect_hash_join_executor.cpp +36 -21
  46. package/src/duckdb/src/execution/operator/join/physical_blockwise_nl_join.cpp +2 -2
  47. package/src/duckdb/src/execution/operator/join/physical_cross_product.cpp +1 -1
  48. package/src/duckdb/src/execution/operator/join/physical_delim_join.cpp +2 -2
  49. package/src/duckdb/src/execution/operator/join/physical_hash_join.cpp +166 -144
  50. package/src/duckdb/src/execution/operator/join/physical_index_join.cpp +5 -5
  51. package/src/duckdb/src/execution/operator/join/physical_join.cpp +2 -10
  52. package/src/duckdb/src/execution/operator/join/physical_positional_join.cpp +0 -1
  53. package/src/duckdb/src/execution/operator/order/physical_top_n.cpp +2 -2
  54. package/src/duckdb/src/execution/operator/persistent/physical_copy_to_file.cpp +13 -11
  55. package/src/duckdb/src/execution/operator/persistent/physical_delete.cpp +3 -2
  56. package/src/duckdb/src/execution/operator/persistent/physical_export.cpp +25 -24
  57. package/src/duckdb/src/execution/operator/persistent/physical_insert.cpp +1 -1
  58. package/src/duckdb/src/execution/operator/persistent/physical_update.cpp +4 -3
  59. package/src/duckdb/src/execution/operator/schema/physical_create_type.cpp +1 -1
  60. package/src/duckdb/src/execution/operator/set/physical_recursive_cte.cpp +3 -3
  61. package/src/duckdb/src/execution/partitionable_hashtable.cpp +9 -37
  62. package/src/duckdb/src/execution/physical_operator.cpp +1 -1
  63. package/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp +19 -18
  64. package/src/duckdb/src/execution/physical_plan/plan_copy_to_file.cpp +2 -1
  65. package/src/duckdb/src/execution/physical_plan/plan_execute.cpp +2 -2
  66. package/src/duckdb/src/execution/physical_plan/plan_explain.cpp +5 -6
  67. package/src/duckdb/src/execution/physical_plan/plan_expression_get.cpp +2 -2
  68. package/src/duckdb/src/execution/physical_plan/plan_recursive_cte.cpp +3 -3
  69. package/src/duckdb/src/execution/physical_plan_generator.cpp +1 -1
  70. package/src/duckdb/src/execution/radix_partitioned_hashtable.cpp +39 -17
  71. package/src/duckdb/src/function/aggregate/sorted_aggregate_function.cpp +2 -2
  72. package/src/duckdb/src/function/table/pragma_detailed_profiling_output.cpp +5 -5
  73. package/src/duckdb/src/function/table/pragma_last_profiling_output.cpp +2 -2
  74. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  75. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/index_catalog_entry.hpp +1 -1
  76. package/src/duckdb/src/include/duckdb/common/arrow/arrow_appender.hpp +1 -1
  77. package/src/duckdb/src/include/duckdb/common/constants.hpp +2 -0
  78. package/src/duckdb/src/include/duckdb/common/exception.hpp +3 -0
  79. package/src/duckdb/src/include/duckdb/common/fast_mem.hpp +528 -0
  80. package/src/duckdb/src/include/duckdb/common/filename_pattern.hpp +34 -0
  81. package/src/duckdb/src/include/duckdb/common/helper.hpp +10 -0
  82. package/src/duckdb/src/include/duckdb/common/hive_partitioning.hpp +13 -3
  83. package/src/duckdb/src/include/duckdb/common/optional_ptr.hpp +8 -0
  84. package/src/duckdb/src/include/duckdb/common/perfect_map_set.hpp +34 -0
  85. package/src/duckdb/src/include/duckdb/common/radix_partitioning.hpp +80 -27
  86. package/src/duckdb/src/include/duckdb/common/reference_map.hpp +38 -0
  87. package/src/duckdb/src/include/duckdb/common/row_operations/row_operations.hpp +7 -6
  88. package/src/duckdb/src/include/duckdb/common/sort/comparators.hpp +1 -1
  89. package/src/duckdb/src/include/duckdb/common/sort/partition_state.hpp +1 -1
  90. package/src/duckdb/src/include/duckdb/common/sort/sort.hpp +1 -1
  91. package/src/duckdb/src/include/duckdb/common/sort/sorted_block.hpp +2 -2
  92. package/src/duckdb/src/include/duckdb/common/types/batched_data_collection.hpp +1 -1
  93. package/src/duckdb/src/include/duckdb/common/types/{column_data_allocator.hpp → column/column_data_allocator.hpp} +4 -4
  94. package/src/duckdb/src/include/duckdb/common/types/{column_data_collection.hpp → column/column_data_collection.hpp} +2 -2
  95. package/src/duckdb/src/include/duckdb/common/types/{column_data_collection_iterators.hpp → column/column_data_collection_iterators.hpp} +2 -2
  96. package/src/duckdb/src/include/duckdb/common/types/{column_data_collection_segment.hpp → column/column_data_collection_segment.hpp} +3 -3
  97. package/src/duckdb/src/include/duckdb/common/types/{column_data_consumer.hpp → column/column_data_consumer.hpp} +8 -4
  98. package/src/duckdb/src/include/duckdb/common/types/{column_data_scan_states.hpp → column/column_data_scan_states.hpp} +1 -1
  99. package/src/duckdb/src/include/duckdb/common/types/{partitioned_column_data.hpp → column/partitioned_column_data.hpp} +15 -7
  100. package/src/duckdb/src/include/duckdb/common/types/row/partitioned_tuple_data.hpp +140 -0
  101. package/src/duckdb/src/include/duckdb/common/types/{row_data_collection.hpp → row/row_data_collection.hpp} +1 -1
  102. package/src/duckdb/src/include/duckdb/common/types/{row_data_collection_scanner.hpp → row/row_data_collection_scanner.hpp} +2 -2
  103. package/src/duckdb/src/include/duckdb/common/types/{row_layout.hpp → row/row_layout.hpp} +3 -1
  104. package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_allocator.hpp +116 -0
  105. package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_collection.hpp +239 -0
  106. package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_iterator.hpp +64 -0
  107. package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_layout.hpp +113 -0
  108. package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_segment.hpp +124 -0
  109. package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_states.hpp +74 -0
  110. package/src/duckdb/src/include/duckdb/common/types/validity_mask.hpp +3 -0
  111. package/src/duckdb/src/include/duckdb/common/types/value.hpp +4 -12
  112. package/src/duckdb/src/include/duckdb/execution/aggregate_hashtable.hpp +34 -31
  113. package/src/duckdb/src/include/duckdb/execution/base_aggregate_hashtable.hpp +2 -2
  114. package/src/duckdb/src/include/duckdb/execution/execution_context.hpp +3 -2
  115. package/src/duckdb/src/include/duckdb/execution/expression_executor.hpp +1 -1
  116. package/src/duckdb/src/include/duckdb/execution/join_hashtable.hpp +41 -67
  117. package/src/duckdb/src/include/duckdb/execution/nested_loop_join.hpp +1 -1
  118. package/src/duckdb/src/include/duckdb/execution/operator/helper/physical_execute.hpp +2 -2
  119. package/src/duckdb/src/include/duckdb/execution/operator/helper/physical_result_collector.hpp +1 -1
  120. package/src/duckdb/src/include/duckdb/execution/operator/join/outer_join_marker.hpp +2 -2
  121. package/src/duckdb/src/include/duckdb/execution/operator/join/perfect_hash_join_executor.hpp +1 -1
  122. package/src/duckdb/src/include/duckdb/execution/operator/join/physical_cross_product.hpp +1 -1
  123. package/src/duckdb/src/include/duckdb/execution/operator/join/physical_hash_join.hpp +0 -2
  124. package/src/duckdb/src/include/duckdb/execution/operator/join/physical_index_join.hpp +2 -2
  125. package/src/duckdb/src/include/duckdb/execution/operator/join/physical_positional_join.hpp +1 -1
  126. package/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_copy_to_file.hpp +4 -1
  127. package/src/duckdb/src/include/duckdb/execution/operator/scan/physical_column_data_scan.hpp +1 -1
  128. package/src/duckdb/src/include/duckdb/execution/operator/set/physical_recursive_cte.hpp +1 -1
  129. package/src/duckdb/src/include/duckdb/execution/partitionable_hashtable.hpp +2 -2
  130. package/src/duckdb/src/include/duckdb/main/materialized_query_result.hpp +1 -1
  131. package/src/duckdb/src/include/duckdb/main/query_result.hpp +14 -1
  132. package/src/duckdb/src/include/duckdb/optimizer/expression_rewriter.hpp +3 -3
  133. package/src/duckdb/src/include/duckdb/optimizer/join_order/cardinality_estimator.hpp +16 -16
  134. package/src/duckdb/src/include/duckdb/optimizer/join_order/join_node.hpp +8 -8
  135. package/src/duckdb/src/include/duckdb/optimizer/join_order/join_order_optimizer.hpp +23 -15
  136. package/src/duckdb/src/include/duckdb/optimizer/join_order/join_relation.hpp +9 -10
  137. package/src/duckdb/src/include/duckdb/optimizer/join_order/query_graph.hpp +18 -11
  138. package/src/duckdb/src/include/duckdb/parallel/meta_pipeline.hpp +1 -1
  139. package/src/duckdb/src/include/duckdb/parser/parsed_data/exported_table_data.hpp +5 -1
  140. package/src/duckdb/src/include/duckdb/parser/parsed_data/vacuum_info.hpp +3 -2
  141. package/src/duckdb/src/include/duckdb/parser/query_error_context.hpp +4 -2
  142. package/src/duckdb/src/include/duckdb/parser/transformer.hpp +9 -35
  143. package/src/duckdb/src/include/duckdb/planner/binder.hpp +24 -23
  144. package/src/duckdb/src/include/duckdb/planner/expression_binder.hpp +3 -3
  145. package/src/duckdb/src/include/duckdb/planner/operator/logical_column_data_get.hpp +1 -1
  146. package/src/duckdb/src/include/duckdb/planner/operator/logical_copy_to_file.hpp +3 -1
  147. package/src/duckdb/src/include/duckdb/storage/table/table_index_list.hpp +1 -1
  148. package/src/duckdb/src/main/appender.cpp +6 -6
  149. package/src/duckdb/src/main/client_context.cpp +1 -1
  150. package/src/duckdb/src/main/connection.cpp +2 -2
  151. package/src/duckdb/src/main/query_result.cpp +13 -0
  152. package/src/duckdb/src/optimizer/expression_rewriter.cpp +4 -4
  153. package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +91 -105
  154. package/src/duckdb/src/optimizer/join_order/join_node.cpp +5 -8
  155. package/src/duckdb/src/optimizer/join_order/join_order_optimizer.cpp +163 -160
  156. package/src/duckdb/src/optimizer/join_order/join_relation_set.cpp +30 -30
  157. package/src/duckdb/src/optimizer/join_order/query_graph.cpp +37 -38
  158. package/src/duckdb/src/parallel/executor.cpp +1 -1
  159. package/src/duckdb/src/parallel/meta_pipeline.cpp +2 -2
  160. package/src/duckdb/src/parser/transform/helpers/transform_cte.cpp +1 -1
  161. package/src/duckdb/src/parser/transform/tableref/transform_subquery.cpp +1 -1
  162. package/src/duckdb/src/parser/transformer.cpp +50 -9
  163. package/src/duckdb/src/planner/binder/statement/bind_copy.cpp +15 -5
  164. package/src/duckdb/src/planner/binder/statement/bind_create.cpp +19 -17
  165. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +4 -4
  166. package/src/duckdb/src/planner/binder/statement/bind_export.cpp +20 -21
  167. package/src/duckdb/src/planner/binder/tableref/bind_basetableref.cpp +24 -22
  168. package/src/duckdb/src/planner/binder/tableref/bind_subqueryref.cpp +2 -2
  169. package/src/duckdb/src/planner/binder.cpp +16 -19
  170. package/src/duckdb/src/planner/expression_binder.cpp +8 -8
  171. package/src/duckdb/src/planner/operator/logical_copy_to_file.cpp +3 -3
  172. package/src/duckdb/src/storage/checkpoint_manager.cpp +23 -23
  173. package/src/duckdb/src/storage/standard_buffer_manager.cpp +1 -1
  174. package/src/duckdb/src/storage/table_index_list.cpp +3 -3
  175. package/src/duckdb/src/verification/statement_verifier.cpp +1 -1
  176. package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +5552 -5598
  177. package/src/duckdb/ub_src_common.cpp +2 -0
  178. package/src/duckdb/ub_src_common_types.cpp +0 -16
  179. package/src/duckdb/ub_src_common_types_column.cpp +10 -0
  180. package/src/duckdb/ub_src_common_types_row.cpp +20 -0
  181. package/test/udf.test.ts +9 -0
@@ -17,10 +17,10 @@ struct RadixPartitionInfo {
17
17
  const idx_t n_partitions;
18
18
  const idx_t radix_bits;
19
19
  const hash_t radix_mask;
20
- constexpr static idx_t RADIX_SHIFT = 40;
20
+ const idx_t radix_shift;
21
21
 
22
22
  inline hash_t GetHashPartition(hash_t hash) const {
23
- return (hash & radix_mask) >> RADIX_SHIFT;
23
+ return (hash & radix_mask) >> radix_shift;
24
24
  }
25
25
  };
26
26
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  #pragma once
10
10
 
11
- #include "duckdb/common/types/column_data_collection.hpp"
11
+ #include "duckdb/common/types/column/column_data_collection.hpp"
12
12
  #include "duckdb/common/winapi.hpp"
13
13
  #include "duckdb/main/query_result.hpp"
14
14
 
@@ -58,7 +58,16 @@ protected:
58
58
  //! The error (in case execution was not successful)
59
59
  PreservedError error;
60
60
  };
61
-
61
+ struct CurrentChunk {
62
+ //! The current data chunk
63
+ unique_ptr<DataChunk> data_chunk;
64
+ //! The current position in the data chunk
65
+ idx_t position;
66
+ //! If we have a current chunk we must scan for result production
67
+ bool Valid();
68
+ //! The remaining size of the current chunk
69
+ idx_t RemainingSize();
70
+ };
62
71
  //! The QueryResult object holds the result of a query. It can either be a MaterializedQueryResult, in which case the
63
72
  //! result contains the entire result set, or a StreamQueryResult in which case the Fetch method can be called to
64
73
  //! incrementally fetch data from the database.
@@ -75,6 +84,10 @@ public:
75
84
  ClientProperties client_properties;
76
85
  //! The next result (if any)
77
86
  unique_ptr<QueryResult> next;
87
+ //! In case we are converting the result from Native DuckDB to a different library (e.g., Arrow, Polars)
88
+ //! We might be producing chunks of a pre-determined size.
89
+ //! To comply, we use the following variable to store the current chunk, and it's position.
90
+ CurrentChunk current_chunk;
78
91
 
79
92
  public:
80
93
  //! Returns the name of the column for the given index
@@ -37,11 +37,11 @@ public:
37
37
 
38
38
  private:
39
39
  //! Apply a set of rules to a specific expression
40
- static unique_ptr<Expression> ApplyRules(LogicalOperator &op, const vector<Rule *> &rules,
40
+ static unique_ptr<Expression> ApplyRules(LogicalOperator &op, const vector<reference<Rule>> &rules,
41
41
  unique_ptr<Expression> expr, bool &changes_made, bool is_root = false);
42
42
 
43
- LogicalOperator *op;
44
- vector<Rule *> to_apply_rules;
43
+ optional_ptr<LogicalOperator> op;
44
+ vector<reference<Rule>> to_apply_rules;
45
45
  };
46
46
 
47
47
  } // namespace duckdb
@@ -41,9 +41,9 @@ struct RelationsToTDom {
41
41
 
42
42
  struct NodeOp {
43
43
  unique_ptr<JoinNode> node;
44
- LogicalOperator *op;
44
+ LogicalOperator &op;
45
45
 
46
- NodeOp(unique_ptr<JoinNode> node, LogicalOperator *op) : node(std::move(node)), op(op) {};
46
+ NodeOp(unique_ptr<JoinNode> node, LogicalOperator &op) : node(std::move(node)), op(op) {};
47
47
  };
48
48
 
49
49
  struct Subgraph2Denominator {
@@ -71,7 +71,7 @@ private:
71
71
  public:
72
72
  static constexpr double DEFAULT_SELECTIVITY = 0.2;
73
73
 
74
- static void VerifySymmetry(JoinNode *result, JoinNode *entry);
74
+ static void VerifySymmetry(JoinNode &result, JoinNode &entry);
75
75
 
76
76
  //! given a binding of (relation, column) used for DP, and a (table, column) in that catalog
77
77
  //! Add the key value entry into the relation_column_to_original_column
@@ -83,20 +83,20 @@ public:
83
83
  // in the child join plan.
84
84
  void CopyRelationMap(column_binding_map_t<ColumnBinding> &child_binding_map);
85
85
  void MergeBindings(idx_t, idx_t relation_id, vector<column_binding_map_t<ColumnBinding>> &child_binding_maps);
86
- void AddRelationColumnMapping(LogicalGet *get, idx_t relation_id);
86
+ void AddRelationColumnMapping(LogicalGet &get, idx_t relation_id);
87
87
 
88
88
  void InitTotalDomains();
89
- void UpdateTotalDomains(JoinNode *node, LogicalOperator *op);
90
- void InitEquivalentRelations(vector<unique_ptr<FilterInfo>> *filter_infos);
89
+ void UpdateTotalDomains(JoinNode &node, LogicalOperator &op);
90
+ void InitEquivalentRelations(vector<unique_ptr<FilterInfo>> &filter_infos);
91
91
 
92
- void InitCardinalityEstimatorProps(vector<NodeOp> *node_ops, vector<unique_ptr<FilterInfo>> *filter_infos);
93
- double EstimateCardinalityWithSet(JoinRelationSet *new_set);
94
- void EstimateBaseTableCardinality(JoinNode *node, LogicalOperator *op);
95
- double EstimateCrossProduct(const JoinNode *left, const JoinNode *right);
96
- static double ComputeCost(JoinNode *left, JoinNode *right, double expected_cardinality);
92
+ void InitCardinalityEstimatorProps(vector<NodeOp> &node_ops, vector<unique_ptr<FilterInfo>> &filter_infos);
93
+ double EstimateCardinalityWithSet(JoinRelationSet &new_set);
94
+ void EstimateBaseTableCardinality(JoinNode &node, LogicalOperator &op);
95
+ double EstimateCrossProduct(const JoinNode &left, const JoinNode &right);
96
+ static double ComputeCost(JoinNode &left, JoinNode &right, double expected_cardinality);
97
97
 
98
98
  private:
99
- bool SingleColumnFilter(FilterInfo *filter_info);
99
+ bool SingleColumnFilter(FilterInfo &filter_info);
100
100
  //! Filter & bindings -> list of indexes into the equivalent_relations array.
101
101
  // The column binding set at each index is an equivalence set.
102
102
  vector<idx_t> DetermineMatchingEquivalentSets(FilterInfo *filter_info);
@@ -106,16 +106,16 @@ private:
106
106
  //! If there are multiple equivalence sets, they are merged.
107
107
  void AddToEquivalenceSets(FilterInfo *filter_info, vector<idx_t> matching_equivalent_sets);
108
108
 
109
- TableFilterSet *GetTableFilters(LogicalOperator *op, idx_t table_index);
109
+ optional_ptr<TableFilterSet> GetTableFilters(LogicalOperator &op, idx_t table_index);
110
110
 
111
- void AddRelationTdom(FilterInfo *filter_info);
112
- bool EmptyFilter(FilterInfo *filter_info);
111
+ void AddRelationTdom(FilterInfo &filter_info);
112
+ bool EmptyFilter(FilterInfo &filter_info);
113
113
 
114
114
  idx_t InspectConjunctionAND(idx_t cardinality, idx_t column_index, ConjunctionAndFilter *fil,
115
115
  unique_ptr<BaseStatistics> base_stats);
116
116
  idx_t InspectConjunctionOR(idx_t cardinality, idx_t column_index, ConjunctionOrFilter *fil,
117
117
  unique_ptr<BaseStatistics> base_stats);
118
- idx_t InspectTableFilters(idx_t cardinality, LogicalOperator *op, TableFilterSet *table_filters, idx_t table_index);
118
+ idx_t InspectTableFilters(idx_t cardinality, LogicalOperator &op, TableFilterSet &table_filters, idx_t table_index);
119
119
  };
120
120
 
121
121
  } // namespace duckdb
@@ -25,27 +25,27 @@ class JoinOrderOptimizer;
25
25
  class JoinNode {
26
26
  public:
27
27
  //! Represents a node in the join plan
28
- JoinRelationSet *set;
29
- NeighborInfo *info;
28
+ JoinRelationSet &set;
29
+ optional_ptr<NeighborInfo> info;
30
30
  //! If the JoinNode is a base table, then base_cardinality is the cardinality before filters
31
31
  //! estimated_props.cardinality will be the cardinality after filters. With no filters, the two are equal
32
32
  bool has_filter;
33
- JoinNode *left;
34
- JoinNode *right;
33
+ optional_ptr<JoinNode> left;
34
+ optional_ptr<JoinNode> right;
35
35
 
36
36
  unique_ptr<EstimatedProperties> estimated_props;
37
37
 
38
38
  //! Create a leaf node in the join tree
39
39
  //! set cost to 0 for leaf nodes
40
40
  //! cost will be the cost to *produce* an intermediate table
41
- JoinNode(JoinRelationSet *set, const double base_cardinality);
41
+ JoinNode(JoinRelationSet &set, const double base_cardinality);
42
42
 
43
43
  //! Create an intermediate node in the join tree. base_cardinality = estimated_props.cardinality
44
- JoinNode(JoinRelationSet *set, NeighborInfo *info, JoinNode *left, JoinNode *right, const double base_cardinality,
45
- double cost);
44
+ JoinNode(JoinRelationSet &set, optional_ptr<NeighborInfo> info, JoinNode &left, JoinNode &right,
45
+ const double base_cardinality, double cost);
46
46
 
47
47
  bool operator==(const JoinNode &other) {
48
- return other.set->ToString().compare(set->ToString()) == 0;
48
+ return other.set.ToString().compare(set.ToString()) == 0;
49
49
  }
50
50
 
51
51
  private:
@@ -22,6 +22,14 @@
22
22
 
23
23
  namespace duckdb {
24
24
 
25
+ struct GenerateJoinRelation {
26
+ GenerateJoinRelation(JoinRelationSet &set, unique_ptr<LogicalOperator> op_p) : set(set), op(std::move(op_p)) {
27
+ }
28
+
29
+ JoinRelationSet &set;
30
+ unique_ptr<LogicalOperator> op;
31
+ };
32
+
25
33
  class JoinOrderOptimizer {
26
34
  public:
27
35
  explicit JoinOrderOptimizer(ClientContext &context)
@@ -31,8 +39,9 @@ public:
31
39
  //! Perform join reordering inside a plan
32
40
  unique_ptr<LogicalOperator> Optimize(unique_ptr<LogicalOperator> plan);
33
41
 
34
- unique_ptr<JoinNode> CreateJoinTree(JoinRelationSet *set, const vector<NeighborInfo *> &possible_connections,
35
- JoinNode *left, JoinNode *right);
42
+ unique_ptr<JoinNode> CreateJoinTree(JoinRelationSet &set,
43
+ const vector<reference<NeighborInfo>> &possible_connections, JoinNode &left,
44
+ JoinNode &right);
36
45
 
37
46
  private:
38
47
  ClientContext &context;
@@ -71,23 +80,23 @@ private:
71
80
 
72
81
  //! Traverse the query tree to find (1) base relations, (2) existing join conditions and (3) filters that can be
73
82
  //! rewritten into joins. Returns true if there are joins in the tree that can be reordered, false otherwise.
74
- bool ExtractJoinRelations(LogicalOperator &input_op, vector<LogicalOperator *> &filter_operators,
75
- LogicalOperator *parent = nullptr);
83
+ bool ExtractJoinRelations(LogicalOperator &input_op, vector<reference<LogicalOperator>> &filter_operators,
84
+ optional_ptr<LogicalOperator> parent = nullptr);
76
85
 
77
86
  //! Emit a pair as a potential join candidate. Returns the best plan found for the (left, right) connection (either
78
87
  //! the newly created plan, or an existing plan)
79
- JoinNode *EmitPair(JoinRelationSet *left, JoinRelationSet *right, const vector<NeighborInfo *> &info);
88
+ JoinNode &EmitPair(JoinRelationSet &left, JoinRelationSet &right, const vector<reference<NeighborInfo>> &info);
80
89
  //! Tries to emit a potential join candidate pair. Returns false if too many pairs have already been emitted,
81
90
  //! cancelling the dynamic programming step.
82
- bool TryEmitPair(JoinRelationSet *left, JoinRelationSet *right, const vector<NeighborInfo *> &info);
91
+ bool TryEmitPair(JoinRelationSet &left, JoinRelationSet &right, const vector<reference<NeighborInfo>> &info);
83
92
 
84
- bool EnumerateCmpRecursive(JoinRelationSet *left, JoinRelationSet *right, unordered_set<idx_t> exclusion_set);
93
+ bool EnumerateCmpRecursive(JoinRelationSet &left, JoinRelationSet &right, unordered_set<idx_t> exclusion_set);
85
94
  //! Emit a relation set node
86
- bool EmitCSG(JoinRelationSet *node);
95
+ bool EmitCSG(JoinRelationSet &node);
87
96
  //! Enumerate the possible connected subgraphs that can be joined together in the join graph
88
- bool EnumerateCSGRecursive(JoinRelationSet *node, unordered_set<idx_t> &exclusion_set);
97
+ bool EnumerateCSGRecursive(JoinRelationSet &node, unordered_set<idx_t> &exclusion_set);
89
98
  //! Rewrite a logical query plan given the join plan
90
- unique_ptr<LogicalOperator> RewritePlan(unique_ptr<LogicalOperator> plan, JoinNode *node);
99
+ unique_ptr<LogicalOperator> RewritePlan(unique_ptr<LogicalOperator> plan, JoinNode &node);
91
100
  //! Generate cross product edges inside the side
92
101
  void GenerateCrossProducts();
93
102
  //! Perform the join order solving
@@ -98,13 +107,12 @@ private:
98
107
  //! Solve the join order approximately using a greedy algorithm
99
108
  void SolveJoinOrderApproximately();
100
109
 
101
- void UpdateDPTree(JoinNode *new_plan);
110
+ void UpdateDPTree(JoinNode &new_plan);
102
111
 
103
- void UpdateJoinNodesInFullPlan(JoinNode *node);
104
- bool NodeInFullPlan(JoinNode *node);
112
+ void UpdateJoinNodesInFullPlan(JoinNode &node);
113
+ bool NodeInFullPlan(JoinNode &node);
105
114
 
106
- std::pair<JoinRelationSet *, unique_ptr<LogicalOperator>>
107
- GenerateJoins(vector<unique_ptr<LogicalOperator>> &extracted_relations, JoinNode *node);
115
+ GenerateJoinRelation GenerateJoins(vector<unique_ptr<LogicalOperator>> &extracted_relations, JoinNode &node);
108
116
  };
109
117
 
110
118
  } // namespace duckdb
@@ -11,18 +11,17 @@
11
11
  #include "duckdb/common/common.hpp"
12
12
  #include "duckdb/common/unordered_map.hpp"
13
13
  #include "duckdb/common/unordered_set.hpp"
14
+ #include "duckdb/common/optional_ptr.hpp"
14
15
 
15
16
  namespace duckdb {
16
17
  class LogicalOperator;
17
18
 
18
19
  //! Represents a single relation and any metadata accompanying that relation
19
20
  struct SingleJoinRelation {
20
- LogicalOperator *op;
21
- LogicalOperator *parent;
21
+ LogicalOperator &op;
22
+ optional_ptr<LogicalOperator> parent;
22
23
 
23
- SingleJoinRelation() {
24
- }
25
- SingleJoinRelation(LogicalOperator *op, LogicalOperator *parent) : op(op), parent(parent) {
24
+ SingleJoinRelation(LogicalOperator &op, optional_ptr<LogicalOperator> parent) : op(op), parent(parent) {
26
25
  }
27
26
  };
28
27
 
@@ -36,7 +35,7 @@ struct JoinRelationSet {
36
35
  unique_ptr<idx_t[]> relations;
37
36
  idx_t count;
38
37
 
39
- static bool IsSubset(JoinRelationSet *super, JoinRelationSet *sub);
38
+ static bool IsSubset(JoinRelationSet &super, JoinRelationSet &sub);
40
39
  };
41
40
 
42
41
  //! The JoinRelationTree is a structure holding all the created JoinRelationSet objects and allowing fast lookup on to
@@ -52,13 +51,13 @@ public:
52
51
 
53
52
  public:
54
53
  //! Create or get a JoinRelationSet from a single node with the given index
55
- JoinRelationSet *GetJoinRelation(idx_t index);
54
+ JoinRelationSet &GetJoinRelation(idx_t index);
56
55
  //! Create or get a JoinRelationSet from a set of relation bindings
57
- JoinRelationSet *GetJoinRelation(unordered_set<idx_t> &bindings);
56
+ JoinRelationSet &GetJoinRelation(unordered_set<idx_t> &bindings);
58
57
  //! Create or get a JoinRelationSet from a (sorted, duplicate-free!) list of relations
59
- JoinRelationSet *GetJoinRelation(unique_ptr<idx_t[]> relations, idx_t count);
58
+ JoinRelationSet &GetJoinRelation(unique_ptr<idx_t[]> relations, idx_t count);
60
59
  //! Union two sets of relations together and create a new relation set
61
- JoinRelationSet *Union(JoinRelationSet *left, JoinRelationSet *right);
60
+ JoinRelationSet &Union(JoinRelationSet &left, JoinRelationSet &right);
62
61
  // //! Create the set difference of left \ right (i.e. all elements in left that are not in right)
63
62
  // JoinRelationSet *Difference(JoinRelationSet *left, JoinRelationSet *right);
64
63
 
@@ -15,6 +15,7 @@
15
15
  #include "duckdb/optimizer/join_order/join_relation.hpp"
16
16
  #include "duckdb/common/vector.hpp"
17
17
  #include "duckdb/planner/column_binding.hpp"
18
+ #include "duckdb/common/optional_ptr.hpp"
18
19
 
19
20
  #include <functional>
20
21
 
@@ -23,22 +24,28 @@ class Expression;
23
24
  class LogicalOperator;
24
25
 
25
26
  struct FilterInfo {
27
+ FilterInfo(JoinRelationSet &set, idx_t filter_index) : set(set), filter_index(filter_index) {
28
+ }
29
+
30
+ JoinRelationSet &set;
26
31
  idx_t filter_index;
27
- JoinRelationSet *left_set = nullptr;
28
- JoinRelationSet *right_set = nullptr;
32
+ optional_ptr<JoinRelationSet> left_set;
33
+ optional_ptr<JoinRelationSet> right_set;
29
34
  ColumnBinding left_binding;
30
35
  ColumnBinding right_binding;
31
- JoinRelationSet *set = nullptr;
32
36
  };
33
37
 
34
38
  struct FilterNode {
35
- vector<FilterInfo *> filters;
39
+ vector<reference<FilterInfo>> filters;
36
40
  unordered_map<idx_t, unique_ptr<FilterNode>> children;
37
41
  };
38
42
 
39
43
  struct NeighborInfo {
40
- JoinRelationSet *neighbor;
41
- vector<FilterInfo *> filters;
44
+ NeighborInfo(JoinRelationSet &neighbor) : neighbor(neighbor) {
45
+ }
46
+
47
+ JoinRelationSet &neighbor;
48
+ vector<reference<FilterInfo>> filters;
42
49
  };
43
50
 
44
51
  //! The QueryGraph contains edges between relations and allows edges to be created/queried
@@ -55,18 +62,18 @@ public:
55
62
  void Print();
56
63
 
57
64
  //! Create an edge in the edge_set
58
- void CreateEdge(JoinRelationSet *left, JoinRelationSet *right, FilterInfo *info);
65
+ void CreateEdge(JoinRelationSet &left, JoinRelationSet &right, optional_ptr<FilterInfo> info);
59
66
  //! Returns a connection if there is an edge that connects these two sets, or nullptr otherwise
60
- vector<NeighborInfo *> GetConnections(JoinRelationSet *node, JoinRelationSet *other);
67
+ vector<reference<NeighborInfo>> GetConnections(JoinRelationSet &node, JoinRelationSet &other);
61
68
  //! Enumerate the neighbors of a specific node that do not belong to any of the exclusion_set. Note that if a
62
69
  //! neighbor has multiple nodes, this function will return the lowest entry in that set.
63
- vector<idx_t> GetNeighbors(JoinRelationSet *node, unordered_set<idx_t> &exclusion_set);
70
+ vector<idx_t> GetNeighbors(JoinRelationSet &node, unordered_set<idx_t> &exclusion_set);
64
71
  //! Enumerate all neighbors of a given JoinRelationSet node
65
- void EnumerateNeighbors(JoinRelationSet *node, const std::function<bool(NeighborInfo *)> &callback);
72
+ void EnumerateNeighbors(JoinRelationSet &node, const std::function<bool(NeighborInfo &)> &callback);
66
73
 
67
74
  private:
68
75
  //! Get the QueryEdge of a specific node
69
- QueryEdge *GetQueryEdge(JoinRelationSet *left);
76
+ QueryEdge &GetQueryEdge(JoinRelationSet &left);
70
77
 
71
78
  QueryEdge root;
72
79
  };
@@ -61,7 +61,7 @@ public:
61
61
 
62
62
  public:
63
63
  //! Build the MetaPipeline with 'op' as the first operator (excl. the shared sink)
64
- void Build(PhysicalOperator *op);
64
+ void Build(PhysicalOperator &op);
65
65
  //! Ready all the pipelines (recursively)
66
66
  void Ready();
67
67
 
@@ -29,7 +29,11 @@ struct ExportedTableData {
29
29
  };
30
30
 
31
31
  struct ExportedTableInfo {
32
- TableCatalogEntry *entry;
32
+ ExportedTableInfo(TableCatalogEntry &entry, ExportedTableData table_data)
33
+ : entry(entry), table_data(std::move(table_data)) {
34
+ }
35
+
36
+ TableCatalogEntry &entry;
33
37
  ExportedTableData table_data;
34
38
  };
35
39
 
@@ -12,6 +12,7 @@
12
12
  #include "duckdb/parser/tableref.hpp"
13
13
  #include "duckdb/planner/tableref/bound_basetableref.hpp"
14
14
  #include "duckdb/common/unordered_map.hpp"
15
+ #include "duckdb/common/optional_ptr.hpp"
15
16
 
16
17
  namespace duckdb {
17
18
 
@@ -22,7 +23,7 @@ struct VacuumOptions {
22
23
 
23
24
  struct VacuumInfo : public ParseInfo {
24
25
  public:
25
- explicit VacuumInfo(VacuumOptions options) : options(options), has_table(false), table(nullptr) {};
26
+ explicit VacuumInfo(VacuumOptions options) : options(options), has_table(false) {};
26
27
 
27
28
  unique_ptr<VacuumInfo> Copy() {
28
29
  auto result = make_uniq<VacuumInfo>(options);
@@ -38,7 +39,7 @@ public:
38
39
  public:
39
40
  bool has_table;
40
41
  unique_ptr<TableRef> ref;
41
- TableCatalogEntry *table;
42
+ optional_ptr<TableCatalogEntry> table;
42
43
  unordered_map<idx_t, idx_t> column_id_map;
43
44
  vector<string> columns;
44
45
  };
@@ -11,18 +11,20 @@
11
11
  #include "duckdb/common/common.hpp"
12
12
  #include "duckdb/common/vector.hpp"
13
13
  #include "duckdb/common/exception_format_value.hpp"
14
+ #include "duckdb/common/optional_ptr.hpp"
14
15
 
15
16
  namespace duckdb {
16
17
  class SQLStatement;
17
18
 
18
19
  class QueryErrorContext {
19
20
  public:
20
- explicit QueryErrorContext(SQLStatement *statement_ = nullptr, idx_t query_location_ = DConstants::INVALID_INDEX)
21
+ explicit QueryErrorContext(optional_ptr<SQLStatement> statement_ = nullptr,
22
+ idx_t query_location_ = DConstants::INVALID_INDEX)
21
23
  : statement(statement_), query_location(query_location_) {
22
24
  }
23
25
 
24
26
  //! The query statement
25
- SQLStatement *statement;
27
+ optional_ptr<SQLStatement> statement;
26
28
  //! The location in which the error should be thrown
27
29
  idx_t query_location;
28
30
 
@@ -49,19 +49,17 @@ class Transformer {
49
49
 
50
50
  public:
51
51
  explicit Transformer(ParserOptions &options);
52
- explicit Transformer(Transformer *parent);
52
+ explicit Transformer(Transformer &parent);
53
53
  ~Transformer();
54
54
 
55
55
  //! Transforms a Postgres parse tree into a set of SQL Statements
56
56
  bool TransformParseTree(duckdb_libpgquery::PGList *tree, vector<unique_ptr<SQLStatement>> &statements);
57
57
  string NodetypeToString(duckdb_libpgquery::PGNodeTag type);
58
58
 
59
- idx_t ParamCount() {
60
- return parent ? parent->ParamCount() : prepared_statement_parameter_index;
61
- }
59
+ idx_t ParamCount() const;
62
60
 
63
61
  private:
64
- Transformer *parent;
62
+ optional_ptr<Transformer> parent;
65
63
  //! Parser options
66
64
  ParserOptions &options;
67
65
  //! The current prepared statement parameter index
@@ -80,36 +78,12 @@ private:
80
78
  void Clear();
81
79
  bool InWindowDefinition();
82
80
 
83
- void SetParamCount(idx_t new_count) {
84
- if (parent) {
85
- parent->SetParamCount(new_count);
86
- } else {
87
- this->prepared_statement_parameter_index = new_count;
88
- }
89
- }
90
- void SetNamedParam(const string &name, int32_t index) {
91
- if (parent) {
92
- parent->SetNamedParam(name, index);
93
- } else {
94
- D_ASSERT(!named_param_map.count(name));
95
- this->named_param_map[name] = index;
96
- }
97
- }
98
- bool GetNamedParam(const string &name, int32_t &index) {
99
- if (parent) {
100
- return parent->GetNamedParam(name, index);
101
- } else {
102
- auto entry = named_param_map.find(name);
103
- if (entry == named_param_map.end()) {
104
- return false;
105
- }
106
- index = entry->second;
107
- return true;
108
- }
109
- }
110
- bool HasNamedParameters() const {
111
- return parent ? parent->HasNamedParameters() : !named_param_map.empty();
112
- }
81
+ Transformer &RootTransformer();
82
+ const Transformer &RootTransformer() const;
83
+ void SetParamCount(idx_t new_count);
84
+ void SetNamedParam(const string &name, int32_t index);
85
+ bool GetNamedParam(const string &name, int32_t &index);
86
+ bool HasNamedParameters() const;
113
87
 
114
88
  void AddPivotEntry(string enum_name, unique_ptr<SelectNode> source, unique_ptr<ParsedExpression> column);
115
89
  unique_ptr<SQLStatement> GenerateCreateEnumStmt(unique_ptr<CreatePivotEntry> entry);
@@ -21,6 +21,7 @@
21
21
  #include "duckdb/planner/bound_tokens.hpp"
22
22
  #include "duckdb/planner/expression/bound_columnref_expression.hpp"
23
23
  #include "duckdb/planner/logical_operator.hpp"
24
+ #include "duckdb/common/reference_map.hpp"
24
25
 
25
26
  namespace duckdb {
26
27
  class BoundResultModifier;
@@ -76,43 +77,43 @@ class Binder : public std::enable_shared_from_this<Binder> {
76
77
  friend class RecursiveSubqueryPlanner;
77
78
 
78
79
  public:
79
- DUCKDB_API static shared_ptr<Binder> CreateBinder(ClientContext &context, Binder *parent = nullptr,
80
+ DUCKDB_API static shared_ptr<Binder> CreateBinder(ClientContext &context, optional_ptr<Binder> parent = nullptr,
80
81
  bool inherit_ctes = true);
81
82
 
82
83
  //! The client context
83
84
  ClientContext &context;
84
85
  //! A mapping of names to common table expressions
85
- case_insensitive_map_t<CommonTableExpressionInfo *> CTE_bindings; // NOLINT
86
+ case_insensitive_map_t<reference<CommonTableExpressionInfo>> CTE_bindings; // NOLINT
86
87
  //! The CTEs that have already been bound
87
- unordered_set<CommonTableExpressionInfo *> bound_ctes;
88
+ reference_set_t<CommonTableExpressionInfo> bound_ctes;
88
89
  //! The bind context
89
90
  BindContext bind_context;
90
91
  //! The set of correlated columns bound by this binder (FIXME: this should probably be an unordered_set and not a
91
92
  //! vector)
92
93
  vector<CorrelatedColumnInfo> correlated_columns;
93
94
  //! The set of parameter expressions bound by this binder
94
- BoundParameterMap *parameters;
95
+ optional_ptr<BoundParameterMap> parameters;
95
96
  //! Statement properties
96
97
  StatementProperties properties;
97
98
  //! The alias for the currently processing subquery, if it exists
98
99
  string alias;
99
100
  //! Macro parameter bindings (if any)
100
- DummyBinding *macro_binding = nullptr;
101
+ optional_ptr<DummyBinding> macro_binding;
101
102
  //! The intermediate lambda bindings to bind nested lambdas (if any)
102
- vector<DummyBinding> *lambda_bindings = nullptr;
103
+ optional_ptr<vector<DummyBinding>> lambda_bindings;
103
104
 
104
105
  public:
105
106
  DUCKDB_API BoundStatement Bind(SQLStatement &statement);
106
107
  DUCKDB_API BoundStatement Bind(QueryNode &node);
107
108
 
108
109
  unique_ptr<BoundCreateTableInfo> BindCreateTableInfo(unique_ptr<CreateInfo> info);
109
- unique_ptr<BoundCreateTableInfo> BindCreateTableInfo(unique_ptr<CreateInfo> info, SchemaCatalogEntry *schema);
110
+ unique_ptr<BoundCreateTableInfo> BindCreateTableInfo(unique_ptr<CreateInfo> info, SchemaCatalogEntry &schema);
110
111
 
111
112
  vector<unique_ptr<Expression>> BindCreateIndexExpressions(TableCatalogEntry *table, CreateIndexInfo *info);
112
113
 
113
114
  void BindCreateViewInfo(CreateViewInfo &base);
114
- SchemaCatalogEntry *BindSchema(CreateInfo &info);
115
- SchemaCatalogEntry *BindCreateFunctionInfo(CreateInfo &info);
115
+ SchemaCatalogEntry &BindSchema(CreateInfo &info);
116
+ SchemaCatalogEntry &BindCreateFunctionInfo(CreateInfo &info);
116
117
 
117
118
  //! Check usage, and cast named parameters to their types
118
119
  static void BindNamedParameters(named_parameter_type_map_t &types, named_parameter_map_t &values,
@@ -125,22 +126,22 @@ public:
125
126
  idx_t GenerateTableIndex();
126
127
 
127
128
  //! Add a common table expression to the binder
128
- void AddCTE(const string &name, CommonTableExpressionInfo *cte);
129
+ void AddCTE(const string &name, CommonTableExpressionInfo &cte);
129
130
  //! Find a common table expression by name; returns nullptr if none exists
130
- CommonTableExpressionInfo *FindCTE(const string &name, bool skip = false);
131
+ optional_ptr<CommonTableExpressionInfo> FindCTE(const string &name, bool skip = false);
131
132
 
132
- bool CTEIsAlreadyBound(CommonTableExpressionInfo *cte);
133
+ bool CTEIsAlreadyBound(CommonTableExpressionInfo &cte);
133
134
 
134
135
  //! Add the view to the set of currently bound views - used for detecting recursive view definitions
135
- void AddBoundView(ViewCatalogEntry *view);
136
+ void AddBoundView(ViewCatalogEntry &view);
136
137
 
137
- void PushExpressionBinder(ExpressionBinder *binder);
138
+ void PushExpressionBinder(ExpressionBinder &binder);
138
139
  void PopExpressionBinder();
139
- void SetActiveBinder(ExpressionBinder *binder);
140
- ExpressionBinder *GetActiveBinder();
140
+ void SetActiveBinder(ExpressionBinder &binder);
141
+ ExpressionBinder &GetActiveBinder();
141
142
  bool HasActiveBinder();
142
143
 
143
- vector<ExpressionBinder *> &GetActiveBinders();
144
+ vector<reference<ExpressionBinder>> &GetActiveBinders();
144
145
 
145
146
  void MergeCorrelatedColumns(vector<CorrelatedColumnInfo> &other);
146
147
  //! Add a correlated column to this binder (if it does not exist)
@@ -184,7 +185,7 @@ public:
184
185
  BindingMode GetBindingMode();
185
186
  void AddTableName(string table_name);
186
187
  const unordered_set<string> &GetTableNames();
187
- SQLStatement *GetRootStatement() {
188
+ optional_ptr<SQLStatement> GetRootStatement() {
188
189
  return root_statement;
189
190
  }
190
191
 
@@ -194,7 +195,7 @@ private:
194
195
  //! The parent binder (if any)
195
196
  shared_ptr<Binder> parent;
196
197
  //! The vector of active binders
197
- vector<ExpressionBinder *> active_binders;
198
+ vector<reference<ExpressionBinder>> active_binders;
198
199
  //! The count of bound_tables
199
200
  idx_t bound_tables;
200
201
  //! Whether or not the binder has any unplanned subqueries that still need to be planned
@@ -206,13 +207,13 @@ private:
206
207
  //! Whether or not the binder can contain NULLs as the root of expressions
207
208
  bool can_contain_nulls = false;
208
209
  //! The root statement of the query that is currently being parsed
209
- SQLStatement *root_statement = nullptr;
210
+ optional_ptr<SQLStatement> root_statement;
210
211
  //! Binding mode
211
212
  BindingMode mode = BindingMode::STANDARD_BINDING;
212
213
  //! Table names extracted for BindingMode::EXTRACT_NAMES
213
214
  unordered_set<string> table_names;
214
215
  //! The set of bound views
215
- unordered_set<ViewCatalogEntry *> bound_views;
216
+ reference_set_t<ViewCatalogEntry> bound_views;
216
217
 
217
218
  private:
218
219
  //! Bind the expressions of generated columns to check for errors
@@ -273,7 +274,7 @@ private:
273
274
 
274
275
  unique_ptr<BoundTableRef> Bind(BaseTableRef &ref);
275
276
  unique_ptr<BoundTableRef> Bind(JoinRef &ref);
276
- unique_ptr<BoundTableRef> Bind(SubqueryRef &ref, CommonTableExpressionInfo *cte = nullptr);
277
+ unique_ptr<BoundTableRef> Bind(SubqueryRef &ref, optional_ptr<CommonTableExpressionInfo> cte = nullptr);
277
278
  unique_ptr<BoundTableRef> Bind(TableFunctionRef &ref);
278
279
  unique_ptr<BoundTableRef> Bind(EmptyTableRef &ref);
279
280
  unique_ptr<BoundTableRef> Bind(ExpressionListRef &ref);
@@ -349,7 +350,7 @@ private:
349
350
 
350
351
  //! If only a schema name is provided (e.g. "a.b") then figure out if "a" is a schema or a catalog name
351
352
  void BindSchemaOrCatalog(string &catalog_name, string &schema_name);
352
- SchemaCatalogEntry *BindCreateSchema(CreateInfo &info);
353
+ SchemaCatalogEntry &BindCreateSchema(CreateInfo &info);
353
354
 
354
355
  unique_ptr<BoundQueryNode> BindSelectNode(SelectNode &statement, unique_ptr<BoundTableRef> from_table);
355
356