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
@@ -50,7 +50,8 @@ void FindForeignKeyInformation(CatalogEntry &entry, AlterForeignKeyType alter_fk
50
50
  }
51
51
  auto &fk = cond->Cast<ForeignKeyConstraint>();
52
52
  if (fk.info.type == ForeignKeyType::FK_TYPE_FOREIGN_KEY_TABLE) {
53
- AlterEntryData alter_data(entry.catalog->GetName(), fk.info.schema, fk.info.table, false);
53
+ AlterEntryData alter_data(entry.ParentCatalog().GetName(), fk.info.schema, fk.info.table,
54
+ OnEntryNotFound::THROW_EXCEPTION);
54
55
  fk_arrays.push_back(make_uniq<AlterForeignKeyInfo>(std::move(alter_data), entry.name, fk.pk_columns,
55
56
  fk.fk_columns, fk.info.pk_keys, fk.info.fk_keys,
56
57
  alter_fk_type));
@@ -62,16 +63,18 @@ void FindForeignKeyInformation(CatalogEntry &entry, AlterForeignKeyType alter_fk
62
63
  }
63
64
  }
64
65
 
65
- DuckSchemaEntry::DuckSchemaEntry(Catalog *catalog, string name_p, bool is_internal)
66
+ DuckSchemaEntry::DuckSchemaEntry(Catalog &catalog, string name_p, bool is_internal)
66
67
  : SchemaCatalogEntry(catalog, std::move(name_p), is_internal),
67
- tables(*catalog, make_uniq<DefaultViewGenerator>(*catalog, *this)), indexes(*catalog), table_functions(*catalog),
68
- copy_functions(*catalog), pragma_functions(*catalog),
69
- functions(*catalog, make_uniq<DefaultFunctionGenerator>(*catalog, *this)), sequences(*catalog),
70
- collations(*catalog), types(*catalog, make_uniq<DefaultTypeGenerator>(*catalog, *this)) {
68
+ tables(catalog, make_uniq<DefaultViewGenerator>(catalog, *this)), indexes(catalog), table_functions(catalog),
69
+ copy_functions(catalog), pragma_functions(catalog),
70
+ functions(catalog, make_uniq<DefaultFunctionGenerator>(catalog, *this)), sequences(catalog), collations(catalog),
71
+ types(catalog, make_uniq<DefaultTypeGenerator>(catalog, *this)) {
71
72
  }
72
73
 
73
- CatalogEntry *DuckSchemaEntry::AddEntryInternal(CatalogTransaction transaction, unique_ptr<StandardEntry> entry,
74
- OnCreateConflict on_conflict, DependencyList dependencies) {
74
+ optional_ptr<CatalogEntry> DuckSchemaEntry::AddEntryInternal(CatalogTransaction transaction,
75
+ unique_ptr<StandardEntry> entry,
76
+ OnCreateConflict on_conflict,
77
+ DependencyList dependencies) {
75
78
  auto entry_name = entry->name;
76
79
  auto entry_type = entry->type;
77
80
  auto result = entry.get();
@@ -102,12 +105,12 @@ CatalogEntry *DuckSchemaEntry::AddEntryInternal(CatalogTransaction transaction,
102
105
  return result;
103
106
  }
104
107
 
105
- CatalogEntry *DuckSchemaEntry::CreateTable(CatalogTransaction transaction, BoundCreateTableInfo *info) {
106
- auto table = make_uniq<DuckTableEntry>(catalog, this, info);
108
+ optional_ptr<CatalogEntry> DuckSchemaEntry::CreateTable(CatalogTransaction transaction, BoundCreateTableInfo &info) {
109
+ auto table = make_uniq<DuckTableEntry>(catalog, *this, info);
107
110
  auto &storage = table->GetStorage();
108
111
  storage.info->cardinality = storage.GetTotalRows();
109
112
 
110
- CatalogEntry *entry = AddEntryInternal(transaction, std::move(table), info->Base().on_conflict, info->dependencies);
113
+ auto entry = AddEntryInternal(transaction, std::move(table), info.Base().on_conflict, info.dependencies);
111
114
  if (!entry) {
112
115
  return nullptr;
113
116
  }
@@ -117,122 +120,126 @@ CatalogEntry *DuckSchemaEntry::CreateTable(CatalogTransaction transaction, Bound
117
120
  FindForeignKeyInformation(*entry, AlterForeignKeyType::AFT_ADD, fk_arrays);
118
121
  for (idx_t i = 0; i < fk_arrays.size(); i++) {
119
122
  // alter primary key table
120
- AlterForeignKeyInfo *fk_info = fk_arrays[i].get();
121
- catalog->Alter(transaction.GetContext(), fk_info);
123
+ auto &fk_info = *fk_arrays[i];
124
+ catalog.Alter(transaction.GetContext(), fk_info);
122
125
 
123
126
  // make a dependency between this table and referenced table
124
127
  auto &set = GetCatalogSet(CatalogType::TABLE_ENTRY);
125
- info->dependencies.AddDependency(*set.GetEntry(transaction, fk_info->name));
128
+ info.dependencies.AddDependency(*set.GetEntry(transaction, fk_info.name));
126
129
  }
127
130
  return entry;
128
131
  }
129
132
 
130
- CatalogEntry *DuckSchemaEntry::CreateFunction(CatalogTransaction transaction, CreateFunctionInfo *info) {
131
- if (info->on_conflict == OnCreateConflict::ALTER_ON_CONFLICT) {
133
+ optional_ptr<CatalogEntry> DuckSchemaEntry::CreateFunction(CatalogTransaction transaction, CreateFunctionInfo &info) {
134
+ if (info.on_conflict == OnCreateConflict::ALTER_ON_CONFLICT) {
132
135
  // check if the original entry exists
133
- auto &catalog_set = GetCatalogSet(info->type);
134
- auto current_entry = catalog_set.GetEntry(transaction, info->name);
136
+ auto &catalog_set = GetCatalogSet(info.type);
137
+ auto current_entry = catalog_set.GetEntry(transaction, info.name);
135
138
  if (current_entry) {
136
139
  // the current entry exists - alter it instead
137
- auto alter_info = info->GetAlterInfo();
138
- Alter(transaction.GetContext(), alter_info.get());
140
+ auto alter_info = info.GetAlterInfo();
141
+ Alter(transaction.GetContext(), *alter_info);
139
142
  return nullptr;
140
143
  }
141
144
  }
142
145
  unique_ptr<StandardEntry> function;
143
- switch (info->type) {
146
+ switch (info.type) {
144
147
  case CatalogType::SCALAR_FUNCTION_ENTRY:
145
- function =
146
- make_uniq_base<StandardEntry, ScalarFunctionCatalogEntry>(catalog, this, (CreateScalarFunctionInfo *)info);
148
+ function = make_uniq_base<StandardEntry, ScalarFunctionCatalogEntry>(catalog, *this,
149
+ info.Cast<CreateScalarFunctionInfo>());
147
150
  break;
148
151
  case CatalogType::TABLE_FUNCTION_ENTRY:
149
- function =
150
- make_uniq_base<StandardEntry, TableFunctionCatalogEntry>(catalog, this, (CreateTableFunctionInfo *)info);
152
+ function = make_uniq_base<StandardEntry, TableFunctionCatalogEntry>(catalog, *this,
153
+ info.Cast<CreateTableFunctionInfo>());
151
154
  break;
152
155
  case CatalogType::MACRO_ENTRY:
153
156
  // create a macro function
154
- function = make_uniq_base<StandardEntry, ScalarMacroCatalogEntry>(catalog, this, (CreateMacroInfo *)info);
157
+ function = make_uniq_base<StandardEntry, ScalarMacroCatalogEntry>(catalog, *this, info.Cast<CreateMacroInfo>());
155
158
  break;
156
159
 
157
160
  case CatalogType::TABLE_MACRO_ENTRY:
158
161
  // create a macro table function
159
- function = make_uniq_base<StandardEntry, TableMacroCatalogEntry>(catalog, this, (CreateMacroInfo *)info);
162
+ function = make_uniq_base<StandardEntry, TableMacroCatalogEntry>(catalog, *this, info.Cast<CreateMacroInfo>());
160
163
  break;
161
164
  case CatalogType::AGGREGATE_FUNCTION_ENTRY:
162
- D_ASSERT(info->type == CatalogType::AGGREGATE_FUNCTION_ENTRY);
165
+ D_ASSERT(info.type == CatalogType::AGGREGATE_FUNCTION_ENTRY);
163
166
  // create an aggregate function
164
- function = make_uniq_base<StandardEntry, AggregateFunctionCatalogEntry>(catalog, this,
165
- (CreateAggregateFunctionInfo *)info);
167
+ function = make_uniq_base<StandardEntry, AggregateFunctionCatalogEntry>(
168
+ catalog, *this, info.Cast<CreateAggregateFunctionInfo>());
166
169
  break;
167
170
  default:
168
- throw InternalException("Unknown function type \"%s\"", CatalogTypeToString(info->type));
171
+ throw InternalException("Unknown function type \"%s\"", CatalogTypeToString(info.type));
169
172
  }
170
- function->internal = info->internal;
171
- return AddEntry(transaction, std::move(function), info->on_conflict);
173
+ function->internal = info.internal;
174
+ return AddEntry(transaction, std::move(function), info.on_conflict);
172
175
  }
173
176
 
174
- CatalogEntry *DuckSchemaEntry::AddEntry(CatalogTransaction transaction, unique_ptr<StandardEntry> entry,
175
- OnCreateConflict on_conflict) {
177
+ optional_ptr<CatalogEntry> DuckSchemaEntry::AddEntry(CatalogTransaction transaction, unique_ptr<StandardEntry> entry,
178
+ OnCreateConflict on_conflict) {
176
179
  DependencyList dependencies;
177
180
  return AddEntryInternal(transaction, std::move(entry), on_conflict, dependencies);
178
181
  }
179
182
 
180
- CatalogEntry *DuckSchemaEntry::CreateSequence(CatalogTransaction transaction, CreateSequenceInfo *info) {
181
- auto sequence = make_uniq<SequenceCatalogEntry>(catalog, this, info);
182
- return AddEntry(transaction, std::move(sequence), info->on_conflict);
183
+ optional_ptr<CatalogEntry> DuckSchemaEntry::CreateSequence(CatalogTransaction transaction, CreateSequenceInfo &info) {
184
+ auto sequence = make_uniq<SequenceCatalogEntry>(catalog, *this, info);
185
+ return AddEntry(transaction, std::move(sequence), info.on_conflict);
183
186
  }
184
187
 
185
- CatalogEntry *DuckSchemaEntry::CreateType(CatalogTransaction transaction, CreateTypeInfo *info) {
186
- auto type_entry = make_uniq<TypeCatalogEntry>(catalog, this, info);
187
- return AddEntry(transaction, std::move(type_entry), info->on_conflict);
188
+ optional_ptr<CatalogEntry> DuckSchemaEntry::CreateType(CatalogTransaction transaction, CreateTypeInfo &info) {
189
+ auto type_entry = make_uniq<TypeCatalogEntry>(catalog, *this, info);
190
+ return AddEntry(transaction, std::move(type_entry), info.on_conflict);
188
191
  }
189
192
 
190
- CatalogEntry *DuckSchemaEntry::CreateView(CatalogTransaction transaction, CreateViewInfo *info) {
191
- auto view = make_uniq<ViewCatalogEntry>(catalog, this, info);
192
- return AddEntry(transaction, std::move(view), info->on_conflict);
193
+ optional_ptr<CatalogEntry> DuckSchemaEntry::CreateView(CatalogTransaction transaction, CreateViewInfo &info) {
194
+ auto view = make_uniq<ViewCatalogEntry>(catalog, *this, info);
195
+ return AddEntry(transaction, std::move(view), info.on_conflict);
193
196
  }
194
197
 
195
- CatalogEntry *DuckSchemaEntry::CreateIndex(ClientContext &context, CreateIndexInfo *info, TableCatalogEntry *table) {
198
+ optional_ptr<CatalogEntry> DuckSchemaEntry::CreateIndex(ClientContext &context, CreateIndexInfo &info,
199
+ TableCatalogEntry &table) {
196
200
  DependencyList dependencies;
197
- dependencies.AddDependency(*table);
198
- auto index = make_uniq<DuckIndexEntry>(catalog, this, info);
199
- return AddEntryInternal(GetCatalogTransaction(context), std::move(index), info->on_conflict, dependencies);
201
+ dependencies.AddDependency(table);
202
+ auto index = make_uniq<DuckIndexEntry>(catalog, *this, info);
203
+ return AddEntryInternal(GetCatalogTransaction(context), std::move(index), info.on_conflict, dependencies);
200
204
  }
201
205
 
202
- CatalogEntry *DuckSchemaEntry::CreateCollation(CatalogTransaction transaction, CreateCollationInfo *info) {
203
- auto collation = make_uniq<CollateCatalogEntry>(catalog, this, info);
204
- collation->internal = info->internal;
205
- return AddEntry(transaction, std::move(collation), info->on_conflict);
206
+ optional_ptr<CatalogEntry> DuckSchemaEntry::CreateCollation(CatalogTransaction transaction, CreateCollationInfo &info) {
207
+ auto collation = make_uniq<CollateCatalogEntry>(catalog, *this, info);
208
+ collation->internal = info.internal;
209
+ return AddEntry(transaction, std::move(collation), info.on_conflict);
206
210
  }
207
211
 
208
- CatalogEntry *DuckSchemaEntry::CreateTableFunction(CatalogTransaction transaction, CreateTableFunctionInfo *info) {
209
- auto table_function = make_uniq<TableFunctionCatalogEntry>(catalog, this, info);
210
- table_function->internal = info->internal;
211
- return AddEntry(transaction, std::move(table_function), info->on_conflict);
212
+ optional_ptr<CatalogEntry> DuckSchemaEntry::CreateTableFunction(CatalogTransaction transaction,
213
+ CreateTableFunctionInfo &info) {
214
+ auto table_function = make_uniq<TableFunctionCatalogEntry>(catalog, *this, info);
215
+ table_function->internal = info.internal;
216
+ return AddEntry(transaction, std::move(table_function), info.on_conflict);
212
217
  }
213
218
 
214
- CatalogEntry *DuckSchemaEntry::CreateCopyFunction(CatalogTransaction transaction, CreateCopyFunctionInfo *info) {
215
- auto copy_function = make_uniq<CopyFunctionCatalogEntry>(catalog, this, info);
216
- copy_function->internal = info->internal;
217
- return AddEntry(transaction, std::move(copy_function), info->on_conflict);
219
+ optional_ptr<CatalogEntry> DuckSchemaEntry::CreateCopyFunction(CatalogTransaction transaction,
220
+ CreateCopyFunctionInfo &info) {
221
+ auto copy_function = make_uniq<CopyFunctionCatalogEntry>(catalog, *this, info);
222
+ copy_function->internal = info.internal;
223
+ return AddEntry(transaction, std::move(copy_function), info.on_conflict);
218
224
  }
219
225
 
220
- CatalogEntry *DuckSchemaEntry::CreatePragmaFunction(CatalogTransaction transaction, CreatePragmaFunctionInfo *info) {
221
- auto pragma_function = make_uniq<PragmaFunctionCatalogEntry>(catalog, this, info);
222
- pragma_function->internal = info->internal;
223
- return AddEntry(transaction, std::move(pragma_function), info->on_conflict);
226
+ optional_ptr<CatalogEntry> DuckSchemaEntry::CreatePragmaFunction(CatalogTransaction transaction,
227
+ CreatePragmaFunctionInfo &info) {
228
+ auto pragma_function = make_uniq<PragmaFunctionCatalogEntry>(catalog, *this, info);
229
+ pragma_function->internal = info.internal;
230
+ return AddEntry(transaction, std::move(pragma_function), info.on_conflict);
224
231
  }
225
232
 
226
- void DuckSchemaEntry::Alter(ClientContext &context, AlterInfo *info) {
227
- CatalogType type = info->GetCatalogType();
233
+ void DuckSchemaEntry::Alter(ClientContext &context, AlterInfo &info) {
234
+ CatalogType type = info.GetCatalogType();
228
235
  auto &set = GetCatalogSet(type);
229
236
  auto transaction = GetCatalogTransaction(context);
230
- if (info->type == AlterType::CHANGE_OWNERSHIP) {
231
- if (!set.AlterOwnership(transaction, (ChangeOwnershipInfo *)info)) {
237
+ if (info.type == AlterType::CHANGE_OWNERSHIP) {
238
+ if (!set.AlterOwnership(transaction, info.Cast<ChangeOwnershipInfo>())) {
232
239
  throw CatalogException("Couldn't change ownership!");
233
240
  }
234
241
  } else {
235
- string name = info->name;
242
+ string name = info.name;
236
243
  if (!set.AlterEntry(transaction, name, info)) {
237
244
  throw CatalogException("Entry with name \"%s\" does not exist!", name);
238
245
  }
@@ -240,46 +247,47 @@ void DuckSchemaEntry::Alter(ClientContext &context, AlterInfo *info) {
240
247
  }
241
248
 
242
249
  void DuckSchemaEntry::Scan(ClientContext &context, CatalogType type,
243
- const std::function<void(CatalogEntry *)> &callback) {
250
+ const std::function<void(CatalogEntry &)> &callback) {
244
251
  auto &set = GetCatalogSet(type);
245
252
  set.Scan(GetCatalogTransaction(context), callback);
246
253
  }
247
254
 
248
- void DuckSchemaEntry::Scan(CatalogType type, const std::function<void(CatalogEntry *)> &callback) {
255
+ void DuckSchemaEntry::Scan(CatalogType type, const std::function<void(CatalogEntry &)> &callback) {
249
256
  auto &set = GetCatalogSet(type);
250
257
  set.Scan(callback);
251
258
  }
252
259
 
253
- void DuckSchemaEntry::DropEntry(ClientContext &context, DropInfo *info) {
254
- auto &set = GetCatalogSet(info->type);
260
+ void DuckSchemaEntry::DropEntry(ClientContext &context, DropInfo &info) {
261
+ auto &set = GetCatalogSet(info.type);
255
262
 
256
263
  // first find the entry
257
264
  auto transaction = GetCatalogTransaction(context);
258
- auto existing_entry = set.GetEntry(transaction, info->name);
265
+ auto existing_entry = set.GetEntry(transaction, info.name);
259
266
  if (!existing_entry) {
260
- throw InternalException("Failed to drop entry \"%s\" - entry could not be found", info->name);
267
+ throw InternalException("Failed to drop entry \"%s\" - entry could not be found", info.name);
261
268
  }
262
- if (existing_entry->type != info->type) {
263
- throw CatalogException("Existing object %s is of type %s, trying to replace with type %s", info->name,
264
- CatalogTypeToString(existing_entry->type), CatalogTypeToString(info->type));
269
+ if (existing_entry->type != info.type) {
270
+ throw CatalogException("Existing object %s is of type %s, trying to replace with type %s", info.name,
271
+ CatalogTypeToString(existing_entry->type), CatalogTypeToString(info.type));
265
272
  }
266
273
 
267
274
  // if there is a foreign key constraint, get that information
268
275
  vector<unique_ptr<AlterForeignKeyInfo>> fk_arrays;
269
276
  FindForeignKeyInformation(*existing_entry, AlterForeignKeyType::AFT_DELETE, fk_arrays);
270
277
 
271
- if (!set.DropEntry(transaction, info->name, info->cascade, info->allow_drop_internal)) {
278
+ if (!set.DropEntry(transaction, info.name, info.cascade, info.allow_drop_internal)) {
272
279
  throw InternalException("Could not drop element because of an internal error");
273
280
  }
274
281
 
275
282
  // remove the foreign key constraint in main key table if main key table's name is valid
276
283
  for (idx_t i = 0; i < fk_arrays.size(); i++) {
277
284
  // alter primary key table
278
- catalog->Alter(context, fk_arrays[i].get());
285
+ catalog.Alter(context, *fk_arrays[i]);
279
286
  }
280
287
  }
281
288
 
282
- CatalogEntry *DuckSchemaEntry::GetEntry(CatalogTransaction transaction, CatalogType type, const string &name) {
289
+ optional_ptr<CatalogEntry> DuckSchemaEntry::GetEntry(CatalogTransaction transaction, CatalogType type,
290
+ const string &name) {
283
291
  return GetCatalogSet(type).GetEntry(transaction, name);
284
292
  }
285
293
 
@@ -318,7 +326,7 @@ CatalogSet &DuckSchemaEntry::GetCatalogSet(CatalogType type) {
318
326
  }
319
327
 
320
328
  void DuckSchemaEntry::Verify(Catalog &catalog) {
321
- CatalogEntry::Verify(catalog);
329
+ InCatalogEntry::Verify(catalog);
322
330
 
323
331
  tables.Verify(catalog);
324
332
  indexes.Verify(catalog);
@@ -19,7 +19,7 @@
19
19
 
20
20
  namespace duckdb {
21
21
 
22
- void AddDataTableIndex(DataTable *storage, const ColumnList &columns, const vector<PhysicalIndex> &keys,
22
+ void AddDataTableIndex(DataTable &storage, const ColumnList &columns, const vector<PhysicalIndex> &keys,
23
23
  IndexConstraintType constraint_type, BlockPointer *index_block = nullptr) {
24
24
  // fetch types and create expressions for the index from the columns
25
25
  vector<column_t> column_ids;
@@ -39,19 +39,19 @@ void AddDataTableIndex(DataTable *storage, const ColumnList &columns, const vect
39
39
  unique_ptr<ART> art;
40
40
  // create an adaptive radix tree around the expressions
41
41
  if (index_block) {
42
- art = make_uniq<ART>(column_ids, TableIOManager::Get(*storage), std::move(unbound_expressions), constraint_type,
43
- storage->db, true, index_block->block_id, index_block->offset);
42
+ art = make_uniq<ART>(column_ids, TableIOManager::Get(storage), std::move(unbound_expressions), constraint_type,
43
+ storage.db, true, index_block->block_id, index_block->offset);
44
44
  } else {
45
- art = make_uniq<ART>(column_ids, TableIOManager::Get(*storage), std::move(unbound_expressions), constraint_type,
46
- storage->db, true);
47
- if (!storage->IsRoot()) {
45
+ art = make_uniq<ART>(column_ids, TableIOManager::Get(storage), std::move(unbound_expressions), constraint_type,
46
+ storage.db, true);
47
+ if (!storage.IsRoot()) {
48
48
  throw TransactionException("Transaction conflict: cannot add an index to a table that has been altered!");
49
49
  }
50
50
  }
51
- storage->info->indexes.AddIndex(std::move(art));
51
+ storage.info->indexes.AddIndex(std::move(art));
52
52
  }
53
53
 
54
- void AddDataTableIndex(DataTable *storage, const ColumnList &columns, vector<LogicalIndex> &keys,
54
+ void AddDataTableIndex(DataTable &storage, const ColumnList &columns, vector<LogicalIndex> &keys,
55
55
  IndexConstraintType constraint_type, BlockPointer *index_block = nullptr) {
56
56
  vector<PhysicalIndex> new_keys;
57
57
  new_keys.reserve(keys.size());
@@ -61,19 +61,19 @@ void AddDataTableIndex(DataTable *storage, const ColumnList &columns, vector<Log
61
61
  AddDataTableIndex(storage, columns, new_keys, constraint_type, index_block);
62
62
  }
63
63
 
64
- DuckTableEntry::DuckTableEntry(Catalog *catalog, SchemaCatalogEntry *schema, BoundCreateTableInfo *info,
64
+ DuckTableEntry::DuckTableEntry(Catalog &catalog, SchemaCatalogEntry &schema, BoundCreateTableInfo &info,
65
65
  std::shared_ptr<DataTable> inherited_storage)
66
- : TableCatalogEntry(catalog, schema, info->Base()), storage(std::move(inherited_storage)),
67
- bound_constraints(std::move(info->bound_constraints)),
68
- column_dependency_manager(std::move(info->column_dependency_manager)) {
66
+ : TableCatalogEntry(catalog, schema, info.Base()), storage(std::move(inherited_storage)),
67
+ bound_constraints(std::move(info.bound_constraints)),
68
+ column_dependency_manager(std::move(info.column_dependency_manager)) {
69
69
  if (!storage) {
70
70
  // create the physical storage
71
71
  vector<ColumnDefinition> storage_columns;
72
72
  for (auto &col_def : columns.Physical()) {
73
73
  storage_columns.push_back(col_def.Copy());
74
74
  }
75
- storage = make_shared<DataTable>(catalog->GetAttached(), StorageManager::Get(*catalog).GetTableIOManager(info),
76
- schema->name, name, std::move(storage_columns), std::move(info->data));
75
+ storage = make_shared<DataTable>(catalog.GetAttached(), StorageManager::Get(catalog).GetTableIOManager(&info),
76
+ schema.name, name, std::move(storage_columns), std::move(info.data));
77
77
 
78
78
  // create the unique indexes for the UNIQUE and PRIMARY KEY and FOREIGN KEY constraints
79
79
  idx_t indexes_idx = 0;
@@ -86,22 +86,21 @@ DuckTableEntry::DuckTableEntry(Catalog *catalog, SchemaCatalogEntry *schema, Bou
86
86
  if (unique.is_primary_key) {
87
87
  constraint_type = IndexConstraintType::PRIMARY;
88
88
  }
89
- if (info->indexes.empty()) {
90
- AddDataTableIndex(storage.get(), columns, unique.keys, constraint_type);
89
+ if (info.indexes.empty()) {
90
+ AddDataTableIndex(*storage, columns, unique.keys, constraint_type);
91
91
  } else {
92
- AddDataTableIndex(storage.get(), columns, unique.keys, constraint_type,
93
- &info->indexes[indexes_idx++]);
92
+ AddDataTableIndex(*storage, columns, unique.keys, constraint_type, &info.indexes[indexes_idx++]);
94
93
  }
95
94
  } else if (constraint->type == ConstraintType::FOREIGN_KEY) {
96
95
  // foreign key constraint: create a foreign key index
97
96
  auto &bfk = constraint->Cast<BoundForeignKeyConstraint>();
98
97
  if (bfk.info.type == ForeignKeyType::FK_TYPE_FOREIGN_KEY_TABLE ||
99
98
  bfk.info.type == ForeignKeyType::FK_TYPE_SELF_REFERENCE_TABLE) {
100
- if (info->indexes.empty()) {
101
- AddDataTableIndex(storage.get(), columns, bfk.info.fk_keys, IndexConstraintType::FOREIGN);
99
+ if (info.indexes.empty()) {
100
+ AddDataTableIndex(*storage, columns, bfk.info.fk_keys, IndexConstraintType::FOREIGN);
102
101
  } else {
103
- AddDataTableIndex(storage.get(), columns, bfk.info.fk_keys, IndexConstraintType::FOREIGN,
104
- &info->indexes[indexes_idx++]);
102
+ AddDataTableIndex(*storage, columns, bfk.info.fk_keys, IndexConstraintType::FOREIGN,
103
+ &info.indexes[indexes_idx++]);
105
104
  }
106
105
  }
107
106
  }
@@ -120,66 +119,66 @@ unique_ptr<BaseStatistics> DuckTableEntry::GetStatistics(ClientContext &context,
120
119
  return storage->GetStatistics(context, column.StorageOid());
121
120
  }
122
121
 
123
- unique_ptr<CatalogEntry> DuckTableEntry::AlterEntry(ClientContext &context, AlterInfo *info) {
122
+ unique_ptr<CatalogEntry> DuckTableEntry::AlterEntry(ClientContext &context, AlterInfo &info) {
124
123
  D_ASSERT(!internal);
125
- if (info->type != AlterType::ALTER_TABLE) {
124
+ if (info.type != AlterType::ALTER_TABLE) {
126
125
  throw CatalogException("Can only modify table with ALTER TABLE statement");
127
126
  }
128
- auto table_info = (AlterTableInfo *)info;
129
- switch (table_info->alter_table_type) {
127
+ auto &table_info = info.Cast<AlterTableInfo>();
128
+ switch (table_info.alter_table_type) {
130
129
  case AlterTableType::RENAME_COLUMN: {
131
- auto rename_info = (RenameColumnInfo *)table_info;
132
- return RenameColumn(context, *rename_info);
130
+ auto &rename_info = table_info.Cast<RenameColumnInfo>();
131
+ return RenameColumn(context, rename_info);
133
132
  }
134
133
  case AlterTableType::RENAME_TABLE: {
135
- auto rename_info = (RenameTableInfo *)table_info;
134
+ auto &rename_info = table_info.Cast<RenameTableInfo>();
136
135
  auto copied_table = Copy(context);
137
- copied_table->name = rename_info->new_table_name;
138
- storage->info->table = rename_info->new_table_name;
136
+ copied_table->name = rename_info.new_table_name;
137
+ storage->info->table = rename_info.new_table_name;
139
138
  return copied_table;
140
139
  }
141
140
  case AlterTableType::ADD_COLUMN: {
142
- auto add_info = (AddColumnInfo *)table_info;
143
- return AddColumn(context, *add_info);
141
+ auto &add_info = table_info.Cast<AddColumnInfo>();
142
+ return AddColumn(context, add_info);
144
143
  }
145
144
  case AlterTableType::REMOVE_COLUMN: {
146
- auto remove_info = (RemoveColumnInfo *)table_info;
147
- return RemoveColumn(context, *remove_info);
145
+ auto &remove_info = table_info.Cast<RemoveColumnInfo>();
146
+ return RemoveColumn(context, remove_info);
148
147
  }
149
148
  case AlterTableType::SET_DEFAULT: {
150
- auto set_default_info = (SetDefaultInfo *)table_info;
151
- return SetDefault(context, *set_default_info);
149
+ auto &set_default_info = table_info.Cast<SetDefaultInfo>();
150
+ return SetDefault(context, set_default_info);
152
151
  }
153
152
  case AlterTableType::ALTER_COLUMN_TYPE: {
154
- auto change_type_info = (ChangeColumnTypeInfo *)table_info;
155
- return ChangeColumnType(context, *change_type_info);
153
+ auto &change_type_info = table_info.Cast<ChangeColumnTypeInfo>();
154
+ return ChangeColumnType(context, change_type_info);
156
155
  }
157
156
  case AlterTableType::FOREIGN_KEY_CONSTRAINT: {
158
- auto foreign_key_constraint_info = (AlterForeignKeyInfo *)table_info;
159
- if (foreign_key_constraint_info->type == AlterForeignKeyType::AFT_ADD) {
160
- return AddForeignKeyConstraint(context, *foreign_key_constraint_info);
157
+ auto &foreign_key_constraint_info = table_info.Cast<AlterForeignKeyInfo>();
158
+ if (foreign_key_constraint_info.type == AlterForeignKeyType::AFT_ADD) {
159
+ return AddForeignKeyConstraint(context, foreign_key_constraint_info);
161
160
  } else {
162
- return DropForeignKeyConstraint(context, *foreign_key_constraint_info);
161
+ return DropForeignKeyConstraint(context, foreign_key_constraint_info);
163
162
  }
164
163
  }
165
164
  case AlterTableType::SET_NOT_NULL: {
166
- auto set_not_null_info = (SetNotNullInfo *)table_info;
167
- return SetNotNull(context, *set_not_null_info);
165
+ auto &set_not_null_info = table_info.Cast<SetNotNullInfo>();
166
+ return SetNotNull(context, set_not_null_info);
168
167
  }
169
168
  case AlterTableType::DROP_NOT_NULL: {
170
- auto drop_not_null_info = (DropNotNullInfo *)table_info;
171
- return DropNotNull(context, *drop_not_null_info);
169
+ auto &drop_not_null_info = table_info.Cast<DropNotNullInfo>();
170
+ return DropNotNull(context, drop_not_null_info);
172
171
  }
173
172
  default:
174
173
  throw InternalException("Unrecognized alter table type!");
175
174
  }
176
175
  }
177
176
 
178
- void DuckTableEntry::UndoAlter(ClientContext &context, AlterInfo *info) {
177
+ void DuckTableEntry::UndoAlter(ClientContext &context, AlterInfo &info) {
179
178
  D_ASSERT(!internal);
180
- D_ASSERT(info->type == AlterType::ALTER_TABLE);
181
- auto table_info = (AlterTableInfo *)info;
182
- switch (table_info->alter_table_type) {
179
+ D_ASSERT(info.type == AlterType::ALTER_TABLE);
180
+ auto &table_info = info.Cast<AlterTableInfo>();
181
+ switch (table_info.alter_table_type) {
183
182
  case AlterTableType::RENAME_TABLE: {
184
183
  storage->info->table = this->name;
185
184
  break;
@@ -266,7 +265,7 @@ unique_ptr<CatalogEntry> DuckTableEntry::RenameColumn(ClientContext &context, Re
266
265
  }
267
266
  auto binder = Binder::CreateBinder(context);
268
267
  auto bound_create_info = binder->BindCreateTableInfo(std::move(create_info));
269
- return make_uniq<DuckTableEntry>(catalog, schema, (BoundCreateTableInfo *)bound_create_info.get(), storage);
268
+ return make_uniq<DuckTableEntry>(catalog, schema, *bound_create_info, storage);
270
269
  }
271
270
 
272
271
  unique_ptr<CatalogEntry> DuckTableEntry::AddColumn(ClientContext &context, AddColumnInfo &info) {
@@ -286,7 +285,7 @@ unique_ptr<CatalogEntry> DuckTableEntry::AddColumn(ClientContext &context, AddCo
286
285
  for (auto &constraint : constraints) {
287
286
  create_info->constraints.push_back(constraint->Copy());
288
287
  }
289
- Binder::BindLogicalType(context, info.new_column.TypeMutable(), catalog, schema->name);
288
+ Binder::BindLogicalType(context, info.new_column.TypeMutable(), &catalog, schema.name);
290
289
  info.new_column.SetOid(columns.LogicalColumnCount());
291
290
  info.new_column.SetStorageOid(columns.PhysicalColumnCount());
292
291
  auto col = info.new_column.Copy();
@@ -297,7 +296,7 @@ unique_ptr<CatalogEntry> DuckTableEntry::AddColumn(ClientContext &context, AddCo
297
296
  auto bound_create_info = binder->BindCreateTableInfo(std::move(create_info));
298
297
  auto new_storage =
299
298
  make_shared<DataTable>(context, *storage, info.new_column, bound_create_info->bound_defaults.back().get());
300
- return make_uniq<DuckTableEntry>(catalog, schema, (BoundCreateTableInfo *)bound_create_info.get(), new_storage);
299
+ return make_uniq<DuckTableEntry>(catalog, schema, *bound_create_info, new_storage);
301
300
  }
302
301
 
303
302
  void DuckTableEntry::UpdateConstraintsOnColumnDrop(const LogicalIndex &removed_index,
@@ -428,11 +427,11 @@ unique_ptr<CatalogEntry> DuckTableEntry::RemoveColumn(ClientContext &context, Re
428
427
  auto binder = Binder::CreateBinder(context);
429
428
  auto bound_create_info = binder->BindCreateTableInfo(std::move(create_info));
430
429
  if (columns.GetColumn(LogicalIndex(removed_index)).Generated()) {
431
- return make_uniq<DuckTableEntry>(catalog, schema, (BoundCreateTableInfo *)bound_create_info.get(), storage);
430
+ return make_uniq<DuckTableEntry>(catalog, schema, *bound_create_info, storage);
432
431
  }
433
432
  auto new_storage =
434
433
  make_shared<DataTable>(context, *storage, columns.LogicalToPhysical(LogicalIndex(removed_index)).index);
435
- return make_uniq<DuckTableEntry>(catalog, schema, (BoundCreateTableInfo *)bound_create_info.get(), new_storage);
434
+ return make_uniq<DuckTableEntry>(catalog, schema, *bound_create_info, new_storage);
436
435
  }
437
436
 
438
437
  unique_ptr<CatalogEntry> DuckTableEntry::SetDefault(ClientContext &context, SetDefaultInfo &info) {
@@ -462,7 +461,7 @@ unique_ptr<CatalogEntry> DuckTableEntry::SetDefault(ClientContext &context, SetD
462
461
 
463
462
  auto binder = Binder::CreateBinder(context);
464
463
  auto bound_create_info = binder->BindCreateTableInfo(std::move(create_info));
465
- return make_uniq<DuckTableEntry>(catalog, schema, (BoundCreateTableInfo *)bound_create_info.get(), storage);
464
+ return make_uniq<DuckTableEntry>(catalog, schema, *bound_create_info, storage);
466
465
  }
467
466
 
468
467
  unique_ptr<CatalogEntry> DuckTableEntry::SetNotNull(ClientContext &context, SetNotNullInfo &info) {
@@ -493,13 +492,13 @@ unique_ptr<CatalogEntry> DuckTableEntry::SetNotNull(ClientContext &context, SetN
493
492
 
494
493
  // Early return
495
494
  if (has_not_null) {
496
- return make_uniq<DuckTableEntry>(catalog, schema, (BoundCreateTableInfo *)bound_create_info.get(), storage);
495
+ return make_uniq<DuckTableEntry>(catalog, schema, *bound_create_info, storage);
497
496
  }
498
497
 
499
498
  // Return with new storage info. Note that we need the bound column index here.
500
499
  auto new_storage = make_shared<DataTable>(
501
500
  context, *storage, make_uniq<BoundNotNullConstraint>(columns.LogicalToPhysical(LogicalIndex(not_null_idx))));
502
- return make_uniq<DuckTableEntry>(catalog, schema, (BoundCreateTableInfo *)bound_create_info.get(), new_storage);
501
+ return make_uniq<DuckTableEntry>(catalog, schema, *bound_create_info, new_storage);
503
502
  }
504
503
 
505
504
  unique_ptr<CatalogEntry> DuckTableEntry::DropNotNull(ClientContext &context, DropNotNullInfo &info) {
@@ -521,13 +520,13 @@ unique_ptr<CatalogEntry> DuckTableEntry::DropNotNull(ClientContext &context, Dro
521
520
 
522
521
  auto binder = Binder::CreateBinder(context);
523
522
  auto bound_create_info = binder->BindCreateTableInfo(std::move(create_info));
524
- return make_uniq<DuckTableEntry>(catalog, schema, (BoundCreateTableInfo *)bound_create_info.get(), storage);
523
+ return make_uniq<DuckTableEntry>(catalog, schema, *bound_create_info, storage);
525
524
  }
526
525
 
527
526
  unique_ptr<CatalogEntry> DuckTableEntry::ChangeColumnType(ClientContext &context, ChangeColumnTypeInfo &info) {
528
527
  if (info.target_type.id() == LogicalTypeId::USER) {
529
528
  info.target_type =
530
- Catalog::GetType(context, catalog->GetName(), schema->name, UserType::GetTypeName(info.target_type));
529
+ Catalog::GetType(context, catalog.GetName(), schema.name, UserType::GetTypeName(info.target_type));
531
530
  }
532
531
  auto change_idx = GetColumnIndex(info.column_name);
533
532
  auto create_info = make_uniq<CreateTableInfo>(schema, name);
@@ -611,8 +610,7 @@ unique_ptr<CatalogEntry> DuckTableEntry::ChangeColumnType(ClientContext &context
611
610
  auto new_storage =
612
611
  make_shared<DataTable>(context, *storage, columns.LogicalToPhysical(LogicalIndex(change_idx)).index,
613
612
  info.target_type, std::move(storage_oids), *bound_expression);
614
- auto result =
615
- make_uniq<DuckTableEntry>(catalog, schema, (BoundCreateTableInfo *)bound_create_info.get(), new_storage);
613
+ auto result = make_uniq<DuckTableEntry>(catalog, schema, *bound_create_info, new_storage);
616
614
  return std::move(result);
617
615
  }
618
616
 
@@ -637,7 +635,7 @@ unique_ptr<CatalogEntry> DuckTableEntry::AddForeignKeyConstraint(ClientContext &
637
635
  auto binder = Binder::CreateBinder(context);
638
636
  auto bound_create_info = binder->BindCreateTableInfo(std::move(create_info));
639
637
 
640
- return make_uniq<DuckTableEntry>(catalog, schema, (BoundCreateTableInfo *)bound_create_info.get(), storage);
638
+ return make_uniq<DuckTableEntry>(catalog, schema, *bound_create_info, storage);
641
639
  }
642
640
 
643
641
  unique_ptr<CatalogEntry> DuckTableEntry::DropForeignKeyConstraint(ClientContext &context, AlterForeignKeyInfo &info) {
@@ -660,7 +658,7 @@ unique_ptr<CatalogEntry> DuckTableEntry::DropForeignKeyConstraint(ClientContext
660
658
  auto binder = Binder::CreateBinder(context);
661
659
  auto bound_create_info = binder->BindCreateTableInfo(std::move(create_info));
662
660
 
663
- return make_uniq<DuckTableEntry>(catalog, schema, (BoundCreateTableInfo *)bound_create_info.get(), storage);
661
+ return make_uniq<DuckTableEntry>(catalog, schema, *bound_create_info, storage);
664
662
  }
665
663
 
666
664
  unique_ptr<CatalogEntry> DuckTableEntry::Copy(ClientContext &context) const {
@@ -674,7 +672,7 @@ unique_ptr<CatalogEntry> DuckTableEntry::Copy(ClientContext &context) const {
674
672
 
675
673
  auto binder = Binder::CreateBinder(context);
676
674
  auto bound_create_info = binder->BindCreateTableInfo(std::move(create_info));
677
- return make_uniq<DuckTableEntry>(catalog, schema, (BoundCreateTableInfo *)bound_create_info.get(), storage);
675
+ return make_uniq<DuckTableEntry>(catalog, schema, *bound_create_info, storage);
678
676
  }
679
677
 
680
678
  void DuckTableEntry::SetAsRoot() {
@@ -712,7 +710,7 @@ const vector<unique_ptr<BoundConstraint>> &DuckTableEntry::GetBoundConstraints()
712
710
  }
713
711
 
714
712
  TableFunction DuckTableEntry::GetScanFunction(ClientContext &context, unique_ptr<FunctionData> &bind_data) {
715
- bind_data = make_uniq<TableScanBindData>(this);
713
+ bind_data = make_uniq<TableScanBindData>(*this);
716
714
  return TableScanFunction::GetFunction();
717
715
  }
718
716
 
@@ -4,9 +4,9 @@
4
4
 
5
5
  namespace duckdb {
6
6
 
7
- IndexCatalogEntry::IndexCatalogEntry(Catalog *catalog, SchemaCatalogEntry *schema, CreateIndexInfo *info)
8
- : StandardEntry(CatalogType::INDEX_ENTRY, schema, catalog, info->index_name), index(nullptr), sql(info->sql) {
9
- this->temporary = info->temporary;
7
+ IndexCatalogEntry::IndexCatalogEntry(Catalog &catalog, SchemaCatalogEntry &schema, CreateIndexInfo &info)
8
+ : StandardEntry(CatalogType::INDEX_ENTRY, schema, catalog, info.index_name), index(nullptr), sql(info.sql) {
9
+ this->temporary = info.temporary;
10
10
  }
11
11
 
12
12
  string IndexCatalogEntry::ToSQL() const {