duckdb 0.7.2-dev2507.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 (200) 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 +5 -5
  71. package/src/duckdb/src/function/table/system/duckdb_columns.cpp +8 -7
  72. package/src/duckdb/src/function/table/system/duckdb_constraints.cpp +14 -14
  73. package/src/duckdb/src/function/table/system/duckdb_databases.cpp +2 -2
  74. package/src/duckdb/src/function/table/system/duckdb_functions.cpp +26 -25
  75. package/src/duckdb/src/function/table/system/duckdb_indexes.cpp +13 -12
  76. package/src/duckdb/src/function/table/system/duckdb_schemas.cpp +7 -7
  77. package/src/duckdb/src/function/table/system/duckdb_sequences.cpp +8 -9
  78. package/src/duckdb/src/function/table/system/duckdb_tables.cpp +10 -9
  79. package/src/duckdb/src/function/table/system/duckdb_types.cpp +13 -13
  80. package/src/duckdb/src/function/table/system/duckdb_views.cpp +11 -10
  81. package/src/duckdb/src/function/table/system/pragma_collations.cpp +2 -2
  82. package/src/duckdb/src/function/table/system/pragma_database_size.cpp +5 -5
  83. package/src/duckdb/src/function/table/system/pragma_storage_info.cpp +3 -3
  84. package/src/duckdb/src/function/table/system/pragma_table_info.cpp +2 -2
  85. package/src/duckdb/src/function/table/table_scan.cpp +39 -37
  86. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  87. package/src/duckdb/src/function/udf_function.cpp +2 -2
  88. package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +122 -81
  89. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/aggregate_function_catalog_entry.hpp +2 -3
  90. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/collate_catalog_entry.hpp +3 -3
  91. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/copy_function_catalog_entry.hpp +1 -1
  92. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_index_entry.hpp +1 -1
  93. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_schema_entry.hpp +24 -20
  94. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_table_entry.hpp +3 -3
  95. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/index_catalog_entry.hpp +1 -1
  96. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/macro_catalog_entry.hpp +2 -2
  97. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/pragma_function_catalog_entry.hpp +1 -1
  98. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/scalar_function_catalog_entry.hpp +2 -2
  99. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/scalar_macro_catalog_entry.hpp +1 -1
  100. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/schema_catalog_entry.hpp +22 -17
  101. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/sequence_catalog_entry.hpp +1 -1
  102. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_catalog_entry.hpp +1 -1
  103. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_function_catalog_entry.hpp +2 -2
  104. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_macro_catalog_entry.hpp +1 -1
  105. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/type_catalog_entry.hpp +1 -1
  106. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/view_catalog_entry.hpp +3 -3
  107. package/src/duckdb/src/include/duckdb/catalog/catalog_entry.hpp +28 -7
  108. package/src/duckdb/src/include/duckdb/catalog/catalog_set.hpp +20 -19
  109. package/src/duckdb/src/include/duckdb/catalog/duck_catalog.hpp +9 -9
  110. package/src/duckdb/src/include/duckdb/catalog/similar_catalog_entry.hpp +2 -1
  111. package/src/duckdb/src/include/duckdb/catalog/standard_entry.hpp +10 -4
  112. package/src/duckdb/src/include/duckdb/common/enums/on_entry_not_found.hpp +17 -0
  113. package/src/duckdb/src/include/duckdb/common/types.hpp +3 -4
  114. package/src/duckdb/src/include/duckdb/function/function_serialization.hpp +4 -4
  115. package/src/duckdb/src/include/duckdb/function/scalar_function.hpp +3 -2
  116. package/src/duckdb/src/include/duckdb/function/table/table_scan.hpp +5 -4
  117. package/src/duckdb/src/include/duckdb/function/table_function.hpp +28 -15
  118. package/src/duckdb/src/include/duckdb/main/attached_database.hpp +2 -0
  119. package/src/duckdb/src/include/duckdb/main/client_context.hpp +1 -1
  120. package/src/duckdb/src/include/duckdb/main/database_manager.hpp +3 -2
  121. package/src/duckdb/src/include/duckdb/parser/expression/bound_expression.hpp +2 -0
  122. package/src/duckdb/src/include/duckdb/parser/keyword_helper.hpp +2 -2
  123. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_info.hpp +7 -5
  124. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_table_info.hpp +1 -1
  125. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_table_info.hpp +1 -1
  126. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_view_info.hpp +1 -1
  127. package/src/duckdb/src/include/duckdb/parser/parsed_data/detach_info.hpp +3 -2
  128. package/src/duckdb/src/include/duckdb/parser/parsed_data/drop_info.hpp +5 -5
  129. package/src/duckdb/src/include/duckdb/parser/parsed_data/parse_info.hpp +13 -0
  130. package/src/duckdb/src/include/duckdb/parser/tableref.hpp +5 -2
  131. package/src/duckdb/src/include/duckdb/parser/transformer.hpp +2 -0
  132. package/src/duckdb/src/include/duckdb/planner/binder.hpp +2 -2
  133. package/src/duckdb/src/include/duckdb/planner/expression_binder/base_select_binder.hpp +1 -2
  134. package/src/duckdb/src/include/duckdb/planner/expression_binder.hpp +4 -7
  135. package/src/duckdb/src/include/duckdb/planner/operator/logical_get.hpp +1 -1
  136. package/src/duckdb/src/include/duckdb/transaction/transaction.hpp +12 -0
  137. package/src/duckdb/src/main/attached_database.cpp +12 -6
  138. package/src/duckdb/src/main/capi/table_function-c.cpp +17 -16
  139. package/src/duckdb/src/main/client_context.cpp +12 -11
  140. package/src/duckdb/src/main/database_manager.cpp +13 -12
  141. package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +1 -2
  142. package/src/duckdb/src/parser/parsed_data/alter_info.cpp +3 -3
  143. package/src/duckdb/src/parser/parsed_data/alter_scalar_function_info.cpp +2 -2
  144. package/src/duckdb/src/parser/parsed_data/alter_table_function_info.cpp +2 -2
  145. package/src/duckdb/src/parser/parsed_data/alter_table_info.cpp +9 -9
  146. package/src/duckdb/src/parser/parsed_data/create_scalar_function_info.cpp +2 -2
  147. package/src/duckdb/src/parser/parsed_data/create_table_function_info.cpp +2 -2
  148. package/src/duckdb/src/parser/parsed_data/create_table_info.cpp +2 -2
  149. package/src/duckdb/src/parser/parsed_data/create_view_info.cpp +2 -2
  150. package/src/duckdb/src/parser/transform/statement/transform_alter_sequence.cpp +3 -2
  151. package/src/duckdb/src/parser/transform/statement/transform_alter_table.cpp +5 -1
  152. package/src/duckdb/src/parser/transform/statement/transform_detach.cpp +1 -1
  153. package/src/duckdb/src/parser/transform/statement/transform_drop.cpp +1 -1
  154. package/src/duckdb/src/parser/transform/statement/transform_rename.cpp +1 -1
  155. package/src/duckdb/src/planner/binder/expression/bind_aggregate_expression.cpp +26 -27
  156. package/src/duckdb/src/planner/binder/expression/bind_between_expression.cpp +17 -17
  157. package/src/duckdb/src/planner/binder/expression/bind_case_expression.cpp +9 -9
  158. package/src/duckdb/src/planner/binder/expression/bind_cast_expression.cpp +6 -6
  159. package/src/duckdb/src/planner/binder/expression/bind_collate_expression.cpp +6 -6
  160. package/src/duckdb/src/planner/binder/expression/bind_columnref_expression.cpp +2 -2
  161. package/src/duckdb/src/planner/binder/expression/bind_comparison_expression.cpp +21 -21
  162. package/src/duckdb/src/planner/binder/expression/bind_conjunction_expression.cpp +2 -3
  163. package/src/duckdb/src/planner/binder/expression/bind_function_expression.cpp +33 -36
  164. package/src/duckdb/src/planner/binder/expression/bind_macro_expression.cpp +5 -5
  165. package/src/duckdb/src/planner/binder/expression/bind_operator_expression.cpp +23 -23
  166. package/src/duckdb/src/planner/binder/expression/bind_subquery_expression.cpp +4 -4
  167. package/src/duckdb/src/planner/binder/expression/bind_unnest_expression.cpp +7 -7
  168. package/src/duckdb/src/planner/binder/expression/bind_window_expression.cpp +23 -23
  169. package/src/duckdb/src/planner/binder/query_node/bind_table_macro_node.cpp +4 -4
  170. package/src/duckdb/src/planner/binder/statement/bind_copy.cpp +14 -13
  171. package/src/duckdb/src/planner/binder/statement/bind_create.cpp +36 -35
  172. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +3 -3
  173. package/src/duckdb/src/planner/binder/statement/bind_delete.cpp +1 -1
  174. package/src/duckdb/src/planner/binder/statement/bind_drop.cpp +4 -4
  175. package/src/duckdb/src/planner/binder/statement/bind_export.cpp +10 -10
  176. package/src/duckdb/src/planner/binder/statement/bind_insert.cpp +2 -2
  177. package/src/duckdb/src/planner/binder/statement/bind_pragma.cpp +4 -4
  178. package/src/duckdb/src/planner/binder/statement/bind_simple.cpp +5 -4
  179. package/src/duckdb/src/planner/binder/statement/bind_update.cpp +1 -1
  180. package/src/duckdb/src/planner/binder/tableref/bind_basetableref.cpp +3 -3
  181. package/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp +10 -12
  182. package/src/duckdb/src/planner/binder.cpp +2 -2
  183. package/src/duckdb/src/planner/expression/bound_expression.cpp +11 -2
  184. package/src/duckdb/src/planner/operator/logical_copy_to_file.cpp +2 -5
  185. package/src/duckdb/src/planner/operator/logical_create.cpp +2 -1
  186. package/src/duckdb/src/planner/operator/logical_create_index.cpp +2 -2
  187. package/src/duckdb/src/planner/operator/logical_delete.cpp +2 -2
  188. package/src/duckdb/src/planner/operator/logical_get.cpp +1 -1
  189. package/src/duckdb/src/planner/operator/logical_insert.cpp +2 -7
  190. package/src/duckdb/src/planner/operator/logical_update.cpp +2 -6
  191. package/src/duckdb/src/planner/parsed_data/bound_create_table_info.cpp +2 -2
  192. package/src/duckdb/src/planner/pragma_handler.cpp +3 -4
  193. package/src/duckdb/src/storage/checkpoint_manager.cpp +46 -46
  194. package/src/duckdb/src/storage/data_table.cpp +3 -6
  195. package/src/duckdb/src/storage/table/update_segment.cpp +1 -1
  196. package/src/duckdb/src/storage/wal_replay.cpp +28 -30
  197. package/src/duckdb/src/storage/write_ahead_log.cpp +8 -8
  198. package/src/duckdb/src/transaction/cleanup_state.cpp +1 -1
  199. package/src/duckdb/src/transaction/commit_state.cpp +3 -4
  200. package/src/duckdb/src/transaction/transaction_context.cpp +1 -1
@@ -15,7 +15,7 @@ struct PragmaDatabaseSizeData : public GlobalTableFunctionState {
15
15
  }
16
16
 
17
17
  idx_t index;
18
- vector<optional_ptr<AttachedDatabase>> databases;
18
+ vector<reference<AttachedDatabase>> databases;
19
19
  Value memory_usage;
20
20
  Value memory_limit;
21
21
  };
@@ -68,13 +68,13 @@ void PragmaDatabaseSizeFunction(ClientContext &context, TableFunctionInput &data
68
68
  auto &data = data_p.global_state->Cast<PragmaDatabaseSizeData>();
69
69
  idx_t row = 0;
70
70
  for (; data.index < data.databases.size() && row < STANDARD_VECTOR_SIZE; data.index++) {
71
- auto db = data.databases[data.index];
72
- if (db->IsSystem() || db->IsTemporary()) {
71
+ auto &db = data.databases[data.index].get();
72
+ if (db.IsSystem() || db.IsTemporary()) {
73
73
  continue;
74
74
  }
75
- auto ds = db->GetCatalog().GetDatabaseSize(context);
75
+ auto ds = db.GetCatalog().GetDatabaseSize(context);
76
76
  idx_t col = 0;
77
- output.data[col++].SetValue(row, Value(db->GetName()));
77
+ output.data[col++].SetValue(row, Value(db.GetName()));
78
78
  output.data[col++].SetValue(row, Value(StringUtil::BytesToHumanReadableString(ds.bytes)));
79
79
  output.data[col++].SetValue(row, Value::BIGINT(ds.block_size));
80
80
  output.data[col++].SetValue(row, Value::BIGINT(ds.total_blocks));
@@ -80,9 +80,9 @@ static unique_ptr<FunctionData> PragmaStorageInfoBind(ClientContext &context, Ta
80
80
 
81
81
  // look up the table name in the catalog
82
82
  Binder::BindSchemaOrCatalog(context, qname.catalog, qname.schema);
83
- auto table_entry = Catalog::GetEntry<TableCatalogEntry>(context, qname.catalog, qname.schema, qname.name);
84
- auto result = make_uniq<PragmaStorageFunctionData>(*table_entry);
85
- result->storage_info = table_entry->GetStorageInfo(context);
83
+ auto &table_entry = Catalog::GetEntry<TableCatalogEntry>(context, qname.catalog, qname.schema, qname.name);
84
+ auto result = make_uniq<PragmaStorageFunctionData>(table_entry);
85
+ result->storage_info = table_entry.GetStorageInfo(context);
86
86
  return std::move(result);
87
87
  }
88
88
 
@@ -54,8 +54,8 @@ static unique_ptr<FunctionData> PragmaTableInfoBind(ClientContext &context, Tabl
54
54
 
55
55
  // look up the table name in the catalog
56
56
  Binder::BindSchemaOrCatalog(context, qname.catalog, qname.schema);
57
- auto entry = Catalog::GetEntry(context, CatalogType::TABLE_ENTRY, qname.catalog, qname.schema, qname.name);
58
- return make_uniq<PragmaTableFunctionData>(*entry);
57
+ auto &entry = Catalog::GetEntry(context, CatalogType::TABLE_ENTRY, qname.catalog, qname.schema, qname.name);
58
+ return make_uniq<PragmaTableFunctionData>(entry);
59
59
  }
60
60
 
61
61
  unique_ptr<GlobalTableFunctionState> PragmaTableInfoInit(ClientContext &context, TableFunctionInitInput &input) {
@@ -43,7 +43,7 @@ struct TableScanGlobalState : public GlobalTableFunctionState {
43
43
  TableScanGlobalState(ClientContext &context, const FunctionData *bind_data_p) {
44
44
  D_ASSERT(bind_data_p);
45
45
  auto &bind_data = bind_data_p->Cast<TableScanBindData>();
46
- max_threads = bind_data.table->GetStorage().MaxThreads(context);
46
+ max_threads = bind_data.table.GetStorage().MaxThreads(context);
47
47
  }
48
48
 
49
49
  ParallelTableScanState state;
@@ -67,11 +67,11 @@ static unique_ptr<LocalTableFunctionState> TableScanInitLocal(ExecutionContext &
67
67
  auto &bind_data = input.bind_data->Cast<TableScanBindData>();
68
68
  vector<column_t> column_ids = input.column_ids;
69
69
  for (auto &col : column_ids) {
70
- auto storage_idx = GetStorageIndex(*bind_data.table, col);
70
+ auto storage_idx = GetStorageIndex(bind_data.table, col);
71
71
  col = storage_idx;
72
72
  }
73
- result->scan_state.Initialize(std::move(column_ids), input.filters);
74
- TableScanParallelStateNext(context.client, input.bind_data, result.get(), gstate);
73
+ result->scan_state.Initialize(std::move(column_ids), input.filters.get());
74
+ TableScanParallelStateNext(context.client, input.bind_data.get(), result.get(), gstate);
75
75
  if (input.CanRemoveFilterColumns()) {
76
76
  auto &tsgs = gstate->Cast<TableScanGlobalState>();
77
77
  result->all_columns.Initialize(context.client, tsgs.scanned_types);
@@ -83,11 +83,11 @@ unique_ptr<GlobalTableFunctionState> TableScanInitGlobal(ClientContext &context,
83
83
 
84
84
  D_ASSERT(input.bind_data);
85
85
  auto &bind_data = input.bind_data->Cast<TableScanBindData>();
86
- auto result = make_uniq<TableScanGlobalState>(context, input.bind_data);
87
- bind_data.table->GetStorage().InitializeParallelScan(context, result->state);
86
+ auto result = make_uniq<TableScanGlobalState>(context, input.bind_data.get());
87
+ bind_data.table.GetStorage().InitializeParallelScan(context, result->state);
88
88
  if (input.CanRemoveFilterColumns()) {
89
89
  result->projection_ids = input.projection_ids;
90
- const auto &columns = bind_data.table->GetColumns();
90
+ const auto &columns = bind_data.table.GetColumns();
91
91
  for (const auto &col_idx : input.column_ids) {
92
92
  if (col_idx == COLUMN_IDENTIFIER_ROW_ID) {
93
93
  result->scanned_types.emplace_back(LogicalType::ROW_TYPE);
@@ -102,20 +102,20 @@ unique_ptr<GlobalTableFunctionState> TableScanInitGlobal(ClientContext &context,
102
102
  static unique_ptr<BaseStatistics> TableScanStatistics(ClientContext &context, const FunctionData *bind_data_p,
103
103
  column_t column_id) {
104
104
  auto &bind_data = bind_data_p->Cast<TableScanBindData>();
105
- auto &local_storage = LocalStorage::Get(context, *bind_data.table->catalog);
106
- if (local_storage.Find(bind_data.table->GetStorage())) {
105
+ auto &local_storage = LocalStorage::Get(context, bind_data.table.catalog);
106
+ if (local_storage.Find(bind_data.table.GetStorage())) {
107
107
  // we don't emit any statistics for tables that have outstanding transaction-local data
108
108
  return nullptr;
109
109
  }
110
- return bind_data.table->GetStatistics(context, column_id);
110
+ return bind_data.table.GetStatistics(context, column_id);
111
111
  }
112
112
 
113
113
  static void TableScanFunc(ClientContext &context, TableFunctionInput &data_p, DataChunk &output) {
114
114
  auto &bind_data = data_p.bind_data->Cast<TableScanBindData>();
115
115
  auto &gstate = data_p.global_state->Cast<TableScanGlobalState>();
116
116
  auto &state = data_p.local_state->Cast<TableScanLocalState>();
117
- auto &transaction = DuckTransaction::Get(context, *bind_data.table->catalog);
118
- auto &storage = bind_data.table->GetStorage();
117
+ auto &transaction = DuckTransaction::Get(context, bind_data.table.catalog);
118
+ auto &storage = bind_data.table.GetStorage();
119
119
  do {
120
120
  if (bind_data.is_create_index) {
121
121
  storage.CreateIndexScan(state.scan_state, output,
@@ -130,7 +130,8 @@ static void TableScanFunc(ClientContext &context, TableFunctionInput &data_p, Da
130
130
  if (output.size() > 0) {
131
131
  return;
132
132
  }
133
- if (!TableScanParallelStateNext(context, data_p.bind_data, data_p.local_state, data_p.global_state)) {
133
+ if (!TableScanParallelStateNext(context, data_p.bind_data.get(), data_p.local_state.get(),
134
+ data_p.global_state.get())) {
134
135
  return;
135
136
  }
136
137
  } while (true);
@@ -141,7 +142,7 @@ bool TableScanParallelStateNext(ClientContext &context, const FunctionData *bind
141
142
  auto &bind_data = bind_data_p->Cast<TableScanBindData>();
142
143
  auto &parallel_state = global_state->Cast<TableScanGlobalState>();
143
144
  auto &state = local_state->Cast<TableScanLocalState>();
144
- auto &storage = bind_data.table->GetStorage();
145
+ auto &storage = bind_data.table.GetStorage();
145
146
 
146
147
  return storage.NextParallelScan(context, parallel_state.state, state.scan_state);
147
148
  }
@@ -150,7 +151,7 @@ double TableScanProgress(ClientContext &context, const FunctionData *bind_data_p
150
151
  const GlobalTableFunctionState *gstate_p) {
151
152
  auto &bind_data = bind_data_p->Cast<TableScanBindData>();
152
153
  auto &gstate = gstate_p->Cast<TableScanGlobalState>();
153
- auto &storage = bind_data.table->GetStorage();
154
+ auto &storage = bind_data.table.GetStorage();
154
155
  idx_t total_rows = storage.GetTotalRows();
155
156
  if (total_rows == 0) {
156
157
  //! Table is either empty or smaller than a vector size, so it is finished
@@ -185,14 +186,14 @@ BindInfo TableScanGetBindInfo(const FunctionData *bind_data) {
185
186
 
186
187
  void TableScanDependency(DependencyList &entries, const FunctionData *bind_data_p) {
187
188
  auto &bind_data = bind_data_p->Cast<TableScanBindData>();
188
- entries.AddDependency(*bind_data.table);
189
+ entries.AddDependency(bind_data.table);
189
190
  }
190
191
 
191
192
  unique_ptr<NodeStatistics> TableScanCardinality(ClientContext &context, const FunctionData *bind_data_p) {
192
193
  auto &bind_data = bind_data_p->Cast<TableScanBindData>();
193
- auto &local_storage = LocalStorage::Get(context, *bind_data.table->catalog);
194
- auto &storage = bind_data.table->GetStorage();
195
- idx_t estimated_cardinality = storage.info->cardinality + local_storage.AddedRows(bind_data.table->GetStorage());
194
+ auto &local_storage = LocalStorage::Get(context, bind_data.table.catalog);
195
+ auto &storage = bind_data.table.GetStorage();
196
+ idx_t estimated_cardinality = storage.info->cardinality + local_storage.AddedRows(bind_data.table.GetStorage());
196
197
  return make_uniq<NodeStatistics>(storage.info->cardinality, estimated_cardinality);
197
198
  }
198
199
 
@@ -217,10 +218,10 @@ static unique_ptr<GlobalTableFunctionState> IndexScanInitGlobal(ClientContext &c
217
218
  row_id_data = (data_ptr_t)&bind_data.result_ids[0];
218
219
  }
219
220
  auto result = make_uniq<IndexScanGlobalState>(row_id_data);
220
- auto &local_storage = LocalStorage::Get(context, *bind_data.table->catalog);
221
+ auto &local_storage = LocalStorage::Get(context, bind_data.table.catalog);
221
222
  result->column_ids = input.column_ids;
222
- result->local_storage_state.Initialize(input.column_ids, input.filters);
223
- local_storage.InitializeScan(bind_data.table->GetStorage(), result->local_storage_state.local_state, input.filters);
223
+ result->local_storage_state.Initialize(input.column_ids, input.filters.get());
224
+ local_storage.InitializeScan(bind_data.table.GetStorage(), result->local_storage_state.local_state, input.filters);
224
225
 
225
226
  result->finished = false;
226
227
  return std::move(result);
@@ -229,12 +230,12 @@ static unique_ptr<GlobalTableFunctionState> IndexScanInitGlobal(ClientContext &c
229
230
  static void IndexScanFunction(ClientContext &context, TableFunctionInput &data_p, DataChunk &output) {
230
231
  auto &bind_data = data_p.bind_data->Cast<TableScanBindData>();
231
232
  auto &state = data_p.global_state->Cast<IndexScanGlobalState>();
232
- auto &transaction = DuckTransaction::Get(context, *bind_data.table->catalog);
233
+ auto &transaction = DuckTransaction::Get(context, bind_data.table.catalog);
233
234
  auto &local_storage = LocalStorage::Get(transaction);
234
235
 
235
236
  if (!state.finished) {
236
- bind_data.table->GetStorage().Fetch(transaction, output, state.column_ids, state.row_ids,
237
- bind_data.result_ids.size(), state.fetch_state);
237
+ bind_data.table.GetStorage().Fetch(transaction, output, state.column_ids, state.row_ids,
238
+ bind_data.result_ids.size(), state.fetch_state);
238
239
  state.finished = true;
239
240
  }
240
241
  if (output.size() == 0) {
@@ -265,8 +266,8 @@ static void RewriteIndexExpression(Index &index, LogicalGet &get, Expression &ex
265
266
  void TableScanPushdownComplexFilter(ClientContext &context, LogicalGet &get, FunctionData *bind_data_p,
266
267
  vector<unique_ptr<Expression>> &filters) {
267
268
  auto &bind_data = bind_data_p->Cast<TableScanBindData>();
268
- auto table = bind_data.table;
269
- auto &storage = table->GetStorage();
269
+ auto &table = bind_data.table;
270
+ auto &storage = table.GetStorage();
270
271
 
271
272
  auto &config = ClientConfig::GetConfig(context);
272
273
  if (!config.enable_optimizer) {
@@ -365,7 +366,7 @@ void TableScanPushdownComplexFilter(ClientContext &context, LogicalGet &get, Fun
365
366
  }
366
367
  if (!equal_value.IsNull() || !low_value.IsNull() || !high_value.IsNull()) {
367
368
  // we can scan this index using this predicate: try a scan
368
- auto &transaction = Transaction::Get(context, *bind_data.table->catalog);
369
+ auto &transaction = Transaction::Get(context, bind_data.table.catalog);
369
370
  unique_ptr<IndexScanState> index_state;
370
371
  if (!equal_value.IsNull()) {
371
372
  // equality predicate
@@ -397,19 +398,19 @@ void TableScanPushdownComplexFilter(ClientContext &context, LogicalGet &get, Fun
397
398
 
398
399
  string TableScanToString(const FunctionData *bind_data_p) {
399
400
  auto &bind_data = bind_data_p->Cast<TableScanBindData>();
400
- string result = bind_data.table->name;
401
+ string result = bind_data.table.name;
401
402
  return result;
402
403
  }
403
404
 
404
405
  static void TableScanSerialize(FieldWriter &writer, const FunctionData *bind_data_p, const TableFunction &function) {
405
406
  auto &bind_data = bind_data_p->Cast<TableScanBindData>();
406
407
 
407
- writer.WriteString(bind_data.table->schema->name);
408
- writer.WriteString(bind_data.table->name);
408
+ writer.WriteString(bind_data.table.schema.name);
409
+ writer.WriteString(bind_data.table.name);
409
410
  writer.WriteField<bool>(bind_data.is_index_scan);
410
411
  writer.WriteField<bool>(bind_data.is_create_index);
411
412
  writer.WriteList<row_t>(bind_data.result_ids);
412
- writer.WriteString(bind_data.table->schema->catalog->GetName());
413
+ writer.WriteString(bind_data.table.schema.catalog.GetName());
413
414
  }
414
415
 
415
416
  static unique_ptr<FunctionData> TableScanDeserialize(ClientContext &context, FieldReader &reader,
@@ -421,12 +422,12 @@ static unique_ptr<FunctionData> TableScanDeserialize(ClientContext &context, Fie
421
422
  auto result_ids = reader.ReadRequiredList<row_t>();
422
423
  auto catalog_name = reader.ReadField<string>(INVALID_CATALOG);
423
424
 
424
- auto catalog_entry = Catalog::GetEntry<TableCatalogEntry>(context, catalog_name, schema_name, table_name);
425
- if (!catalog_entry || catalog_entry->type != CatalogType::TABLE_ENTRY) {
425
+ auto &catalog_entry = Catalog::GetEntry<TableCatalogEntry>(context, catalog_name, schema_name, table_name);
426
+ if (catalog_entry.type != CatalogType::TABLE_ENTRY) {
426
427
  throw SerializationException("Cant find table for %s.%s", schema_name, table_name);
427
428
  }
428
429
 
429
- auto result = make_uniq<TableScanBindData>((DuckTableEntry *)catalog_entry);
430
+ auto result = make_uniq<TableScanBindData>(catalog_entry.Cast<DuckTableEntry>());
430
431
  result->is_index_scan = is_index_scan;
431
432
  result->is_create_index = is_create_index;
432
433
  result->result_ids = std::move(result_ids);
@@ -471,12 +472,13 @@ TableFunction TableScanFunction::GetFunction() {
471
472
  return scan_function;
472
473
  }
473
474
 
474
- TableCatalogEntry *TableScanFunction::GetTableEntry(const TableFunction &function, const FunctionData *bind_data_p) {
475
+ optional_ptr<TableCatalogEntry> TableScanFunction::GetTableEntry(const TableFunction &function,
476
+ const optional_ptr<FunctionData> bind_data_p) {
475
477
  if (function.function != TableScanFunc || !bind_data_p) {
476
478
  return nullptr;
477
479
  }
478
480
  auto &bind_data = bind_data_p->Cast<TableScanBindData>();
479
- return bind_data.table;
481
+ return &bind_data.table;
480
482
  }
481
483
 
482
484
  void TableScanFunction::RegisterFunction(BuiltinFunctions &set) {
@@ -1,8 +1,8 @@
1
1
  #ifndef DUCKDB_VERSION
2
- #define DUCKDB_VERSION "0.7.2-dev2507"
2
+ #define DUCKDB_VERSION "0.7.2-dev2552"
3
3
  #endif
4
4
  #ifndef DUCKDB_SOURCE_ID
5
- #define DUCKDB_SOURCE_ID "c5737e4a94"
5
+ #define DUCKDB_SOURCE_ID "98590facb8"
6
6
  #endif
7
7
  #include "duckdb/function/table/system_functions.hpp"
8
8
  #include "duckdb/main/database.hpp"
@@ -15,13 +15,13 @@ void UDFWrapper::RegisterFunction(string name, vector<LogicalType> args, Logical
15
15
  scalar_function.null_handling = FunctionNullHandling::SPECIAL_HANDLING;
16
16
  CreateScalarFunctionInfo info(scalar_function);
17
17
  info.schema = DEFAULT_SCHEMA;
18
- context.RegisterFunction(&info);
18
+ context.RegisterFunction(info);
19
19
  }
20
20
 
21
21
  void UDFWrapper::RegisterAggrFunction(AggregateFunction aggr_function, ClientContext &context, LogicalType varargs) {
22
22
  aggr_function.varargs = std::move(varargs);
23
23
  CreateAggregateFunctionInfo info(std::move(aggr_function));
24
- context.RegisterFunction(&info);
24
+ context.RegisterFunction(info);
25
25
  }
26
26
 
27
27
  } // namespace duckdb
@@ -15,7 +15,7 @@
15
15
  #include "duckdb/common/reference_map.hpp"
16
16
  #include "duckdb/common/atomic.hpp"
17
17
  #include "duckdb/common/optional_ptr.hpp"
18
-
18
+ #include "duckdb/common/enums/on_entry_not_found.hpp"
19
19
  #include <functional>
20
20
 
21
21
  namespace duckdb {
@@ -110,100 +110,121 @@ public:
110
110
  DUCKDB_API CatalogTransaction GetCatalogTransaction(ClientContext &context);
111
111
 
112
112
  //! Creates a schema in the catalog.
113
- DUCKDB_API virtual CatalogEntry *CreateSchema(CatalogTransaction transaction, CreateSchemaInfo *info) = 0;
114
- DUCKDB_API CatalogEntry *CreateSchema(ClientContext &context, CreateSchemaInfo *info);
113
+ DUCKDB_API virtual optional_ptr<CatalogEntry> CreateSchema(CatalogTransaction transaction,
114
+ CreateSchemaInfo &info) = 0;
115
+ DUCKDB_API optional_ptr<CatalogEntry> CreateSchema(ClientContext &context, CreateSchemaInfo &info);
115
116
  //! Creates a table in the catalog.
116
- DUCKDB_API CatalogEntry *CreateTable(CatalogTransaction transaction, BoundCreateTableInfo *info);
117
- DUCKDB_API CatalogEntry *CreateTable(ClientContext &context, BoundCreateTableInfo *info);
117
+ DUCKDB_API optional_ptr<CatalogEntry> CreateTable(CatalogTransaction transaction, BoundCreateTableInfo &info);
118
+ DUCKDB_API optional_ptr<CatalogEntry> CreateTable(ClientContext &context, BoundCreateTableInfo &info);
118
119
  //! Creates a table in the catalog.
119
- DUCKDB_API CatalogEntry *CreateTable(ClientContext &context, unique_ptr<CreateTableInfo> info);
120
+ DUCKDB_API optional_ptr<CatalogEntry> CreateTable(ClientContext &context, unique_ptr<CreateTableInfo> info);
120
121
  //! Create a table function in the catalog
121
- DUCKDB_API CatalogEntry *CreateTableFunction(CatalogTransaction transaction, CreateTableFunctionInfo *info);
122
- DUCKDB_API CatalogEntry *CreateTableFunction(ClientContext &context, CreateTableFunctionInfo *info);
122
+ DUCKDB_API optional_ptr<CatalogEntry> CreateTableFunction(CatalogTransaction transaction,
123
+ CreateTableFunctionInfo &info);
124
+ DUCKDB_API optional_ptr<CatalogEntry> CreateTableFunction(ClientContext &context, CreateTableFunctionInfo &info);
125
+ // Kept for backwards compatibility
126
+ DUCKDB_API optional_ptr<CatalogEntry> CreateTableFunction(ClientContext &context,
127
+ optional_ptr<CreateTableFunctionInfo> info);
123
128
  //! Create a copy function in the catalog
124
- DUCKDB_API CatalogEntry *CreateCopyFunction(CatalogTransaction transaction, CreateCopyFunctionInfo *info);
125
- DUCKDB_API CatalogEntry *CreateCopyFunction(ClientContext &context, CreateCopyFunctionInfo *info);
129
+ DUCKDB_API optional_ptr<CatalogEntry> CreateCopyFunction(CatalogTransaction transaction,
130
+ CreateCopyFunctionInfo &info);
131
+ DUCKDB_API optional_ptr<CatalogEntry> CreateCopyFunction(ClientContext &context, CreateCopyFunctionInfo &info);
126
132
  //! Create a pragma function in the catalog
127
- DUCKDB_API CatalogEntry *CreatePragmaFunction(CatalogTransaction transaction, CreatePragmaFunctionInfo *info);
128
- DUCKDB_API CatalogEntry *CreatePragmaFunction(ClientContext &context, CreatePragmaFunctionInfo *info);
133
+ DUCKDB_API optional_ptr<CatalogEntry> CreatePragmaFunction(CatalogTransaction transaction,
134
+ CreatePragmaFunctionInfo &info);
135
+ DUCKDB_API optional_ptr<CatalogEntry> CreatePragmaFunction(ClientContext &context, CreatePragmaFunctionInfo &info);
129
136
  //! Create a scalar or aggregate function in the catalog
130
- DUCKDB_API CatalogEntry *CreateFunction(CatalogTransaction transaction, CreateFunctionInfo *info);
131
- DUCKDB_API CatalogEntry *CreateFunction(ClientContext &context, CreateFunctionInfo *info);
137
+ DUCKDB_API optional_ptr<CatalogEntry> CreateFunction(CatalogTransaction transaction, CreateFunctionInfo &info);
138
+ DUCKDB_API optional_ptr<CatalogEntry> CreateFunction(ClientContext &context, CreateFunctionInfo &info);
132
139
  //! Creates a table in the catalog.
133
- DUCKDB_API CatalogEntry *CreateView(CatalogTransaction transaction, CreateViewInfo *info);
134
- DUCKDB_API CatalogEntry *CreateView(ClientContext &context, CreateViewInfo *info);
140
+ DUCKDB_API optional_ptr<CatalogEntry> CreateView(CatalogTransaction transaction, CreateViewInfo &info);
141
+ DUCKDB_API optional_ptr<CatalogEntry> CreateView(ClientContext &context, CreateViewInfo &info);
135
142
  //! Creates a sequence in the catalog.
136
- DUCKDB_API CatalogEntry *CreateSequence(CatalogTransaction transaction, CreateSequenceInfo *info);
137
- DUCKDB_API CatalogEntry *CreateSequence(ClientContext &context, CreateSequenceInfo *info);
143
+ DUCKDB_API optional_ptr<CatalogEntry> CreateSequence(CatalogTransaction transaction, CreateSequenceInfo &info);
144
+ DUCKDB_API optional_ptr<CatalogEntry> CreateSequence(ClientContext &context, CreateSequenceInfo &info);
138
145
  //! Creates a Enum in the catalog.
139
- DUCKDB_API CatalogEntry *CreateType(CatalogTransaction transaction, CreateTypeInfo *info);
140
- DUCKDB_API CatalogEntry *CreateType(ClientContext &context, CreateTypeInfo *info);
146
+ DUCKDB_API optional_ptr<CatalogEntry> CreateType(CatalogTransaction transaction, CreateTypeInfo &info);
147
+ DUCKDB_API optional_ptr<CatalogEntry> CreateType(ClientContext &context, CreateTypeInfo &info);
141
148
  //! Creates a collation in the catalog
142
- DUCKDB_API CatalogEntry *CreateCollation(CatalogTransaction transaction, CreateCollationInfo *info);
143
- DUCKDB_API CatalogEntry *CreateCollation(ClientContext &context, CreateCollationInfo *info);
149
+ DUCKDB_API optional_ptr<CatalogEntry> CreateCollation(CatalogTransaction transaction, CreateCollationInfo &info);
150
+ DUCKDB_API optional_ptr<CatalogEntry> CreateCollation(ClientContext &context, CreateCollationInfo &info);
144
151
  //! Creates an index in the catalog
145
- DUCKDB_API CatalogEntry *CreateIndex(CatalogTransaction transaction, CreateIndexInfo *info);
146
- DUCKDB_API CatalogEntry *CreateIndex(ClientContext &context, CreateIndexInfo *info);
152
+ DUCKDB_API optional_ptr<CatalogEntry> CreateIndex(CatalogTransaction transaction, CreateIndexInfo &info);
153
+ DUCKDB_API optional_ptr<CatalogEntry> CreateIndex(ClientContext &context, CreateIndexInfo &info);
147
154
 
148
155
  //! Creates a table in the catalog.
149
- DUCKDB_API CatalogEntry *CreateTable(CatalogTransaction transaction, SchemaCatalogEntry &schema,
150
- BoundCreateTableInfo *info);
156
+ DUCKDB_API optional_ptr<CatalogEntry> CreateTable(CatalogTransaction transaction, SchemaCatalogEntry &schema,
157
+ BoundCreateTableInfo &info);
151
158
  //! Create a table function in the catalog
152
- DUCKDB_API CatalogEntry *CreateTableFunction(CatalogTransaction transaction, SchemaCatalogEntry &schema,
153
- CreateTableFunctionInfo *info);
159
+ DUCKDB_API optional_ptr<CatalogEntry>
160
+ CreateTableFunction(CatalogTransaction transaction, SchemaCatalogEntry &schema, CreateTableFunctionInfo &info);
154
161
  //! Create a copy function in the catalog
155
- DUCKDB_API CatalogEntry *CreateCopyFunction(CatalogTransaction transaction, SchemaCatalogEntry &schema,
156
- CreateCopyFunctionInfo *info);
162
+ DUCKDB_API optional_ptr<CatalogEntry> CreateCopyFunction(CatalogTransaction transaction, SchemaCatalogEntry &schema,
163
+ CreateCopyFunctionInfo &info);
157
164
  //! Create a pragma function in the catalog
158
- DUCKDB_API CatalogEntry *CreatePragmaFunction(CatalogTransaction transaction, SchemaCatalogEntry &schema,
159
- CreatePragmaFunctionInfo *info);
165
+ DUCKDB_API optional_ptr<CatalogEntry>
166
+ CreatePragmaFunction(CatalogTransaction transaction, SchemaCatalogEntry &schema, CreatePragmaFunctionInfo &info);
160
167
  //! Create a scalar or aggregate function in the catalog
161
- DUCKDB_API CatalogEntry *CreateFunction(CatalogTransaction transaction, SchemaCatalogEntry &schema,
162
- CreateFunctionInfo *info);
168
+ DUCKDB_API optional_ptr<CatalogEntry> CreateFunction(CatalogTransaction transaction, SchemaCatalogEntry &schema,
169
+ CreateFunctionInfo &info);
163
170
  //! Creates a view in the catalog
164
- DUCKDB_API CatalogEntry *CreateView(CatalogTransaction transaction, SchemaCatalogEntry &schema,
165
- CreateViewInfo *info);
171
+ DUCKDB_API optional_ptr<CatalogEntry> CreateView(CatalogTransaction transaction, SchemaCatalogEntry &schema,
172
+ CreateViewInfo &info);
166
173
  //! Creates a table in the catalog.
167
- DUCKDB_API CatalogEntry *CreateSequence(CatalogTransaction transaction, SchemaCatalogEntry &schema,
168
- CreateSequenceInfo *info);
174
+ DUCKDB_API optional_ptr<CatalogEntry> CreateSequence(CatalogTransaction transaction, SchemaCatalogEntry &schema,
175
+ CreateSequenceInfo &info);
169
176
  //! Creates a enum in the catalog.
170
- DUCKDB_API CatalogEntry *CreateType(CatalogTransaction transaction, SchemaCatalogEntry &schema,
171
- CreateTypeInfo *info);
177
+ DUCKDB_API optional_ptr<CatalogEntry> CreateType(CatalogTransaction transaction, SchemaCatalogEntry &schema,
178
+ CreateTypeInfo &info);
172
179
  //! Creates a collation in the catalog
173
- DUCKDB_API CatalogEntry *CreateCollation(CatalogTransaction transaction, SchemaCatalogEntry &schema,
174
- CreateCollationInfo *info);
180
+ DUCKDB_API optional_ptr<CatalogEntry> CreateCollation(CatalogTransaction transaction, SchemaCatalogEntry &schema,
181
+ CreateCollationInfo &info);
175
182
 
176
183
  //! Drops an entry from the catalog
177
- DUCKDB_API void DropEntry(ClientContext &context, DropInfo *info);
184
+ DUCKDB_API void DropEntry(ClientContext &context, DropInfo &info);
178
185
 
179
186
  //! Returns the schema object with the specified name, or throws an exception if it does not exist
180
- DUCKDB_API SchemaCatalogEntry *GetSchema(ClientContext &context, const string &name = DEFAULT_SCHEMA,
181
- bool if_exists = false,
187
+ DUCKDB_API SchemaCatalogEntry &GetSchema(ClientContext &context, const string &name,
188
+ QueryErrorContext error_context = QueryErrorContext());
189
+ DUCKDB_API optional_ptr<SchemaCatalogEntry> GetSchema(ClientContext &context, const string &name,
190
+ OnEntryNotFound if_not_found,
191
+ QueryErrorContext error_context = QueryErrorContext());
192
+ DUCKDB_API SchemaCatalogEntry &GetSchema(CatalogTransaction transaction, const string &name,
182
193
  QueryErrorContext error_context = QueryErrorContext());
183
- DUCKDB_API virtual SchemaCatalogEntry *GetSchema(CatalogTransaction transaction, const string &schema_name,
184
- bool if_exists = false,
185
- QueryErrorContext error_context = QueryErrorContext()) = 0;
186
- DUCKDB_API static SchemaCatalogEntry *GetSchema(ClientContext &context, const string &catalog_name,
187
- const string &schema_name, bool if_exists = false,
194
+ DUCKDB_API virtual optional_ptr<SchemaCatalogEntry>
195
+ GetSchema(CatalogTransaction transaction, const string &schema_name, OnEntryNotFound if_not_found,
196
+ QueryErrorContext error_context = QueryErrorContext()) = 0;
197
+ DUCKDB_API static SchemaCatalogEntry &GetSchema(ClientContext &context, const string &catalog_name,
198
+ const string &schema_name,
188
199
  QueryErrorContext error_context = QueryErrorContext());
200
+ DUCKDB_API static optional_ptr<SchemaCatalogEntry> GetSchema(ClientContext &context, const string &catalog_name,
201
+ const string &schema_name,
202
+ OnEntryNotFound if_not_found,
203
+ QueryErrorContext error_context = QueryErrorContext());
189
204
  //! Scans all the schemas in the system one-by-one, invoking the callback for each entry
190
- DUCKDB_API virtual void ScanSchemas(ClientContext &context, std::function<void(CatalogEntry *)> callback) = 0;
191
- //! Gets the "schema.name" entry of the specified type, if if_exists=true returns nullptr if entry does not
192
- //! exist, otherwise an exception is thrown
193
- DUCKDB_API CatalogEntry *GetEntry(ClientContext &context, CatalogType type, const string &schema,
194
- const string &name, bool if_exists = false,
195
- QueryErrorContext error_context = QueryErrorContext());
196
- //! Gets the "catalog.schema.name" entry of the specified type, if if_exists=true returns nullptr if entry does not
197
- //! exist, otherwise an exception is thrown
198
- DUCKDB_API static CatalogEntry *GetEntry(ClientContext &context, CatalogType type, const string &catalog,
199
- const string &schema, const string &name, bool if_exists = false,
205
+ DUCKDB_API virtual void ScanSchemas(ClientContext &context, std::function<void(SchemaCatalogEntry &)> callback) = 0;
206
+ //! Gets the "schema.name" entry of the specified type, if entry does not exist behavior depends on OnEntryNotFound
207
+ DUCKDB_API optional_ptr<CatalogEntry> GetEntry(ClientContext &context, CatalogType type, const string &schema,
208
+ const string &name, OnEntryNotFound if_not_found,
209
+ QueryErrorContext error_context = QueryErrorContext());
210
+ DUCKDB_API CatalogEntry &GetEntry(ClientContext &context, CatalogType type, const string &schema,
211
+ const string &name, QueryErrorContext error_context = QueryErrorContext());
212
+ //! Gets the "catalog.schema.name" entry of the specified type, if entry does not exist behavior depends on
213
+ //! OnEntryNotFound
214
+ DUCKDB_API static optional_ptr<CatalogEntry> GetEntry(ClientContext &context, CatalogType type,
215
+ const string &catalog, const string &schema,
216
+ const string &name, OnEntryNotFound if_not_found,
217
+ QueryErrorContext error_context = QueryErrorContext());
218
+ DUCKDB_API static CatalogEntry &GetEntry(ClientContext &context, CatalogType type, const string &catalog,
219
+ const string &schema, const string &name,
200
220
  QueryErrorContext error_context = QueryErrorContext());
201
221
 
202
222
  //! Gets the "schema.name" entry without a specified type, if entry does not exist an exception is thrown
203
- DUCKDB_API CatalogEntry *GetEntry(ClientContext &context, const string &schema, const string &name);
223
+ DUCKDB_API CatalogEntry &GetEntry(ClientContext &context, const string &schema, const string &name);
204
224
 
205
225
  //! Fetches a logical type from the catalog
206
- DUCKDB_API LogicalType GetType(ClientContext &context, const string &schema, const string &names, bool if_exists);
226
+ DUCKDB_API LogicalType GetType(ClientContext &context, const string &schema, const string &names,
227
+ OnEntryNotFound if_not_found);
207
228
 
208
229
  DUCKDB_API static LogicalType GetType(ClientContext &context, const string &catalog_name, const string &schema,
209
230
  const string &name);
@@ -212,20 +233,29 @@ public:
212
233
  const string &name);
213
234
 
214
235
  template <class T>
215
- T *GetEntry(ClientContext &context, const string &schema_name, const string &name, bool if_exists = false,
216
- QueryErrorContext error_context = QueryErrorContext()) {
217
- auto entry = GetEntry(context, T::Type, schema_name, name, if_exists, error_context);
218
- if (entry && entry->type != T::Type) {
236
+ optional_ptr<T> GetEntry(ClientContext &context, const string &schema_name, const string &name,
237
+ OnEntryNotFound if_not_found, QueryErrorContext error_context = QueryErrorContext()) {
238
+ auto entry = GetEntry(context, T::Type, schema_name, name, if_not_found, error_context);
239
+ if (!entry) {
240
+ return nullptr;
241
+ }
242
+ if (entry->type != T::Type) {
219
243
  throw CatalogException(error_context.FormatError("%s is not an %s", name, T::Name));
220
244
  }
221
- return (T *)entry;
245
+ return &entry->template Cast<T>();
246
+ }
247
+ template <class T>
248
+ T &GetEntry(ClientContext &context, const string &schema_name, const string &name,
249
+ QueryErrorContext error_context = QueryErrorContext()) {
250
+ auto entry = GetEntry<T>(context, schema_name, name, OnEntryNotFound::THROW_EXCEPTION, error_context);
251
+ return *entry;
222
252
  }
223
253
 
224
254
  //! Append a scalar or aggregate function to the catalog
225
- DUCKDB_API CatalogEntry *AddFunction(ClientContext &context, CreateFunctionInfo *info);
255
+ DUCKDB_API optional_ptr<CatalogEntry> AddFunction(ClientContext &context, CreateFunctionInfo &info);
226
256
 
227
257
  //! Alter an existing entry in the catalog.
228
- DUCKDB_API void Alter(ClientContext &context, AlterInfo *info);
258
+ DUCKDB_API void Alter(ClientContext &context, AlterInfo &info);
229
259
 
230
260
  virtual unique_ptr<PhysicalOperator> PlanCreateTableAs(ClientContext &context, LogicalCreateTable &op,
231
261
  unique_ptr<PhysicalOperator> plan) = 0;
@@ -245,19 +275,30 @@ public:
245
275
 
246
276
  public:
247
277
  template <class T>
248
- static T *GetEntry(ClientContext &context, const string &catalog_name, const string &schema_name,
249
- const string &name, bool if_exists = false,
250
- QueryErrorContext error_context = QueryErrorContext()) {
251
- auto entry = GetEntry(context, T::Type, catalog_name, schema_name, name, if_exists, error_context);
252
- if (entry && entry->type != T::Type) {
278
+ static optional_ptr<T> GetEntry(ClientContext &context, const string &catalog_name, const string &schema_name,
279
+ const string &name, OnEntryNotFound if_not_found,
280
+ QueryErrorContext error_context = QueryErrorContext()) {
281
+ auto entry = GetEntry(context, T::Type, catalog_name, schema_name, name, if_not_found, error_context);
282
+ if (!entry) {
283
+ return nullptr;
284
+ }
285
+ if (entry->type != T::Type) {
253
286
  throw CatalogException(error_context.FormatError("%s is not an %s", name, T::Name));
254
287
  }
255
- return (T *)entry;
288
+ return &entry->template Cast<T>();
289
+ }
290
+ template <class T>
291
+ static T &GetEntry(ClientContext &context, const string &catalog_name, const string &schema_name,
292
+ const string &name, QueryErrorContext error_context = QueryErrorContext()) {
293
+ auto entry =
294
+ GetEntry<T>(context, catalog_name, schema_name, name, OnEntryNotFound::THROW_EXCEPTION, error_context);
295
+ return *entry;
256
296
  }
257
297
 
258
- DUCKDB_API vector<SchemaCatalogEntry *> GetSchemas(ClientContext &context);
259
- DUCKDB_API static vector<SchemaCatalogEntry *> GetSchemas(ClientContext &context, const string &catalog_name);
260
- DUCKDB_API static vector<SchemaCatalogEntry *> GetAllSchemas(ClientContext &context);
298
+ DUCKDB_API vector<reference<SchemaCatalogEntry>> GetSchemas(ClientContext &context);
299
+ DUCKDB_API static vector<reference<SchemaCatalogEntry>> GetSchemas(ClientContext &context,
300
+ const string &catalog_name);
301
+ DUCKDB_API static vector<reference<SchemaCatalogEntry>> GetAllSchemas(ClientContext &context);
261
302
 
262
303
  virtual void Verify();
263
304
 
@@ -271,9 +312,9 @@ private:
271
312
  CatalogEntryLookup LookupEntryInternal(CatalogTransaction transaction, CatalogType type, const string &schema,
272
313
  const string &name);
273
314
  CatalogEntryLookup LookupEntry(ClientContext &context, CatalogType type, const string &schema, const string &name,
274
- bool if_exists = false, QueryErrorContext error_context = QueryErrorContext());
315
+ OnEntryNotFound if_not_found, QueryErrorContext error_context = QueryErrorContext());
275
316
  static CatalogEntryLookup LookupEntry(ClientContext &context, vector<CatalogLookup> &lookups, CatalogType type,
276
- const string &name, bool if_exists = false,
317
+ const string &name, OnEntryNotFound if_not_found,
277
318
  QueryErrorContext error_context = QueryErrorContext());
278
319
 
279
320
  //! Return an exception with did-you-mean suggestion.
@@ -286,7 +327,7 @@ private:
286
327
  static SimilarCatalogEntry SimilarEntryInSchemas(ClientContext &context, const string &entry_name, CatalogType type,
287
328
  const reference_set_t<SchemaCatalogEntry> &schemas);
288
329
 
289
- virtual void DropSchema(ClientContext &context, DropInfo *info) = 0;
330
+ virtual void DropSchema(ClientContext &context, DropInfo &info) = 0;
290
331
 
291
332
  public:
292
333
  template <class TARGET>
@@ -22,9 +22,8 @@ public:
22
22
  static constexpr const char *Name = "aggregate function";
23
23
 
24
24
  public:
25
- AggregateFunctionCatalogEntry(Catalog *catalog, SchemaCatalogEntry *schema, CreateAggregateFunctionInfo *info)
26
- : StandardEntry(CatalogType::AGGREGATE_FUNCTION_ENTRY, schema, catalog, info->name),
27
- functions(info->functions) {
25
+ AggregateFunctionCatalogEntry(Catalog &catalog, SchemaCatalogEntry &schema, CreateAggregateFunctionInfo &info)
26
+ : StandardEntry(CatalogType::AGGREGATE_FUNCTION_ENTRY, schema, catalog, info.name), functions(info.functions) {
28
27
  }
29
28
 
30
29
  //! The aggregate functions
@@ -21,9 +21,9 @@ public:
21
21
  static constexpr const char *Name = "collation";
22
22
 
23
23
  public:
24
- CollateCatalogEntry(Catalog *catalog, SchemaCatalogEntry *schema, CreateCollationInfo *info)
25
- : StandardEntry(CatalogType::COLLATION_ENTRY, schema, catalog, info->name), function(info->function),
26
- combinable(info->combinable), not_required_for_equality(info->not_required_for_equality) {
24
+ CollateCatalogEntry(Catalog &catalog, SchemaCatalogEntry &schema, CreateCollationInfo &info)
25
+ : StandardEntry(CatalogType::COLLATION_ENTRY, schema, catalog, info.name), function(info.function),
26
+ combinable(info.combinable), not_required_for_equality(info.not_required_for_equality) {
27
27
  }
28
28
 
29
29
  //! The collation function to push in case collation is required