duckdb 0.7.2-dev2430.0 → 0.7.2-dev2552.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 (201) hide show
  1. package/package.json +1 -1
  2. package/src/connection.cpp +1 -1
  3. package/src/duckdb/extension/icu/icu-dateadd.cpp +3 -3
  4. package/src/duckdb/extension/icu/icu-datepart.cpp +3 -3
  5. package/src/duckdb/extension/icu/icu-datesub.cpp +2 -2
  6. package/src/duckdb/extension/icu/icu-datetrunc.cpp +1 -1
  7. package/src/duckdb/extension/icu/icu-extension.cpp +3 -3
  8. package/src/duckdb/extension/icu/icu-list-range.cpp +2 -2
  9. package/src/duckdb/extension/icu/icu-makedate.cpp +1 -1
  10. package/src/duckdb/extension/icu/icu-strptime.cpp +4 -4
  11. package/src/duckdb/extension/icu/icu-table-range.cpp +2 -2
  12. package/src/duckdb/extension/icu/icu-timebucket.cpp +1 -1
  13. package/src/duckdb/extension/icu/icu-timezone.cpp +4 -4
  14. package/src/duckdb/extension/json/json-extension.cpp +6 -6
  15. package/src/duckdb/extension/parquet/parquet-extension.cpp +9 -8
  16. package/src/duckdb/src/catalog/catalog.cpp +166 -127
  17. package/src/duckdb/src/catalog/catalog_entry/copy_function_catalog_entry.cpp +3 -3
  18. package/src/duckdb/src/catalog/catalog_entry/duck_index_entry.cpp +1 -1
  19. package/src/duckdb/src/catalog/catalog_entry/duck_schema_entry.cpp +90 -82
  20. package/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp +65 -67
  21. package/src/duckdb/src/catalog/catalog_entry/index_catalog_entry.cpp +3 -3
  22. package/src/duckdb/src/catalog/catalog_entry/pragma_function_catalog_entry.cpp +4 -4
  23. package/src/duckdb/src/catalog/catalog_entry/scalar_function_catalog_entry.cpp +8 -8
  24. package/src/duckdb/src/catalog/catalog_entry/scalar_macro_catalog_entry.cpp +10 -10
  25. package/src/duckdb/src/catalog/catalog_entry/schema_catalog_entry.cpp +6 -6
  26. package/src/duckdb/src/catalog/catalog_entry/sequence_catalog_entry.cpp +6 -6
  27. package/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp +4 -4
  28. package/src/duckdb/src/catalog/catalog_entry/table_function_catalog_entry.cpp +9 -9
  29. package/src/duckdb/src/catalog/catalog_entry/type_catalog_entry.cpp +5 -5
  30. package/src/duckdb/src/catalog/catalog_entry/view_catalog_entry.cpp +23 -23
  31. package/src/duckdb/src/catalog/catalog_entry.cpp +27 -6
  32. package/src/duckdb/src/catalog/catalog_search_path.cpp +2 -2
  33. package/src/duckdb/src/catalog/catalog_set.cpp +84 -87
  34. package/src/duckdb/src/catalog/catalog_transaction.cpp +1 -1
  35. package/src/duckdb/src/catalog/default/default_functions.cpp +1 -1
  36. package/src/duckdb/src/catalog/default/default_schemas.cpp +1 -1
  37. package/src/duckdb/src/catalog/default/default_types.cpp +1 -1
  38. package/src/duckdb/src/catalog/default/default_views.cpp +1 -1
  39. package/src/duckdb/src/catalog/dependency_list.cpp +2 -2
  40. package/src/duckdb/src/catalog/dependency_manager.cpp +9 -10
  41. package/src/duckdb/src/catalog/duck_catalog.cpp +30 -26
  42. package/src/duckdb/src/catalog/similar_catalog_entry.cpp +1 -1
  43. package/src/duckdb/src/common/types.cpp +15 -27
  44. package/src/duckdb/src/execution/operator/join/physical_index_join.cpp +2 -2
  45. package/src/duckdb/src/execution/operator/persistent/physical_batch_insert.cpp +4 -3
  46. package/src/duckdb/src/execution/operator/persistent/physical_export.cpp +19 -18
  47. package/src/duckdb/src/execution/operator/persistent/physical_insert.cpp +5 -5
  48. package/src/duckdb/src/execution/operator/schema/physical_alter.cpp +1 -1
  49. package/src/duckdb/src/execution/operator/schema/physical_create_function.cpp +1 -1
  50. package/src/duckdb/src/execution/operator/schema/physical_create_index.cpp +6 -5
  51. package/src/duckdb/src/execution/operator/schema/physical_create_schema.cpp +1 -1
  52. package/src/duckdb/src/execution/operator/schema/physical_create_sequence.cpp +1 -1
  53. package/src/duckdb/src/execution/operator/schema/physical_create_table.cpp +2 -2
  54. package/src/duckdb/src/execution/operator/schema/physical_create_type.cpp +4 -3
  55. package/src/duckdb/src/execution/operator/schema/physical_create_view.cpp +1 -1
  56. package/src/duckdb/src/execution/operator/schema/physical_detach.cpp +1 -1
  57. package/src/duckdb/src/execution/operator/schema/physical_drop.cpp +2 -2
  58. package/src/duckdb/src/execution/physical_plan/plan_aggregate.cpp +1 -1
  59. package/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp +4 -4
  60. package/src/duckdb/src/execution/physical_plan/plan_create_table.cpp +4 -3
  61. package/src/duckdb/src/execution/physical_plan/plan_delete.cpp +1 -1
  62. package/src/duckdb/src/execution/physical_plan/plan_insert.cpp +1 -1
  63. package/src/duckdb/src/execution/physical_plan/plan_update.cpp +1 -1
  64. package/src/duckdb/src/function/built_in_functions.cpp +10 -10
  65. package/src/duckdb/src/function/function_binder.cpp +3 -3
  66. package/src/duckdb/src/function/scalar/list/list_aggregates.cpp +5 -6
  67. package/src/duckdb/src/function/scalar/operators/arithmetic.cpp +2 -2
  68. package/src/duckdb/src/function/scalar/sequence/nextval.cpp +9 -8
  69. package/src/duckdb/src/function/scalar/system/aggregate_export.cpp +6 -6
  70. package/src/duckdb/src/function/table/arrow.cpp +32 -31
  71. package/src/duckdb/src/function/table/arrow_conversion.cpp +75 -59
  72. package/src/duckdb/src/function/table/system/duckdb_columns.cpp +8 -7
  73. package/src/duckdb/src/function/table/system/duckdb_constraints.cpp +14 -14
  74. package/src/duckdb/src/function/table/system/duckdb_databases.cpp +2 -2
  75. package/src/duckdb/src/function/table/system/duckdb_functions.cpp +26 -25
  76. package/src/duckdb/src/function/table/system/duckdb_indexes.cpp +13 -12
  77. package/src/duckdb/src/function/table/system/duckdb_schemas.cpp +7 -7
  78. package/src/duckdb/src/function/table/system/duckdb_sequences.cpp +8 -9
  79. package/src/duckdb/src/function/table/system/duckdb_tables.cpp +10 -9
  80. package/src/duckdb/src/function/table/system/duckdb_types.cpp +13 -13
  81. package/src/duckdb/src/function/table/system/duckdb_views.cpp +11 -10
  82. package/src/duckdb/src/function/table/system/pragma_collations.cpp +2 -2
  83. package/src/duckdb/src/function/table/system/pragma_database_size.cpp +5 -5
  84. package/src/duckdb/src/function/table/system/pragma_storage_info.cpp +3 -3
  85. package/src/duckdb/src/function/table/system/pragma_table_info.cpp +2 -2
  86. package/src/duckdb/src/function/table/table_scan.cpp +39 -37
  87. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  88. package/src/duckdb/src/function/udf_function.cpp +2 -2
  89. package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +122 -81
  90. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/aggregate_function_catalog_entry.hpp +2 -3
  91. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/collate_catalog_entry.hpp +3 -3
  92. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/copy_function_catalog_entry.hpp +1 -1
  93. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_index_entry.hpp +1 -1
  94. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_schema_entry.hpp +24 -20
  95. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_table_entry.hpp +3 -3
  96. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/index_catalog_entry.hpp +1 -1
  97. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/macro_catalog_entry.hpp +2 -2
  98. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/pragma_function_catalog_entry.hpp +1 -1
  99. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/scalar_function_catalog_entry.hpp +2 -2
  100. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/scalar_macro_catalog_entry.hpp +1 -1
  101. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/schema_catalog_entry.hpp +22 -17
  102. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/sequence_catalog_entry.hpp +1 -1
  103. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_catalog_entry.hpp +1 -1
  104. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_function_catalog_entry.hpp +2 -2
  105. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_macro_catalog_entry.hpp +1 -1
  106. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/type_catalog_entry.hpp +1 -1
  107. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/view_catalog_entry.hpp +3 -3
  108. package/src/duckdb/src/include/duckdb/catalog/catalog_entry.hpp +28 -7
  109. package/src/duckdb/src/include/duckdb/catalog/catalog_set.hpp +20 -19
  110. package/src/duckdb/src/include/duckdb/catalog/duck_catalog.hpp +9 -9
  111. package/src/duckdb/src/include/duckdb/catalog/similar_catalog_entry.hpp +2 -1
  112. package/src/duckdb/src/include/duckdb/catalog/standard_entry.hpp +10 -4
  113. package/src/duckdb/src/include/duckdb/common/enums/on_entry_not_found.hpp +17 -0
  114. package/src/duckdb/src/include/duckdb/common/types.hpp +3 -4
  115. package/src/duckdb/src/include/duckdb/function/function_serialization.hpp +4 -4
  116. package/src/duckdb/src/include/duckdb/function/scalar_function.hpp +3 -2
  117. package/src/duckdb/src/include/duckdb/function/table/table_scan.hpp +5 -4
  118. package/src/duckdb/src/include/duckdb/function/table_function.hpp +28 -15
  119. package/src/duckdb/src/include/duckdb/main/attached_database.hpp +2 -0
  120. package/src/duckdb/src/include/duckdb/main/client_context.hpp +1 -1
  121. package/src/duckdb/src/include/duckdb/main/database_manager.hpp +3 -2
  122. package/src/duckdb/src/include/duckdb/parser/expression/bound_expression.hpp +2 -0
  123. package/src/duckdb/src/include/duckdb/parser/keyword_helper.hpp +2 -2
  124. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_info.hpp +7 -5
  125. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_table_info.hpp +1 -1
  126. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_table_info.hpp +1 -1
  127. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_view_info.hpp +1 -1
  128. package/src/duckdb/src/include/duckdb/parser/parsed_data/detach_info.hpp +3 -2
  129. package/src/duckdb/src/include/duckdb/parser/parsed_data/drop_info.hpp +5 -5
  130. package/src/duckdb/src/include/duckdb/parser/parsed_data/parse_info.hpp +13 -0
  131. package/src/duckdb/src/include/duckdb/parser/tableref.hpp +5 -2
  132. package/src/duckdb/src/include/duckdb/parser/transformer.hpp +2 -0
  133. package/src/duckdb/src/include/duckdb/planner/binder.hpp +2 -2
  134. package/src/duckdb/src/include/duckdb/planner/expression_binder/base_select_binder.hpp +1 -2
  135. package/src/duckdb/src/include/duckdb/planner/expression_binder.hpp +4 -7
  136. package/src/duckdb/src/include/duckdb/planner/operator/logical_get.hpp +1 -1
  137. package/src/duckdb/src/include/duckdb/transaction/transaction.hpp +12 -0
  138. package/src/duckdb/src/main/attached_database.cpp +12 -6
  139. package/src/duckdb/src/main/capi/table_function-c.cpp +17 -16
  140. package/src/duckdb/src/main/client_context.cpp +12 -11
  141. package/src/duckdb/src/main/database_manager.cpp +13 -12
  142. package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +1 -2
  143. package/src/duckdb/src/parser/parsed_data/alter_info.cpp +3 -3
  144. package/src/duckdb/src/parser/parsed_data/alter_scalar_function_info.cpp +2 -2
  145. package/src/duckdb/src/parser/parsed_data/alter_table_function_info.cpp +2 -2
  146. package/src/duckdb/src/parser/parsed_data/alter_table_info.cpp +9 -9
  147. package/src/duckdb/src/parser/parsed_data/create_scalar_function_info.cpp +2 -2
  148. package/src/duckdb/src/parser/parsed_data/create_table_function_info.cpp +2 -2
  149. package/src/duckdb/src/parser/parsed_data/create_table_info.cpp +2 -2
  150. package/src/duckdb/src/parser/parsed_data/create_view_info.cpp +2 -2
  151. package/src/duckdb/src/parser/transform/statement/transform_alter_sequence.cpp +3 -2
  152. package/src/duckdb/src/parser/transform/statement/transform_alter_table.cpp +5 -1
  153. package/src/duckdb/src/parser/transform/statement/transform_detach.cpp +1 -1
  154. package/src/duckdb/src/parser/transform/statement/transform_drop.cpp +1 -1
  155. package/src/duckdb/src/parser/transform/statement/transform_rename.cpp +1 -1
  156. package/src/duckdb/src/planner/binder/expression/bind_aggregate_expression.cpp +26 -27
  157. package/src/duckdb/src/planner/binder/expression/bind_between_expression.cpp +17 -17
  158. package/src/duckdb/src/planner/binder/expression/bind_case_expression.cpp +9 -9
  159. package/src/duckdb/src/planner/binder/expression/bind_cast_expression.cpp +6 -6
  160. package/src/duckdb/src/planner/binder/expression/bind_collate_expression.cpp +6 -6
  161. package/src/duckdb/src/planner/binder/expression/bind_columnref_expression.cpp +2 -2
  162. package/src/duckdb/src/planner/binder/expression/bind_comparison_expression.cpp +21 -21
  163. package/src/duckdb/src/planner/binder/expression/bind_conjunction_expression.cpp +2 -3
  164. package/src/duckdb/src/planner/binder/expression/bind_function_expression.cpp +33 -36
  165. package/src/duckdb/src/planner/binder/expression/bind_macro_expression.cpp +5 -5
  166. package/src/duckdb/src/planner/binder/expression/bind_operator_expression.cpp +23 -23
  167. package/src/duckdb/src/planner/binder/expression/bind_subquery_expression.cpp +4 -4
  168. package/src/duckdb/src/planner/binder/expression/bind_unnest_expression.cpp +7 -7
  169. package/src/duckdb/src/planner/binder/expression/bind_window_expression.cpp +23 -23
  170. package/src/duckdb/src/planner/binder/query_node/bind_table_macro_node.cpp +4 -4
  171. package/src/duckdb/src/planner/binder/statement/bind_copy.cpp +14 -13
  172. package/src/duckdb/src/planner/binder/statement/bind_create.cpp +36 -35
  173. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +3 -3
  174. package/src/duckdb/src/planner/binder/statement/bind_delete.cpp +1 -1
  175. package/src/duckdb/src/planner/binder/statement/bind_drop.cpp +4 -4
  176. package/src/duckdb/src/planner/binder/statement/bind_export.cpp +10 -10
  177. package/src/duckdb/src/planner/binder/statement/bind_insert.cpp +2 -2
  178. package/src/duckdb/src/planner/binder/statement/bind_pragma.cpp +4 -4
  179. package/src/duckdb/src/planner/binder/statement/bind_simple.cpp +5 -4
  180. package/src/duckdb/src/planner/binder/statement/bind_update.cpp +1 -1
  181. package/src/duckdb/src/planner/binder/tableref/bind_basetableref.cpp +3 -3
  182. package/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp +10 -12
  183. package/src/duckdb/src/planner/binder.cpp +2 -2
  184. package/src/duckdb/src/planner/expression/bound_expression.cpp +11 -2
  185. package/src/duckdb/src/planner/operator/logical_copy_to_file.cpp +2 -5
  186. package/src/duckdb/src/planner/operator/logical_create.cpp +2 -1
  187. package/src/duckdb/src/planner/operator/logical_create_index.cpp +2 -2
  188. package/src/duckdb/src/planner/operator/logical_delete.cpp +2 -2
  189. package/src/duckdb/src/planner/operator/logical_get.cpp +1 -1
  190. package/src/duckdb/src/planner/operator/logical_insert.cpp +2 -7
  191. package/src/duckdb/src/planner/operator/logical_update.cpp +2 -6
  192. package/src/duckdb/src/planner/parsed_data/bound_create_table_info.cpp +2 -2
  193. package/src/duckdb/src/planner/pragma_handler.cpp +3 -4
  194. package/src/duckdb/src/storage/checkpoint_manager.cpp +46 -46
  195. package/src/duckdb/src/storage/data_table.cpp +3 -6
  196. package/src/duckdb/src/storage/table/update_segment.cpp +1 -1
  197. package/src/duckdb/src/storage/wal_replay.cpp +28 -30
  198. package/src/duckdb/src/storage/write_ahead_log.cpp +8 -8
  199. package/src/duckdb/src/transaction/cleanup_state.cpp +1 -1
  200. package/src/duckdb/src/transaction/commit_state.cpp +3 -4
  201. package/src/duckdb/src/transaction/transaction_context.cpp +1 -1
@@ -15,6 +15,7 @@
15
15
  #include "duckdb/execution/expression_executor_state.hpp"
16
16
  #include "duckdb/function/function.hpp"
17
17
  #include "duckdb/storage/statistics/base_statistics.hpp"
18
+ #include "duckdb/common/optional_ptr.hpp"
18
19
 
19
20
  namespace duckdb {
20
21
 
@@ -39,13 +40,13 @@ class DependencyList;
39
40
  class ScalarFunctionCatalogEntry;
40
41
 
41
42
  struct FunctionStatisticsInput {
42
- FunctionStatisticsInput(BoundFunctionExpression &expr_p, FunctionData *bind_data_p,
43
+ FunctionStatisticsInput(BoundFunctionExpression &expr_p, optional_ptr<FunctionData> bind_data_p,
43
44
  vector<BaseStatistics> &child_stats_p, unique_ptr<Expression> *expr_ptr_p)
44
45
  : expr(expr_p), bind_data(bind_data_p), child_stats(child_stats_p), expr_ptr(expr_ptr_p) {
45
46
  }
46
47
 
47
48
  BoundFunctionExpression &expr;
48
- FunctionData *bind_data;
49
+ optional_ptr<FunctionData> bind_data;
49
50
  vector<BaseStatistics> &child_stats;
50
51
  unique_ptr<Expression> *expr_ptr;
51
52
  };
@@ -17,11 +17,11 @@ class DuckTableEntry;
17
17
  class TableCatalogEntry;
18
18
 
19
19
  struct TableScanBindData : public TableFunctionData {
20
- explicit TableScanBindData(DuckTableEntry *table) : table(table), is_index_scan(false), is_create_index(false) {
20
+ explicit TableScanBindData(DuckTableEntry &table) : table(table), is_index_scan(false), is_create_index(false) {
21
21
  }
22
22
 
23
23
  //! The table to scan
24
- DuckTableEntry *table;
24
+ DuckTableEntry &table;
25
25
 
26
26
  //! Whether or not the table scan is an index scan
27
27
  bool is_index_scan;
@@ -33,7 +33,7 @@ struct TableScanBindData : public TableFunctionData {
33
33
  public:
34
34
  bool Equals(const FunctionData &other_p) const override {
35
35
  auto &other = (const TableScanBindData &)other_p;
36
- return other.table == table && result_ids == other.result_ids;
36
+ return &other.table == &table && result_ids == other.result_ids;
37
37
  }
38
38
  };
39
39
 
@@ -42,7 +42,8 @@ struct TableScanFunction {
42
42
  static void RegisterFunction(BuiltinFunctions &set);
43
43
  static TableFunction GetFunction();
44
44
  static TableFunction GetIndexScanFunction();
45
- static TableCatalogEntry *GetTableEntry(const TableFunction &function, const FunctionData *bind_data);
45
+ static optional_ptr<TableCatalogEntry> GetTableEntry(const TableFunction &function,
46
+ const optional_ptr<FunctionData> bind_data);
46
47
  };
47
48
 
48
49
  } // namespace duckdb
@@ -14,6 +14,7 @@
14
14
  #include "duckdb/planner/bind_context.hpp"
15
15
  #include "duckdb/planner/logical_operator.hpp"
16
16
  #include "duckdb/storage/statistics/node_statistics.hpp"
17
+ #include "duckdb/common/optional_ptr.hpp"
17
18
 
18
19
  #include <functional>
19
20
 
@@ -26,6 +27,17 @@ class TableFilterSet;
26
27
 
27
28
  struct TableFunctionInfo {
28
29
  DUCKDB_API virtual ~TableFunctionInfo();
30
+
31
+ template <class TARGET>
32
+ TARGET &Cast() {
33
+ D_ASSERT(dynamic_cast<TARGET *>(this));
34
+ return (TARGET &)*this;
35
+ }
36
+ template <class TARGET>
37
+ const TARGET &Cast() const {
38
+ D_ASSERT(dynamic_cast<const TARGET *>(this));
39
+ return (const TARGET &)*this;
40
+ }
29
41
  };
30
42
 
31
43
  struct GlobalTableFunctionState {
@@ -70,7 +82,7 @@ struct LocalTableFunctionState {
70
82
  struct TableFunctionBindInput {
71
83
  TableFunctionBindInput(vector<Value> &inputs, named_parameter_map_t &named_parameters,
72
84
  vector<LogicalType> &input_table_types, vector<string> &input_table_names,
73
- TableFunctionInfo *info)
85
+ optional_ptr<TableFunctionInfo> info)
74
86
  : inputs(inputs), named_parameters(named_parameters), input_table_types(input_table_types),
75
87
  input_table_names(input_table_names), info(info) {
76
88
  }
@@ -79,19 +91,19 @@ struct TableFunctionBindInput {
79
91
  named_parameter_map_t &named_parameters;
80
92
  vector<LogicalType> &input_table_types;
81
93
  vector<string> &input_table_names;
82
- TableFunctionInfo *info;
94
+ optional_ptr<TableFunctionInfo> info;
83
95
  };
84
96
 
85
97
  struct TableFunctionInitInput {
86
- TableFunctionInitInput(const FunctionData *bind_data_p, const vector<column_t> &column_ids_p,
87
- const vector<idx_t> &projection_ids_p, TableFilterSet *filters_p)
98
+ TableFunctionInitInput(optional_ptr<const FunctionData> bind_data_p, const vector<column_t> &column_ids_p,
99
+ const vector<idx_t> &projection_ids_p, optional_ptr<TableFilterSet> filters_p)
88
100
  : bind_data(bind_data_p), column_ids(column_ids_p), projection_ids(projection_ids_p), filters(filters_p) {
89
101
  }
90
102
 
91
- const FunctionData *bind_data;
103
+ optional_ptr<const FunctionData> bind_data;
92
104
  const vector<column_t> &column_ids;
93
105
  const vector<idx_t> projection_ids;
94
- TableFilterSet *filters;
106
+ optional_ptr<TableFilterSet> filters;
95
107
 
96
108
  bool CanRemoveFilterColumns() const {
97
109
  if (projection_ids.empty()) {
@@ -109,15 +121,16 @@ struct TableFunctionInitInput {
109
121
 
110
122
  struct TableFunctionInput {
111
123
  public:
112
- TableFunctionInput(const FunctionData *bind_data_p, LocalTableFunctionState *local_state_p,
113
- GlobalTableFunctionState *global_state_p)
124
+ TableFunctionInput(optional_ptr<const FunctionData> bind_data_p,
125
+ optional_ptr<LocalTableFunctionState> local_state_p,
126
+ optional_ptr<GlobalTableFunctionState> global_state_p)
114
127
  : bind_data(bind_data_p), local_state(local_state_p), global_state(global_state_p) {
115
128
  }
116
129
 
117
130
  public:
118
- const FunctionData *bind_data;
119
- LocalTableFunctionState *local_state;
120
- GlobalTableFunctionState *global_state;
131
+ optional_ptr<const FunctionData> bind_data;
132
+ optional_ptr<LocalTableFunctionState> local_state;
133
+ optional_ptr<GlobalTableFunctionState> global_state;
121
134
  };
122
135
 
123
136
  enum ScanType { TABLE, PARQUET };
@@ -127,21 +140,21 @@ public:
127
140
  explicit BindInfo(ScanType type_p) : type(type_p) {};
128
141
  unordered_map<string, Value> options;
129
142
  ScanType type;
130
- void InsertOption(string name, Value value) {
143
+ void InsertOption(const string &name, Value value) {
131
144
  if (options.find(name) != options.end()) {
132
145
  throw InternalException("This option already exists");
133
146
  }
134
- options[name] = value;
147
+ options[name] = std::move(value);
135
148
  }
136
149
  template <class T>
137
- T GetOption(string name) {
150
+ T GetOption(const string &name) {
138
151
  if (options.find(name) == options.end()) {
139
152
  throw InternalException("This option does not exist");
140
153
  }
141
154
  return options[name].GetValue<T>();
142
155
  }
143
156
  template <class T>
144
- vector<T> GetOptionList(string name) {
157
+ vector<T> GetOptionList(const string &name) {
145
158
  if (options.find(name) == options.end()) {
146
159
  throw InternalException("This option does not exist");
147
160
  }
@@ -44,6 +44,7 @@ public:
44
44
 
45
45
  void Initialize();
46
46
 
47
+ Catalog &ParentCatalog() override;
47
48
  StorageManager &GetStorageManager();
48
49
  Catalog &GetCatalog();
49
50
  TransactionManager &GetTransactionManager();
@@ -65,6 +66,7 @@ private:
65
66
  unique_ptr<Catalog> catalog;
66
67
  unique_ptr<TransactionManager> transaction_manager;
67
68
  AttachedDatabaseType type;
69
+ optional_ptr<Catalog> parent_catalog;
68
70
  };
69
71
 
70
72
  } // namespace duckdb
@@ -149,7 +149,7 @@ public:
149
149
  DUCKDB_API double GetProgress();
150
150
 
151
151
  //! Register function in the temporary schema
152
- DUCKDB_API void RegisterFunction(CreateFunctionInfo *info);
152
+ DUCKDB_API void RegisterFunction(CreateFunctionInfo &info);
153
153
 
154
154
  //! Parse statements from a query
155
155
  DUCKDB_API vector<unique_ptr<SQLStatement>> ParseStatements(const string &query);
@@ -13,6 +13,7 @@
13
13
  #include "duckdb/common/mutex.hpp"
14
14
  #include "duckdb/common/atomic.hpp"
15
15
  #include "duckdb/common/optional_ptr.hpp"
16
+ #include "duckdb/common/enums/on_entry_not_found.hpp"
16
17
 
17
18
  namespace duckdb {
18
19
  class AttachedDatabase;
@@ -39,13 +40,13 @@ public:
39
40
  optional_ptr<AttachedDatabase> GetDatabase(ClientContext &context, const string &name);
40
41
  //! Add a new attached database to the database manager
41
42
  void AddDatabase(ClientContext &context, unique_ptr<AttachedDatabase> db);
42
- void DetachDatabase(ClientContext &context, const string &name, bool if_exists);
43
+ void DetachDatabase(ClientContext &context, const string &name, OnEntryNotFound if_not_found);
43
44
  //! Returns a reference to the system catalog
44
45
  Catalog &GetSystemCatalog();
45
46
  static const string &GetDefaultDatabase(ClientContext &context);
46
47
 
47
48
  optional_ptr<AttachedDatabase> GetDatabaseFromPath(ClientContext &context, const string &path);
48
- vector<optional_ptr<AttachedDatabase>> GetDatabases(ClientContext &context);
49
+ vector<reference<AttachedDatabase>> GetDatabases(ClientContext &context);
49
50
 
50
51
  transaction_t GetNewQueryNumber() {
51
52
  return current_query_number++;
@@ -28,6 +28,8 @@ public:
28
28
  unique_ptr<Expression> expr;
29
29
 
30
30
  public:
31
+ static unique_ptr<Expression> &GetExpression(ParsedExpression &expr);
32
+
31
33
  string ToString() const override;
32
34
 
33
35
  bool Equals(const BaseExpression *other) const override;
@@ -18,10 +18,10 @@ public:
18
18
  static bool IsKeyword(const string &text);
19
19
 
20
20
  //! Returns true if the given string needs to be quoted when written as an identifier
21
- static bool RequiresQuotes(const string &text, bool allow_caps = false);
21
+ static bool RequiresQuotes(const string &text, bool allow_caps = true);
22
22
 
23
23
  //! Writes a string that is optionally quoted + escaped so it can be used as an identifier
24
- static string WriteOptionallyQuoted(const string &text, char quote = '"', bool allow_caps = false);
24
+ static string WriteOptionallyQuoted(const string &text, char quote = '"', bool allow_caps = true);
25
25
  };
26
26
 
27
27
  } // namespace duckdb
@@ -11,6 +11,7 @@
11
11
  #include "duckdb/common/enums/catalog_type.hpp"
12
12
  #include "duckdb/parser/column_definition.hpp"
13
13
  #include "duckdb/parser/parsed_data/parse_info.hpp"
14
+ #include "duckdb/common/enums/on_entry_not_found.hpp"
14
15
 
15
16
  namespace duckdb {
16
17
 
@@ -27,23 +28,24 @@ enum class AlterType : uint8_t {
27
28
  struct AlterEntryData {
28
29
  AlterEntryData() {
29
30
  }
30
- AlterEntryData(string catalog_p, string schema_p, string name_p, bool if_exists)
31
- : catalog(std::move(catalog_p)), schema(std::move(schema_p)), name(std::move(name_p)), if_exists(if_exists) {
31
+ AlterEntryData(string catalog_p, string schema_p, string name_p, OnEntryNotFound if_not_found)
32
+ : catalog(std::move(catalog_p)), schema(std::move(schema_p)), name(std::move(name_p)),
33
+ if_not_found(if_not_found) {
32
34
  }
33
35
 
34
36
  string catalog;
35
37
  string schema;
36
38
  string name;
37
- bool if_exists;
39
+ OnEntryNotFound if_not_found;
38
40
  };
39
41
 
40
42
  struct AlterInfo : public ParseInfo {
41
- AlterInfo(AlterType type, string catalog, string schema, string name, bool if_exists);
43
+ AlterInfo(AlterType type, string catalog, string schema, string name, OnEntryNotFound if_not_found);
42
44
  virtual ~AlterInfo() override;
43
45
 
44
46
  AlterType type;
45
47
  //! if exists
46
- bool if_exists;
48
+ OnEntryNotFound if_not_found;
47
49
  //! Catalog name to alter
48
50
  string catalog;
49
51
  //! Schema name to alter
@@ -22,7 +22,7 @@ enum AlterForeignKeyType : uint8_t { AFT_ADD = 0, AFT_DELETE = 1 };
22
22
  //===--------------------------------------------------------------------===//
23
23
  struct ChangeOwnershipInfo : public AlterInfo {
24
24
  ChangeOwnershipInfo(CatalogType entry_catalog_type, string entry_catalog, string entry_schema, string entry_name,
25
- string owner_schema, string owner_name, bool if_exists);
25
+ string owner_schema, string owner_name, OnEntryNotFound if_not_found);
26
26
 
27
27
  // Catalog type refers to the entry type, since this struct is usually built from an
28
28
  // ALTER <TYPE> <schema>.<name> OWNED BY <owner_schema>.<owner_name> statement
@@ -22,7 +22,7 @@ class SchemaCatalogEntry;
22
22
  struct CreateTableInfo : public CreateInfo {
23
23
  DUCKDB_API CreateTableInfo();
24
24
  DUCKDB_API CreateTableInfo(string catalog, string schema, string name);
25
- DUCKDB_API CreateTableInfo(SchemaCatalogEntry *schema, string name);
25
+ DUCKDB_API CreateTableInfo(SchemaCatalogEntry &schema, string name);
26
26
 
27
27
  //! Table name to insert to
28
28
  string table;
@@ -16,7 +16,7 @@ class SchemaCatalogEntry;
16
16
 
17
17
  struct CreateViewInfo : public CreateInfo {
18
18
  CreateViewInfo();
19
- CreateViewInfo(SchemaCatalogEntry *schema, string view_name);
19
+ CreateViewInfo(SchemaCatalogEntry &schema, string view_name);
20
20
  CreateViewInfo(string catalog_p, string schema_p, string view_name);
21
21
 
22
22
  //! Table name to insert to
@@ -9,6 +9,7 @@
9
9
  #pragma once
10
10
 
11
11
  #include "duckdb/parser/parsed_data/parse_info.hpp"
12
+ #include "duckdb/common/enums/on_entry_not_found.hpp"
12
13
 
13
14
  namespace duckdb {
14
15
 
@@ -19,13 +20,13 @@ struct DetachInfo : public ParseInfo {
19
20
  //! The alias of the attached database
20
21
  string name;
21
22
  //! Whether to throw an exception if alias is not found
22
- bool if_exists;
23
+ OnEntryNotFound if_not_found;
23
24
 
24
25
  public:
25
26
  unique_ptr<DetachInfo> Copy() const {
26
27
  auto result = make_uniq<DetachInfo>();
27
28
  result->name = name;
28
- result->if_exists = if_exists;
29
+ result->if_not_found = if_not_found;
29
30
  return result;
30
31
  }
31
32
  };
@@ -15,7 +15,7 @@
15
15
  namespace duckdb {
16
16
 
17
17
  struct DropInfo : public ParseInfo {
18
- DropInfo() : catalog(INVALID_CATALOG), schema(INVALID_SCHEMA), if_exists(false), cascade(false) {
18
+ DropInfo() : catalog(INVALID_CATALOG), schema(INVALID_SCHEMA), cascade(false) {
19
19
  }
20
20
 
21
21
  //! The catalog type to drop
@@ -27,7 +27,7 @@ struct DropInfo : public ParseInfo {
27
27
  //! Element name to drop
28
28
  string name;
29
29
  //! Ignore if the entry does not exist instead of failing
30
- bool if_exists = false;
30
+ OnEntryNotFound if_not_found = OnEntryNotFound::THROW_EXCEPTION;
31
31
  //! Cascade drop (drop all dependents instead of throwing an error if there
32
32
  //! are any)
33
33
  bool cascade = false;
@@ -41,7 +41,7 @@ public:
41
41
  result->catalog = catalog;
42
42
  result->schema = schema;
43
43
  result->name = name;
44
- result->if_exists = if_exists;
44
+ result->if_not_found = if_not_found;
45
45
  result->cascade = cascade;
46
46
  result->allow_drop_internal = allow_drop_internal;
47
47
  return result;
@@ -53,7 +53,7 @@ public:
53
53
  writer.WriteString(catalog);
54
54
  writer.WriteString(schema);
55
55
  writer.WriteString(name);
56
- writer.WriteField(if_exists);
56
+ writer.WriteField(if_not_found);
57
57
  writer.WriteField(cascade);
58
58
  writer.WriteField(allow_drop_internal);
59
59
  writer.Finalize();
@@ -66,7 +66,7 @@ public:
66
66
  drop_info->catalog = reader.ReadRequired<string>();
67
67
  drop_info->schema = reader.ReadRequired<string>();
68
68
  drop_info->name = reader.ReadRequired<string>();
69
- drop_info->if_exists = reader.ReadRequired<bool>();
69
+ drop_info->if_not_found = reader.ReadRequired<OnEntryNotFound>();
70
70
  drop_info->cascade = reader.ReadRequired<bool>();
71
71
  drop_info->allow_drop_internal = reader.ReadRequired<bool>();
72
72
  reader.Finalize();
@@ -15,6 +15,19 @@ namespace duckdb {
15
15
  struct ParseInfo {
16
16
  virtual ~ParseInfo() {
17
17
  }
18
+
19
+ public:
20
+ template <class TARGET>
21
+ TARGET &Cast() {
22
+ D_ASSERT(dynamic_cast<TARGET *>(this));
23
+ return (TARGET &)*this;
24
+ }
25
+
26
+ template <class TARGET>
27
+ const TARGET &Cast() const {
28
+ D_ASSERT(dynamic_cast<const TARGET *>(this));
29
+ return (const TARGET &)*this;
30
+ }
18
31
  };
19
32
 
20
33
  } // namespace duckdb
@@ -18,6 +18,9 @@ class Serializer;
18
18
 
19
19
  //! Represents a generic expression that returns a table.
20
20
  class TableRef {
21
+ public:
22
+ static constexpr const TableReferenceType TYPE = TableReferenceType::INVALID;
23
+
21
24
  public:
22
25
  explicit TableRef(TableReferenceType type) : type(type) {
23
26
  }
@@ -57,7 +60,7 @@ public:
57
60
  public:
58
61
  template <class TARGET>
59
62
  TARGET &Cast() {
60
- if (type != TARGET::TYPE) {
63
+ if (type != TARGET::TYPE && TARGET::TYPE != TableReferenceType::INVALID) {
61
64
  throw InternalException("Failed to cast constraint to type - constraint type mismatch");
62
65
  }
63
66
  return (TARGET &)*this;
@@ -65,7 +68,7 @@ public:
65
68
 
66
69
  template <class TARGET>
67
70
  const TARGET &Cast() const {
68
- if (type != TARGET::TYPE) {
71
+ if (type != TARGET::TYPE && TARGET::TYPE != TableReferenceType::INVALID) {
69
72
  throw InternalException("Failed to cast constraint to type - constraint type mismatch");
70
73
  }
71
74
  return (const TARGET &)*this;
@@ -320,6 +320,8 @@ private:
320
320
  //! Returns true if an expression is only a star (i.e. "*", without any other decorators)
321
321
  bool ExpressionIsEmptyStar(ParsedExpression &expr);
322
322
 
323
+ OnEntryNotFound TransformOnEntryNotFound(bool missing_ok);
324
+
323
325
  private:
324
326
  //! Current stack depth
325
327
  idx_t stack_depth;
@@ -172,7 +172,7 @@ public:
172
172
  void BindOnConflictClause(LogicalInsert &insert, TableCatalogEntry &table, InsertStatement &stmt);
173
173
 
174
174
  static void BindSchemaOrCatalog(ClientContext &context, string &catalog, string &schema);
175
- static void BindLogicalType(ClientContext &context, LogicalType &type, Catalog *catalog = nullptr,
175
+ static void BindLogicalType(ClientContext &context, LogicalType &type, optional_ptr<Catalog> catalog = nullptr,
176
176
  const string &schema = INVALID_SCHEMA);
177
177
 
178
178
  bool HasMatchingBinding(const string &table_name, const string &column_name, string &error_message);
@@ -259,7 +259,7 @@ private:
259
259
  const string &alias, idx_t update_table_index,
260
260
  unique_ptr<LogicalOperator> child_operator, BoundStatement result);
261
261
 
262
- unique_ptr<QueryNode> BindTableMacro(FunctionExpression &function, TableMacroCatalogEntry *macro_func, idx_t depth);
262
+ unique_ptr<QueryNode> BindTableMacro(FunctionExpression &function, TableMacroCatalogEntry &macro_func, idx_t depth);
263
263
 
264
264
  unique_ptr<BoundQueryNode> BindNode(SelectNode &node);
265
265
  unique_ptr<BoundQueryNode> BindNode(SetOperationNode &node);
@@ -43,8 +43,7 @@ protected:
43
43
  BindResult BindExpression(unique_ptr<ParsedExpression> &expr_ptr, idx_t depth,
44
44
  bool root_expression = false) override;
45
45
 
46
- BindResult BindAggregate(FunctionExpression &expr, optional_ptr<AggregateFunctionCatalogEntry> function,
47
- idx_t depth) override;
46
+ BindResult BindAggregate(FunctionExpression &expr, AggregateFunctionCatalogEntry &function, idx_t depth) override;
48
47
 
49
48
  bool inside_window;
50
49
  bool bound_aggregate = false;
@@ -134,14 +134,11 @@ protected:
134
134
 
135
135
  protected:
136
136
  virtual BindResult BindGroupingFunction(OperatorExpression &op, idx_t depth);
137
- virtual BindResult BindFunction(FunctionExpression &expr, optional_ptr<ScalarFunctionCatalogEntry> function,
138
- idx_t depth);
139
- virtual BindResult BindLambdaFunction(FunctionExpression &expr, optional_ptr<ScalarFunctionCatalogEntry> function,
140
- idx_t depth);
141
- virtual BindResult BindAggregate(FunctionExpression &expr, optional_ptr<AggregateFunctionCatalogEntry> function,
142
- idx_t depth);
137
+ virtual BindResult BindFunction(FunctionExpression &expr, ScalarFunctionCatalogEntry &function, idx_t depth);
138
+ virtual BindResult BindLambdaFunction(FunctionExpression &expr, ScalarFunctionCatalogEntry &function, idx_t depth);
139
+ virtual BindResult BindAggregate(FunctionExpression &expr, AggregateFunctionCatalogEntry &function, idx_t depth);
143
140
  virtual BindResult BindUnnest(FunctionExpression &expr, idx_t depth, bool root_expression);
144
- virtual BindResult BindMacro(FunctionExpression &expr, optional_ptr<ScalarMacroCatalogEntry> macro, idx_t depth,
141
+ virtual BindResult BindMacro(FunctionExpression &expr, ScalarMacroCatalogEntry &macro, idx_t depth,
145
142
  unique_ptr<ParsedExpression> &expr_ptr);
146
143
 
147
144
  virtual string UnsupportedAggregateMessage();
@@ -53,7 +53,7 @@ public:
53
53
  string GetName() const override;
54
54
  string ParamsToString() const override;
55
55
  //! Returns the underlying table that is being scanned, or nullptr if there is none
56
- TableCatalogEntry *GetTable() const;
56
+ optional_ptr<TableCatalogEntry> GetTable() const;
57
57
 
58
58
  public:
59
59
  vector<ColumnBinding> GetColumnBindings() override;
@@ -57,6 +57,18 @@ public:
57
57
  virtual bool IsDuckTransaction() const {
58
58
  return false;
59
59
  }
60
+
61
+ public:
62
+ template <class TARGET>
63
+ TARGET &Cast() {
64
+ D_ASSERT(dynamic_cast<TARGET *>(this));
65
+ return (TARGET &)*this;
66
+ }
67
+ template <class TARGET>
68
+ const TARGET &Cast() const {
69
+ D_ASSERT(dynamic_cast<const TARGET *>(this));
70
+ return (const TARGET &)*this;
71
+ }
60
72
  };
61
73
 
62
74
  } // namespace duckdb
@@ -8,8 +8,8 @@
8
8
  namespace duckdb {
9
9
 
10
10
  AttachedDatabase::AttachedDatabase(DatabaseInstance &db, AttachedDatabaseType type)
11
- : CatalogEntry(CatalogType::DATABASE_ENTRY, nullptr,
12
- type == AttachedDatabaseType::SYSTEM_DATABASE ? SYSTEM_CATALOG : TEMP_CATALOG),
11
+ : CatalogEntry(CatalogType::DATABASE_ENTRY,
12
+ type == AttachedDatabaseType::SYSTEM_DATABASE ? SYSTEM_CATALOG : TEMP_CATALOG, 0),
13
13
  db(db), type(type) {
14
14
  D_ASSERT(type == AttachedDatabaseType::TEMP_DATABASE || type == AttachedDatabaseType::SYSTEM_DATABASE);
15
15
  if (type == AttachedDatabaseType::TEMP_DATABASE) {
@@ -22,9 +22,10 @@ AttachedDatabase::AttachedDatabase(DatabaseInstance &db, AttachedDatabaseType ty
22
22
 
23
23
  AttachedDatabase::AttachedDatabase(DatabaseInstance &db, Catalog &catalog_p, string name_p, string file_path_p,
24
24
  AccessMode access_mode)
25
- : CatalogEntry(CatalogType::DATABASE_ENTRY, &catalog_p, std::move(name_p)), db(db),
25
+ : CatalogEntry(CatalogType::DATABASE_ENTRY, catalog_p, std::move(name_p)), db(db),
26
26
  type(access_mode == AccessMode::READ_ONLY ? AttachedDatabaseType::READ_ONLY_DATABASE
27
- : AttachedDatabaseType::READ_WRITE_DATABASE) {
27
+ : AttachedDatabaseType::READ_WRITE_DATABASE),
28
+ parent_catalog(&catalog_p) {
28
29
  storage = make_uniq<SingleFileStorageManager>(*this, std::move(file_path_p), access_mode == AccessMode::READ_ONLY);
29
30
  catalog = make_uniq<DuckCatalog>(*this);
30
31
  transaction_manager = make_uniq<DuckTransactionManager>(*this);
@@ -33,9 +34,10 @@ AttachedDatabase::AttachedDatabase(DatabaseInstance &db, Catalog &catalog_p, str
33
34
 
34
35
  AttachedDatabase::AttachedDatabase(DatabaseInstance &db, Catalog &catalog_p, StorageExtension &storage_extension,
35
36
  string name_p, AttachInfo &info, AccessMode access_mode)
36
- : CatalogEntry(CatalogType::DATABASE_ENTRY, &catalog_p, std::move(name_p)), db(db),
37
+ : CatalogEntry(CatalogType::DATABASE_ENTRY, catalog_p, std::move(name_p)), db(db),
37
38
  type(access_mode == AccessMode::READ_ONLY ? AttachedDatabaseType::READ_ONLY_DATABASE
38
- : AttachedDatabaseType::READ_WRITE_DATABASE) {
39
+ : AttachedDatabaseType::READ_WRITE_DATABASE),
40
+ parent_catalog(&catalog_p) {
39
41
  catalog = storage_extension.attach(storage_extension.storage_info.get(), *this, name, info, access_mode);
40
42
  if (!catalog) {
41
43
  throw InternalException("AttachedDatabase - attach function did not return a catalog");
@@ -116,4 +118,8 @@ TransactionManager &AttachedDatabase::GetTransactionManager() {
116
118
  return *transaction_manager;
117
119
  }
118
120
 
121
+ Catalog &AttachedDatabase::ParentCatalog() {
122
+ return *parent_catalog;
123
+ }
124
+
119
125
  } // namespace duckdb