duckdb 0.6.2-dev1832.0 → 0.6.2-dev1922.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 (186) hide show
  1. package/package.json +1 -1
  2. package/src/duckdb/extension/parquet/parquet-extension.cpp +1 -0
  3. package/src/duckdb/src/catalog/catalog.cpp +22 -119
  4. package/src/duckdb/src/catalog/catalog_entry/duck_index_entry.cpp +27 -0
  5. package/src/duckdb/src/catalog/catalog_entry/duck_schema_entry.cpp +330 -0
  6. package/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp +739 -0
  7. package/src/duckdb/src/catalog/catalog_entry/index_catalog_entry.cpp +4 -13
  8. package/src/duckdb/src/catalog/catalog_entry/schema_catalog_entry.cpp +11 -308
  9. package/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp +44 -708
  10. package/src/duckdb/src/catalog/catalog_set.cpp +44 -38
  11. package/src/duckdb/src/catalog/catalog_transaction.cpp +9 -3
  12. package/src/duckdb/src/catalog/default/default_functions.cpp +1 -2
  13. package/src/duckdb/src/catalog/default/default_schemas.cpp +2 -2
  14. package/src/duckdb/src/catalog/default/default_views.cpp +8 -16
  15. package/src/duckdb/src/catalog/dependency_manager.cpp +6 -6
  16. package/src/duckdb/src/catalog/duck_catalog.cpp +111 -0
  17. package/src/duckdb/src/catalog/similar_catalog_entry.cpp +26 -0
  18. package/src/duckdb/src/common/bind_helpers.cpp +67 -0
  19. package/src/duckdb/src/common/enums/physical_operator_type.cpp +2 -0
  20. package/src/duckdb/src/common/file_system.cpp +2 -1
  21. package/src/duckdb/src/common/hive_partitioning.cpp +129 -4
  22. package/src/duckdb/src/common/local_file_system.cpp +4 -2
  23. package/src/duckdb/src/common/radix_partitioning.cpp +1 -0
  24. package/src/duckdb/src/common/string_util.cpp +9 -1
  25. package/src/duckdb/src/common/types/data_chunk.cpp +10 -0
  26. package/src/duckdb/src/common/types/partitioned_column_data.cpp +5 -0
  27. package/src/duckdb/src/common/vector_operations/vector_cast.cpp +1 -0
  28. package/src/duckdb/src/execution/column_binding_resolver.cpp +2 -2
  29. package/src/duckdb/src/execution/operator/helper/physical_vacuum.cpp +2 -1
  30. package/src/duckdb/src/execution/operator/join/physical_index_join.cpp +5 -4
  31. package/src/duckdb/src/execution/operator/persistent/csv_reader_options.cpp +1 -50
  32. package/src/duckdb/src/execution/operator/persistent/physical_batch_insert.cpp +13 -11
  33. package/src/duckdb/src/execution/operator/persistent/physical_copy_to_file.cpp +110 -15
  34. package/src/duckdb/src/execution/operator/persistent/physical_delete.cpp +2 -1
  35. package/src/duckdb/src/execution/operator/persistent/physical_insert.cpp +30 -35
  36. package/src/duckdb/src/execution/operator/schema/physical_attach.cpp +26 -5
  37. package/src/duckdb/src/execution/operator/schema/physical_create_index.cpp +29 -11
  38. package/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp +5 -4
  39. package/src/duckdb/src/execution/physical_plan/plan_copy_to_file.cpp +5 -0
  40. package/src/duckdb/src/execution/physical_plan/plan_create_table.cpp +22 -16
  41. package/src/duckdb/src/execution/physical_plan/plan_delete.cpp +14 -8
  42. package/src/duckdb/src/execution/physical_plan/plan_insert.cpp +15 -11
  43. package/src/duckdb/src/execution/physical_plan/plan_update.cpp +13 -7
  44. package/src/duckdb/src/function/pragma/pragma_functions.cpp +1 -0
  45. package/src/duckdb/src/function/pragma/pragma_queries.cpp +3 -3
  46. package/src/duckdb/src/function/scalar/sequence/nextval.cpp +5 -5
  47. package/src/duckdb/src/function/scalar/system/system_functions.cpp +9 -2
  48. package/src/duckdb/src/function/table/checkpoint.cpp +1 -0
  49. package/src/duckdb/src/function/table/copy_csv.cpp +1 -7
  50. package/src/duckdb/src/function/table/system/duckdb_columns.cpp +5 -5
  51. package/src/duckdb/src/function/table/system/duckdb_constraints.cpp +70 -59
  52. package/src/duckdb/src/function/table/system/duckdb_databases.cpp +89 -0
  53. package/src/duckdb/src/function/table/system/duckdb_dependencies.cpp +12 -8
  54. package/src/duckdb/src/function/table/system/duckdb_indexes.cpp +16 -9
  55. package/src/duckdb/src/function/table/system/duckdb_tables.cpp +9 -5
  56. package/src/duckdb/src/function/table/system/duckdb_views.cpp +1 -1
  57. package/src/duckdb/src/function/table/system/pragma_database_size.cpp +3 -3
  58. package/src/duckdb/src/function/table/system/pragma_storage_info.cpp +41 -18
  59. package/src/duckdb/src/function/table/system/pragma_table_info.cpp +17 -11
  60. package/src/duckdb/src/function/table/system_functions.cpp +1 -1
  61. package/src/duckdb/src/function/table/table_scan.cpp +27 -23
  62. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  63. package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +42 -20
  64. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_index_entry.hpp +29 -0
  65. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_schema_entry.hpp +69 -0
  66. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_table_entry.hpp +68 -0
  67. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/index_catalog_entry.hpp +3 -2
  68. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/schema_catalog_entry.hpp +19 -50
  69. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_catalog_entry.hpp +48 -39
  70. package/src/duckdb/src/include/duckdb/catalog/catalog_set.hpp +8 -5
  71. package/src/duckdb/src/include/duckdb/catalog/dependency_manager.hpp +3 -3
  72. package/src/duckdb/src/include/duckdb/catalog/duck_catalog.hpp +75 -0
  73. package/src/duckdb/src/include/duckdb/catalog/similar_catalog_entry.hpp +32 -0
  74. package/src/duckdb/src/include/duckdb/common/bind_helpers.hpp +21 -0
  75. package/src/duckdb/src/include/duckdb/common/enums/access_mode.hpp +17 -0
  76. package/src/duckdb/src/include/duckdb/common/enums/physical_operator_type.hpp +2 -1
  77. package/src/duckdb/src/include/duckdb/common/file_system.hpp +3 -1
  78. package/src/duckdb/src/include/duckdb/common/hive_partitioning.hpp +71 -2
  79. package/src/duckdb/src/include/duckdb/common/local_file_system.hpp +2 -1
  80. package/src/duckdb/src/include/duckdb/common/string_util.hpp +2 -0
  81. package/src/duckdb/src/include/duckdb/common/types/data_chunk.hpp +2 -0
  82. package/src/duckdb/src/include/duckdb/common/types/partitioned_column_data.hpp +1 -1
  83. package/src/duckdb/src/include/duckdb/common/virtual_file_system.hpp +3 -2
  84. package/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_copy_to_file.hpp +7 -1
  85. package/src/duckdb/src/include/duckdb/execution/operator/schema/physical_create_index.hpp +4 -11
  86. package/src/duckdb/src/include/duckdb/function/replacement_open.hpp +9 -0
  87. package/src/duckdb/src/include/duckdb/function/table/system_functions.hpp +4 -4
  88. package/src/duckdb/src/include/duckdb/function/table/table_scan.hpp +3 -2
  89. package/src/duckdb/src/include/duckdb/main/attached_database.hpp +6 -0
  90. package/src/duckdb/src/include/duckdb/main/client_context.hpp +1 -1
  91. package/src/duckdb/src/include/duckdb/main/config.hpp +5 -2
  92. package/src/duckdb/src/include/duckdb/optimizer/join_order/cardinality_estimator.hpp +0 -1
  93. package/src/duckdb/src/include/duckdb/optimizer/join_order/estimated_properties.hpp +0 -1
  94. package/src/duckdb/src/include/duckdb/optimizer/join_order/join_node.hpp +0 -1
  95. package/src/duckdb/src/include/duckdb/parser/column_list.hpp +1 -1
  96. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_view_info.hpp +5 -0
  97. package/src/duckdb/src/include/duckdb/planner/bind_context.hpp +3 -2
  98. package/src/duckdb/src/include/duckdb/planner/binder.hpp +7 -3
  99. package/src/duckdb/src/include/duckdb/planner/expression/bound_cast_expression.hpp +2 -2
  100. package/src/duckdb/src/include/duckdb/planner/operator/logical_copy_to_file.hpp +6 -0
  101. package/src/duckdb/src/include/duckdb/planner/operator/logical_delete.hpp +4 -20
  102. package/src/duckdb/src/include/duckdb/planner/operator/logical_extension_operator.hpp +1 -2
  103. package/src/duckdb/src/include/duckdb/planner/operator/logical_insert.hpp +4 -18
  104. package/src/duckdb/src/include/duckdb/planner/operator/logical_update.hpp +4 -18
  105. package/src/duckdb/src/include/duckdb/storage/checkpoint/table_data_writer.hpp +2 -1
  106. package/src/duckdb/src/include/duckdb/storage/checkpoint_manager.hpp +1 -3
  107. package/src/duckdb/src/include/duckdb/storage/data_table.hpp +7 -6
  108. package/src/duckdb/src/include/duckdb/storage/database_size.hpp +24 -0
  109. package/src/duckdb/src/include/duckdb/storage/magic_bytes.hpp +28 -0
  110. package/src/duckdb/src/include/duckdb/storage/single_file_block_manager.hpp +6 -1
  111. package/src/duckdb/src/include/duckdb/storage/storage_extension.hpp +42 -0
  112. package/src/duckdb/src/include/duckdb/storage/storage_manager.hpp +1 -9
  113. package/src/duckdb/src/include/duckdb/storage/table/column_data.hpp +2 -1
  114. package/src/duckdb/src/include/duckdb/storage/table/list_column_data.hpp +1 -1
  115. package/src/duckdb/src/include/duckdb/storage/table/row_group.hpp +2 -1
  116. package/src/duckdb/src/include/duckdb/storage/table/row_group_collection.hpp +5 -3
  117. package/src/duckdb/src/include/duckdb/storage/table/scan_state.hpp +2 -1
  118. package/src/duckdb/src/include/duckdb/storage/table/standard_column_data.hpp +1 -1
  119. package/src/duckdb/src/include/duckdb/storage/table/struct_column_data.hpp +1 -1
  120. package/src/duckdb/src/include/duckdb/storage/table_storage_info.hpp +48 -0
  121. package/src/duckdb/src/include/duckdb/transaction/duck_transaction.hpp +68 -0
  122. package/src/duckdb/src/include/duckdb/transaction/duck_transaction_manager.hpp +75 -0
  123. package/src/duckdb/src/include/duckdb/transaction/local_storage.hpp +7 -6
  124. package/src/duckdb/src/include/duckdb/transaction/meta_transaction.hpp +3 -0
  125. package/src/duckdb/src/include/duckdb/transaction/transaction.hpp +9 -42
  126. package/src/duckdb/src/include/duckdb/transaction/transaction_data.hpp +3 -2
  127. package/src/duckdb/src/include/duckdb/transaction/transaction_manager.hpp +12 -41
  128. package/src/duckdb/src/main/appender.cpp +2 -1
  129. package/src/duckdb/src/main/attached_database.cpp +28 -7
  130. package/src/duckdb/src/main/client_context.cpp +6 -6
  131. package/src/duckdb/src/main/config.cpp +1 -0
  132. package/src/duckdb/src/main/database.cpp +26 -7
  133. package/src/duckdb/src/main/database_manager.cpp +4 -3
  134. package/src/duckdb/src/main/extension_prefix_opener.cpp +8 -0
  135. package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +1 -0
  136. package/src/duckdb/src/parser/parsed_data/create_table_info.cpp +1 -0
  137. package/src/duckdb/src/parser/parsed_data/create_view_info.cpp +52 -0
  138. package/src/duckdb/src/planner/bind_context.cpp +3 -2
  139. package/src/duckdb/src/planner/binder/statement/bind_copy.cpp +40 -3
  140. package/src/duckdb/src/planner/binder/statement/bind_create.cpp +43 -34
  141. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +1 -1
  142. package/src/duckdb/src/planner/binder/statement/bind_delete.cpp +1 -0
  143. package/src/duckdb/src/planner/binder/statement/bind_export.cpp +5 -3
  144. package/src/duckdb/src/planner/binder/statement/bind_insert.cpp +52 -45
  145. package/src/duckdb/src/planner/binder/statement/bind_update.cpp +12 -7
  146. package/src/duckdb/src/planner/binder/statement/bind_vacuum.cpp +2 -1
  147. package/src/duckdb/src/planner/binder/tableref/bind_basetableref.cpp +4 -4
  148. package/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp +2 -0
  149. package/src/duckdb/src/planner/binder.cpp +1 -1
  150. package/src/duckdb/src/planner/expression_binder/alter_binder.cpp +2 -3
  151. package/src/duckdb/src/planner/operator/logical_copy_to_file.cpp +8 -0
  152. package/src/duckdb/src/planner/operator/logical_delete.cpp +21 -0
  153. package/src/duckdb/src/planner/operator/logical_insert.cpp +20 -0
  154. package/src/duckdb/src/planner/operator/logical_update.cpp +19 -0
  155. package/src/duckdb/src/planner/table_binding.cpp +4 -4
  156. package/src/duckdb/src/storage/checkpoint/row_group_writer.cpp +1 -1
  157. package/src/duckdb/src/storage/checkpoint/table_data_writer.cpp +5 -3
  158. package/src/duckdb/src/storage/checkpoint_manager.cpp +13 -12
  159. package/src/duckdb/src/storage/data_table.cpp +38 -33
  160. package/src/duckdb/src/storage/local_storage.cpp +8 -8
  161. package/src/duckdb/src/storage/magic_bytes.cpp +31 -0
  162. package/src/duckdb/src/storage/single_file_block_manager.cpp +80 -64
  163. package/src/duckdb/src/storage/storage_manager.cpp +6 -2
  164. package/src/duckdb/src/storage/table/column_data.cpp +20 -31
  165. package/src/duckdb/src/storage/table/list_column_data.cpp +1 -1
  166. package/src/duckdb/src/storage/table/row_group.cpp +5 -3
  167. package/src/duckdb/src/storage/table/row_group_collection.cpp +3 -7
  168. package/src/duckdb/src/storage/table/scan_state.cpp +2 -2
  169. package/src/duckdb/src/storage/table/standard_column_data.cpp +1 -1
  170. package/src/duckdb/src/storage/table/struct_column_data.cpp +1 -1
  171. package/src/duckdb/src/storage/table/update_segment.cpp +3 -2
  172. package/src/duckdb/src/storage/wal_replay.cpp +4 -4
  173. package/src/duckdb/src/transaction/commit_state.cpp +9 -3
  174. package/src/duckdb/src/transaction/duck_transaction.cpp +155 -0
  175. package/src/duckdb/src/transaction/duck_transaction_manager.cpp +342 -0
  176. package/src/duckdb/src/transaction/meta_transaction.cpp +3 -0
  177. package/src/duckdb/src/transaction/transaction.cpp +10 -132
  178. package/src/duckdb/src/transaction/transaction_manager.cpp +1 -321
  179. package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +8159 -8028
  180. package/src/duckdb/ub_src_catalog.cpp +4 -0
  181. package/src/duckdb/ub_src_catalog_catalog_entry.cpp +6 -0
  182. package/src/duckdb/ub_src_common.cpp +2 -0
  183. package/src/duckdb/ub_src_function_table_system.cpp +2 -2
  184. package/src/duckdb/ub_src_storage.cpp +2 -0
  185. package/src/duckdb/ub_src_transaction.cpp +4 -0
  186. package/src/duckdb/src/function/table/system/pragma_database_list.cpp +0 -59
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "duckdb",
3
3
  "main": "./lib/duckdb.js",
4
4
  "types": "./lib/duckdb.d.ts",
5
- "version": "0.6.2-dev1832.0",
5
+ "version": "0.6.2-dev1922.0",
6
6
  "description": "DuckDB node.js API",
7
7
  "gypfile": true,
8
8
  "dependencies": {
@@ -33,6 +33,7 @@
33
33
  #include "duckdb/parser/tableref/table_function_ref.hpp"
34
34
  #include "duckdb/planner/operator/logical_get.hpp"
35
35
  #include "duckdb/storage/statistics/base_statistics.hpp"
36
+ #include "duckdb/catalog/catalog_entry/table_function_catalog_entry.hpp"
36
37
  #endif
37
38
 
38
39
  namespace duckdb {
@@ -4,7 +4,6 @@
4
4
  #include "duckdb/catalog/catalog_entry/list.hpp"
5
5
  #include "duckdb/catalog/catalog_set.hpp"
6
6
  #include "duckdb/catalog/default/default_schemas.hpp"
7
- #include "duckdb/catalog/dependency_manager.hpp"
8
7
  #include "duckdb/catalog/catalog_entry/type_catalog_entry.hpp"
9
8
  #include "duckdb/common/exception.hpp"
10
9
  #include "duckdb/main/client_context.hpp"
@@ -32,36 +31,15 @@
32
31
  #include "duckdb/main/attached_database.hpp"
33
32
  #include "duckdb/main/database_manager.hpp"
34
33
  #include "duckdb/function/built_in_functions.hpp"
34
+ #include "duckdb/catalog/similar_catalog_entry.hpp"
35
35
  #include <algorithm>
36
36
 
37
37
  namespace duckdb {
38
38
 
39
- Catalog::Catalog(AttachedDatabase &db)
40
- : schemas(make_unique<CatalogSet>(*this, make_unique<DefaultSchemaGenerator>(*this))),
41
- dependency_manager(make_unique<DependencyManager>(*this)), db(db) {
39
+ Catalog::Catalog(AttachedDatabase &db) : db(db) {
42
40
  }
43
- Catalog::~Catalog() {
44
- }
45
-
46
- void Catalog::Initialize(bool load_builtin) {
47
- // first initialize the base system catalogs
48
- // these are never written to the WAL
49
- // we start these at 1 because deleted entries default to 0
50
- CatalogTransaction data(GetDatabase(), 1, 1);
51
-
52
- // create the default schema
53
- CreateSchemaInfo info;
54
- info.schema = DEFAULT_SCHEMA;
55
- info.internal = true;
56
- CreateSchema(data, &info);
57
-
58
- if (load_builtin) {
59
- // initialize default functions
60
- BuiltinFunctions builtin(data, *this);
61
- builtin.Initialize();
62
- }
63
41
 
64
- Verify();
42
+ Catalog::~Catalog() {
65
43
  }
66
44
 
67
45
  DatabaseInstance &Catalog::GetDatabase() {
@@ -103,22 +81,6 @@ Catalog &Catalog::GetCatalog(ClientContext &context, const string &catalog_name)
103
81
  //===--------------------------------------------------------------------===//
104
82
  // Schema
105
83
  //===--------------------------------------------------------------------===//
106
- CatalogEntry *Catalog::CreateSchema(CatalogTransaction transaction, CreateSchemaInfo *info) {
107
- D_ASSERT(!info->schema.empty());
108
- DependencyList dependencies;
109
- auto entry = make_unique<SchemaCatalogEntry>(this, info->schema, info->internal);
110
- auto result = entry.get();
111
- if (!schemas->CreateEntry(transaction, info->schema, std::move(entry), dependencies)) {
112
- if (info->on_conflict == OnCreateConflict::ERROR_ON_CONFLICT) {
113
- throw CatalogException("Schema with name %s already exists!", info->schema);
114
- } else {
115
- D_ASSERT(info->on_conflict == OnCreateConflict::IGNORE_ON_CONFLICT);
116
- }
117
- return nullptr;
118
- }
119
- return result;
120
- }
121
-
122
84
  CatalogEntry *Catalog::CreateSchema(ClientContext &context, CreateSchemaInfo *info) {
123
85
  return CreateSchema(GetCatalogTransaction(context), info);
124
86
  }
@@ -127,16 +89,6 @@ CatalogTransaction Catalog::GetCatalogTransaction(ClientContext &context) {
127
89
  return CatalogTransaction(*this, context);
128
90
  }
129
91
 
130
- void Catalog::DropSchema(ClientContext &context, DropInfo *info) {
131
- D_ASSERT(!info->name.empty());
132
- ModifyCatalog();
133
- if (!schemas->DropEntry(GetCatalogTransaction(context), info->name, info->cascade)) {
134
- if (!info->if_exists) {
135
- throw CatalogException("Schema with name \"%s\" does not exist!", info->name);
136
- }
137
- }
138
- }
139
-
140
92
  //===--------------------------------------------------------------------===//
141
93
  // Table
142
94
  //===--------------------------------------------------------------------===//
@@ -320,41 +272,6 @@ struct CatalogEntryLookup {
320
272
  }
321
273
  };
322
274
 
323
- //! Return value of SimilarEntryInSchemas
324
- struct SimilarCatalogEntry {
325
- //! The entry name. Empty if absent
326
- string name;
327
- //! The distance to the given name.
328
- idx_t distance;
329
- //! The schema of the entry.
330
- SchemaCatalogEntry *schema;
331
-
332
- DUCKDB_API bool Found() const {
333
- return !name.empty();
334
- }
335
-
336
- DUCKDB_API string GetQualifiedName(bool qualify_catalog, bool qualify_schema) const;
337
- };
338
-
339
- string SimilarCatalogEntry::GetQualifiedName(bool qualify_catalog, bool qualify_schema) const {
340
- D_ASSERT(Found());
341
- string result;
342
- if (qualify_catalog) {
343
- result += schema->catalog->GetName();
344
- }
345
- if (qualify_schema) {
346
- if (!result.empty()) {
347
- result += ".";
348
- }
349
- result += schema->name;
350
- }
351
- if (!result.empty()) {
352
- result += ".";
353
- }
354
- result += name;
355
- return result;
356
- }
357
-
358
275
  //===--------------------------------------------------------------------===//
359
276
  // Generic
360
277
  //===--------------------------------------------------------------------===//
@@ -374,47 +291,30 @@ void Catalog::DropEntry(ClientContext &context, DropInfo *info) {
374
291
  lookup.schema->DropEntry(context, info);
375
292
  }
376
293
 
377
- SchemaCatalogEntry *Catalog::GetSchema(CatalogTransaction transaction, const string &schema_name, bool if_exists,
378
- QueryErrorContext error_context) {
379
- D_ASSERT(!schema_name.empty());
380
- auto entry = schemas->GetEntry(transaction, schema_name);
381
- if (!entry && !if_exists) {
382
- throw CatalogException(error_context.FormatError("Schema with name %s does not exist!", schema_name));
383
- }
384
- return (SchemaCatalogEntry *)entry;
385
- }
386
-
387
294
  SchemaCatalogEntry *Catalog::GetSchema(ClientContext &context, const string &schema_name, bool if_exists,
388
295
  QueryErrorContext error_context) {
389
296
  return GetSchema(GetCatalogTransaction(context), schema_name, if_exists, error_context);
390
297
  }
391
298
 
392
- void Catalog::ScanSchemas(ClientContext &context, std::function<void(CatalogEntry *)> callback) {
393
- // create all default schemas first
394
- schemas->Scan(GetCatalogTransaction(context), [&](CatalogEntry *entry) { callback(entry); });
395
- }
396
-
397
299
  //===--------------------------------------------------------------------===//
398
300
  // Lookup
399
301
  //===--------------------------------------------------------------------===//
400
302
  SimilarCatalogEntry Catalog::SimilarEntryInSchemas(ClientContext &context, const string &entry_name, CatalogType type,
401
303
  const unordered_set<SchemaCatalogEntry *> &schemas) {
402
-
403
- vector<CatalogSet *> sets;
404
- std::transform(schemas.begin(), schemas.end(), std::back_inserter(sets),
405
- [type](SchemaCatalogEntry *s) -> CatalogSet * { return &s->GetCatalogSet(type); });
406
- pair<string, idx_t> most_similar {"", (idx_t)-1};
407
- SchemaCatalogEntry *schema_of_most_similar = nullptr;
304
+ SimilarCatalogEntry result;
408
305
  for (auto schema : schemas) {
409
306
  auto transaction = schema->catalog->GetCatalogTransaction(context);
410
- auto entry = schema->GetCatalogSet(type).SimilarEntry(transaction, entry_name);
411
- if (!entry.first.empty() && (most_similar.first.empty() || most_similar.second > entry.second)) {
412
- most_similar = entry;
413
- schema_of_most_similar = schema;
307
+ auto entry = schema->GetSimilarEntry(transaction, type, entry_name);
308
+ if (!entry.Found()) {
309
+ // no similar entry found
310
+ continue;
311
+ }
312
+ if (!result.Found() || result.distance > entry.distance) {
313
+ result = entry;
314
+ result.schema = schema;
414
315
  }
415
316
  }
416
-
417
- return {most_similar.first, most_similar.second, schema_of_most_similar};
317
+ return result;
418
318
  }
419
319
 
420
320
  string FindExtension(const string &function_name) {
@@ -540,7 +440,7 @@ CatalogEntryLookup Catalog::LookupEntryInternal(CatalogTransaction transaction,
540
440
  if (!schema_entry) {
541
441
  return {nullptr, nullptr};
542
442
  }
543
- auto entry = schema_entry->GetCatalogSet(type).GetEntry(transaction, name);
443
+ auto entry = schema_entry->GetEntry(transaction, type, name);
544
444
  if (!entry) {
545
445
  return {schema_entry, nullptr};
546
446
  }
@@ -671,6 +571,12 @@ LogicalType Catalog::GetType(ClientContext &context, const string &catalog_name,
671
571
  return result_type;
672
572
  }
673
573
 
574
+ vector<SchemaCatalogEntry *> Catalog::GetSchemas(ClientContext &context) {
575
+ vector<SchemaCatalogEntry *> schemas;
576
+ ScanSchemas(context, [&](CatalogEntry *entry) { schemas.push_back((SchemaCatalogEntry *)entry); });
577
+ return schemas;
578
+ }
579
+
674
580
  vector<SchemaCatalogEntry *> Catalog::GetSchemas(ClientContext &context, const string &catalog_name) {
675
581
  vector<Catalog *> catalogs;
676
582
  if (IsInvalidCatalog(catalog_name)) {
@@ -689,7 +595,7 @@ vector<SchemaCatalogEntry *> Catalog::GetSchemas(ClientContext &context, const s
689
595
  }
690
596
  vector<SchemaCatalogEntry *> result;
691
597
  for (auto catalog : catalogs) {
692
- auto schemas = catalog->schemas->GetEntries<SchemaCatalogEntry>(catalog->GetCatalogTransaction(context));
598
+ auto schemas = catalog->GetSchemas(context);
693
599
  result.insert(result.end(), schemas.begin(), schemas.end());
694
600
  }
695
601
  return result;
@@ -702,7 +608,7 @@ vector<SchemaCatalogEntry *> Catalog::GetAllSchemas(ClientContext &context) {
702
608
  auto databases = db_manager.GetDatabases(context);
703
609
  for (auto database : databases) {
704
610
  auto &catalog = database->GetCatalog();
705
- auto new_schemas = catalog.schemas->GetEntries<SchemaCatalogEntry>(catalog.GetCatalogTransaction(context));
611
+ auto new_schemas = catalog.GetSchemas(context);
706
612
  result.insert(result.end(), new_schemas.begin(), new_schemas.end());
707
613
  }
708
614
  sort(result.begin(), result.end(), [&](SchemaCatalogEntry *x, SchemaCatalogEntry *y) {
@@ -728,9 +634,6 @@ void Catalog::Alter(ClientContext &context, AlterInfo *info) {
728
634
  }
729
635
 
730
636
  void Catalog::Verify() {
731
- #ifdef DEBUG
732
- schemas->Verify(*this);
733
- #endif
734
637
  }
735
638
 
736
639
  //===--------------------------------------------------------------------===//
@@ -0,0 +1,27 @@
1
+ #include "duckdb/catalog/catalog_entry/duck_index_entry.hpp"
2
+ #include "duckdb/storage/data_table.hpp"
3
+ #include "duckdb/execution/index/art/art.hpp"
4
+
5
+ namespace duckdb {
6
+
7
+ DuckIndexEntry::DuckIndexEntry(Catalog *catalog, SchemaCatalogEntry *schema, CreateIndexInfo *info)
8
+ : IndexCatalogEntry(catalog, schema, info) {
9
+ }
10
+
11
+ DuckIndexEntry::~DuckIndexEntry() {
12
+ // remove the associated index from the info
13
+ if (!info || !index) {
14
+ return;
15
+ }
16
+ info->indexes.RemoveIndex(index);
17
+ }
18
+
19
+ string DuckIndexEntry::GetSchemaName() {
20
+ return info->schema;
21
+ }
22
+
23
+ string DuckIndexEntry::GetTableName() {
24
+ return info->table;
25
+ }
26
+
27
+ } // namespace duckdb
@@ -0,0 +1,330 @@
1
+ #include "duckdb/catalog/catalog_entry/duck_schema_entry.hpp"
2
+ #include "duckdb/catalog/default/default_functions.hpp"
3
+ #include "duckdb/catalog/default/default_types.hpp"
4
+ #include "duckdb/catalog/default/default_views.hpp"
5
+ #include "duckdb/catalog/catalog_entry/collate_catalog_entry.hpp"
6
+ #include "duckdb/catalog/catalog_entry/copy_function_catalog_entry.hpp"
7
+ #include "duckdb/catalog/catalog_entry/duck_index_entry.hpp"
8
+ #include "duckdb/catalog/catalog_entry/pragma_function_catalog_entry.hpp"
9
+ #include "duckdb/catalog/catalog_entry/sequence_catalog_entry.hpp"
10
+ #include "duckdb/catalog/catalog_entry/table_function_catalog_entry.hpp"
11
+ #include "duckdb/catalog/catalog_entry/type_catalog_entry.hpp"
12
+ #include "duckdb/catalog/catalog_entry/view_catalog_entry.hpp"
13
+ #include "duckdb/catalog/catalog_entry/aggregate_function_catalog_entry.hpp"
14
+ #include "duckdb/catalog/catalog_entry/scalar_function_catalog_entry.hpp"
15
+ #include "duckdb/catalog/catalog_entry/scalar_macro_catalog_entry.hpp"
16
+ #include "duckdb/catalog/catalog_entry/table_macro_catalog_entry.hpp"
17
+ #include "duckdb/catalog/catalog_entry/duck_table_entry.hpp"
18
+ #include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp"
19
+ #include "duckdb/catalog/dependency_list.hpp"
20
+ #include "duckdb/planner/constraints/bound_foreign_key_constraint.hpp"
21
+ #include "duckdb/parser/constraints/foreign_key_constraint.hpp"
22
+ #include "duckdb/parser/parsed_data/alter_table_info.hpp"
23
+ #include "duckdb/parser/parsed_data/create_scalar_function_info.hpp"
24
+ #include "duckdb/storage/data_table.hpp"
25
+ #include "duckdb/planner/parsed_data/bound_create_table_info.hpp"
26
+ #include "duckdb/parser/parsed_data/create_collation_info.hpp"
27
+ #include "duckdb/parser/parsed_data/create_copy_function_info.hpp"
28
+ #include "duckdb/parser/parsed_data/create_index_info.hpp"
29
+ #include "duckdb/parser/parsed_data/create_pragma_function_info.hpp"
30
+ #include "duckdb/parser/parsed_data/create_schema_info.hpp"
31
+ #include "duckdb/parser/parsed_data/create_sequence_info.hpp"
32
+ #include "duckdb/parser/parsed_data/create_table_function_info.hpp"
33
+ #include "duckdb/parser/parsed_data/create_type_info.hpp"
34
+ #include "duckdb/parser/parsed_data/create_view_info.hpp"
35
+ #include "duckdb/parser/parsed_data/drop_info.hpp"
36
+
37
+ namespace duckdb {
38
+
39
+ void FindForeignKeyInformation(CatalogEntry *entry, AlterForeignKeyType alter_fk_type,
40
+ vector<unique_ptr<AlterForeignKeyInfo>> &fk_arrays) {
41
+ if (entry->type != CatalogType::TABLE_ENTRY) {
42
+ return;
43
+ }
44
+ auto *table_entry = (TableCatalogEntry *)entry;
45
+ auto &constraints = table_entry->GetConstraints();
46
+ for (idx_t i = 0; i < constraints.size(); i++) {
47
+ auto &cond = constraints[i];
48
+ if (cond->type != ConstraintType::FOREIGN_KEY) {
49
+ continue;
50
+ }
51
+ auto &fk = (ForeignKeyConstraint &)*cond;
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);
54
+ fk_arrays.push_back(make_unique<AlterForeignKeyInfo>(std::move(alter_data), entry->name, fk.pk_columns,
55
+ fk.fk_columns, fk.info.pk_keys, fk.info.fk_keys,
56
+ alter_fk_type));
57
+ } else if (fk.info.type == ForeignKeyType::FK_TYPE_PRIMARY_KEY_TABLE &&
58
+ alter_fk_type == AlterForeignKeyType::AFT_DELETE) {
59
+ throw CatalogException("Could not drop the table because this table is main key table of the table \"%s\"",
60
+ fk.info.table);
61
+ }
62
+ }
63
+ }
64
+
65
+ DuckSchemaEntry::DuckSchemaEntry(Catalog *catalog, string name_p, bool is_internal)
66
+ : SchemaCatalogEntry(catalog, move(name_p), is_internal),
67
+ tables(*catalog, make_unique<DefaultViewGenerator>(*catalog, this)), indexes(*catalog), table_functions(*catalog),
68
+ copy_functions(*catalog), pragma_functions(*catalog),
69
+ functions(*catalog, make_unique<DefaultFunctionGenerator>(*catalog, this)), sequences(*catalog),
70
+ collations(*catalog), types(*catalog, make_unique<DefaultTypeGenerator>(*catalog, this)) {
71
+ }
72
+
73
+ CatalogEntry *DuckSchemaEntry::AddEntryInternal(CatalogTransaction transaction, unique_ptr<StandardEntry> entry,
74
+ OnCreateConflict on_conflict, DependencyList dependencies) {
75
+ auto entry_name = entry->name;
76
+ auto entry_type = entry->type;
77
+ auto result = entry.get();
78
+
79
+ // first find the set for this entry
80
+ auto &set = GetCatalogSet(entry_type);
81
+ dependencies.AddDependency(this);
82
+ if (on_conflict == OnCreateConflict::REPLACE_ON_CONFLICT) {
83
+ // CREATE OR REPLACE: first try to drop the entry
84
+ auto old_entry = set.GetEntry(transaction, entry_name);
85
+ if (old_entry) {
86
+ if (old_entry->type != entry_type) {
87
+ throw CatalogException("Existing object %s is of type %s, trying to replace with type %s", entry_name,
88
+ CatalogTypeToString(old_entry->type), CatalogTypeToString(entry_type));
89
+ }
90
+ (void)set.DropEntry(transaction, entry_name, false, entry->internal);
91
+ }
92
+ }
93
+ // now try to add the entry
94
+ if (!set.CreateEntry(transaction, entry_name, std::move(entry), dependencies)) {
95
+ // entry already exists!
96
+ if (on_conflict == OnCreateConflict::ERROR_ON_CONFLICT) {
97
+ throw CatalogException("%s with name \"%s\" already exists!", CatalogTypeToString(entry_type), entry_name);
98
+ } else {
99
+ return nullptr;
100
+ }
101
+ }
102
+ return result;
103
+ }
104
+
105
+ CatalogEntry *DuckSchemaEntry::CreateTable(CatalogTransaction transaction, BoundCreateTableInfo *info) {
106
+ auto table = make_unique<DuckTableEntry>(catalog, this, info);
107
+ auto &storage = table->GetStorage();
108
+ storage.info->cardinality = storage.GetTotalRows();
109
+
110
+ CatalogEntry *entry = AddEntryInternal(transaction, std::move(table), info->Base().on_conflict, info->dependencies);
111
+ if (!entry) {
112
+ return nullptr;
113
+ }
114
+
115
+ // add a foreign key constraint in main key table if there is a foreign key constraint
116
+ vector<unique_ptr<AlterForeignKeyInfo>> fk_arrays;
117
+ FindForeignKeyInformation(entry, AlterForeignKeyType::AFT_ADD, fk_arrays);
118
+ for (idx_t i = 0; i < fk_arrays.size(); i++) {
119
+ // alter primary key table
120
+ AlterForeignKeyInfo *fk_info = fk_arrays[i].get();
121
+ catalog->Alter(transaction.GetContext(), fk_info);
122
+
123
+ // make a dependency between this table and referenced table
124
+ auto &set = GetCatalogSet(CatalogType::TABLE_ENTRY);
125
+ info->dependencies.AddDependency(set.GetEntry(transaction, fk_info->name));
126
+ }
127
+ return entry;
128
+ }
129
+
130
+ CatalogEntry *DuckSchemaEntry::CreateFunction(CatalogTransaction transaction, CreateFunctionInfo *info) {
131
+ if (info->on_conflict == OnCreateConflict::ALTER_ON_CONFLICT) {
132
+ // check if the original entry exists
133
+ auto &catalog_set = GetCatalogSet(info->type);
134
+ auto current_entry = catalog_set.GetEntry(transaction, info->name);
135
+ if (current_entry) {
136
+ // the current entry exists - alter it instead
137
+ auto alter_info = info->GetAlterInfo();
138
+ Alter(transaction.GetContext(), alter_info.get());
139
+ return nullptr;
140
+ }
141
+ }
142
+ unique_ptr<StandardEntry> function;
143
+ switch (info->type) {
144
+ case CatalogType::SCALAR_FUNCTION_ENTRY:
145
+ function = make_unique_base<StandardEntry, ScalarFunctionCatalogEntry>(catalog, this,
146
+ (CreateScalarFunctionInfo *)info);
147
+ break;
148
+ case CatalogType::MACRO_ENTRY:
149
+ // create a macro function
150
+ function = make_unique_base<StandardEntry, ScalarMacroCatalogEntry>(catalog, this, (CreateMacroInfo *)info);
151
+ break;
152
+
153
+ case CatalogType::TABLE_MACRO_ENTRY:
154
+ // create a macro table function
155
+ function = make_unique_base<StandardEntry, TableMacroCatalogEntry>(catalog, this, (CreateMacroInfo *)info);
156
+ break;
157
+ case CatalogType::AGGREGATE_FUNCTION_ENTRY:
158
+ D_ASSERT(info->type == CatalogType::AGGREGATE_FUNCTION_ENTRY);
159
+ // create an aggregate function
160
+ function = make_unique_base<StandardEntry, AggregateFunctionCatalogEntry>(catalog, this,
161
+ (CreateAggregateFunctionInfo *)info);
162
+ break;
163
+ default:
164
+ throw InternalException("Unknown function type \"%s\"", CatalogTypeToString(info->type));
165
+ }
166
+ function->internal = info->internal;
167
+ return AddEntry(transaction, std::move(function), info->on_conflict);
168
+ }
169
+
170
+ CatalogEntry *DuckSchemaEntry::AddEntry(CatalogTransaction transaction, unique_ptr<StandardEntry> entry,
171
+ OnCreateConflict on_conflict) {
172
+ DependencyList dependencies;
173
+ return AddEntryInternal(transaction, std::move(entry), on_conflict, dependencies);
174
+ }
175
+
176
+ CatalogEntry *DuckSchemaEntry::CreateSequence(CatalogTransaction transaction, CreateSequenceInfo *info) {
177
+ auto sequence = make_unique<SequenceCatalogEntry>(catalog, this, info);
178
+ return AddEntry(transaction, std::move(sequence), info->on_conflict);
179
+ }
180
+
181
+ CatalogEntry *DuckSchemaEntry::CreateType(CatalogTransaction transaction, CreateTypeInfo *info) {
182
+ auto type_entry = make_unique<TypeCatalogEntry>(catalog, this, info);
183
+ return AddEntry(transaction, std::move(type_entry), info->on_conflict);
184
+ }
185
+
186
+ CatalogEntry *DuckSchemaEntry::CreateView(CatalogTransaction transaction, CreateViewInfo *info) {
187
+ auto view = make_unique<ViewCatalogEntry>(catalog, this, info);
188
+ return AddEntry(transaction, std::move(view), info->on_conflict);
189
+ }
190
+
191
+ CatalogEntry *DuckSchemaEntry::CreateIndex(ClientContext &context, CreateIndexInfo *info, TableCatalogEntry *table) {
192
+ DependencyList dependencies;
193
+ dependencies.AddDependency(table);
194
+ auto index = make_unique<DuckIndexEntry>(catalog, this, info);
195
+ return AddEntryInternal(GetCatalogTransaction(context), std::move(index), info->on_conflict, dependencies);
196
+ }
197
+
198
+ CatalogEntry *DuckSchemaEntry::CreateCollation(CatalogTransaction transaction, CreateCollationInfo *info) {
199
+ auto collation = make_unique<CollateCatalogEntry>(catalog, this, info);
200
+ collation->internal = info->internal;
201
+ return AddEntry(transaction, std::move(collation), info->on_conflict);
202
+ }
203
+
204
+ CatalogEntry *DuckSchemaEntry::CreateTableFunction(CatalogTransaction transaction, CreateTableFunctionInfo *info) {
205
+ auto table_function = make_unique<TableFunctionCatalogEntry>(catalog, this, info);
206
+ table_function->internal = info->internal;
207
+ return AddEntry(transaction, std::move(table_function), info->on_conflict);
208
+ }
209
+
210
+ CatalogEntry *DuckSchemaEntry::CreateCopyFunction(CatalogTransaction transaction, CreateCopyFunctionInfo *info) {
211
+ auto copy_function = make_unique<CopyFunctionCatalogEntry>(catalog, this, info);
212
+ copy_function->internal = info->internal;
213
+ return AddEntry(transaction, std::move(copy_function), info->on_conflict);
214
+ }
215
+
216
+ CatalogEntry *DuckSchemaEntry::CreatePragmaFunction(CatalogTransaction transaction, CreatePragmaFunctionInfo *info) {
217
+ auto pragma_function = make_unique<PragmaFunctionCatalogEntry>(catalog, this, info);
218
+ pragma_function->internal = info->internal;
219
+ return AddEntry(transaction, std::move(pragma_function), info->on_conflict);
220
+ }
221
+
222
+ void DuckSchemaEntry::Alter(ClientContext &context, AlterInfo *info) {
223
+ CatalogType type = info->GetCatalogType();
224
+ auto &set = GetCatalogSet(type);
225
+ auto transaction = GetCatalogTransaction(context);
226
+ if (info->type == AlterType::CHANGE_OWNERSHIP) {
227
+ if (!set.AlterOwnership(transaction, (ChangeOwnershipInfo *)info)) {
228
+ throw CatalogException("Couldn't change ownership!");
229
+ }
230
+ } else {
231
+ string name = info->name;
232
+ if (!set.AlterEntry(transaction, name, info)) {
233
+ throw CatalogException("Entry with name \"%s\" does not exist!", name);
234
+ }
235
+ }
236
+ }
237
+
238
+ void DuckSchemaEntry::Scan(ClientContext &context, CatalogType type,
239
+ const std::function<void(CatalogEntry *)> &callback) {
240
+ auto &set = GetCatalogSet(type);
241
+ set.Scan(GetCatalogTransaction(context), callback);
242
+ }
243
+
244
+ void DuckSchemaEntry::Scan(CatalogType type, const std::function<void(CatalogEntry *)> &callback) {
245
+ auto &set = GetCatalogSet(type);
246
+ set.Scan(callback);
247
+ }
248
+
249
+ void DuckSchemaEntry::DropEntry(ClientContext &context, DropInfo *info) {
250
+ auto &set = GetCatalogSet(info->type);
251
+
252
+ // first find the entry
253
+ auto transaction = GetCatalogTransaction(context);
254
+ auto existing_entry = set.GetEntry(transaction, info->name);
255
+ if (!existing_entry) {
256
+ throw InternalException("Failed to drop entry \"%s\" - entry could not be found", info->name);
257
+ }
258
+ if (existing_entry->type != info->type) {
259
+ throw CatalogException("Existing object %s is of type %s, trying to replace with type %s", info->name,
260
+ CatalogTypeToString(existing_entry->type), CatalogTypeToString(info->type));
261
+ }
262
+
263
+ // if there is a foreign key constraint, get that information
264
+ vector<unique_ptr<AlterForeignKeyInfo>> fk_arrays;
265
+ FindForeignKeyInformation(existing_entry, AlterForeignKeyType::AFT_DELETE, fk_arrays);
266
+
267
+ if (!set.DropEntry(transaction, info->name, info->cascade, info->allow_drop_internal)) {
268
+ throw InternalException("Could not drop element because of an internal error");
269
+ }
270
+
271
+ // remove the foreign key constraint in main key table if main key table's name is valid
272
+ for (idx_t i = 0; i < fk_arrays.size(); i++) {
273
+ // alter primary key table
274
+ catalog->Alter(context, fk_arrays[i].get());
275
+ }
276
+ }
277
+
278
+ CatalogEntry *DuckSchemaEntry::GetEntry(CatalogTransaction transaction, CatalogType type, const string &name) {
279
+ return GetCatalogSet(type).GetEntry(transaction, name);
280
+ }
281
+
282
+ SimilarCatalogEntry DuckSchemaEntry::GetSimilarEntry(CatalogTransaction transaction, CatalogType type,
283
+ const string &name) {
284
+ return GetCatalogSet(type).SimilarEntry(transaction, name);
285
+ }
286
+
287
+ CatalogSet &DuckSchemaEntry::GetCatalogSet(CatalogType type) {
288
+ switch (type) {
289
+ case CatalogType::VIEW_ENTRY:
290
+ case CatalogType::TABLE_ENTRY:
291
+ return tables;
292
+ case CatalogType::INDEX_ENTRY:
293
+ return indexes;
294
+ case CatalogType::TABLE_FUNCTION_ENTRY:
295
+ case CatalogType::TABLE_MACRO_ENTRY:
296
+ return table_functions;
297
+ case CatalogType::COPY_FUNCTION_ENTRY:
298
+ return copy_functions;
299
+ case CatalogType::PRAGMA_FUNCTION_ENTRY:
300
+ return pragma_functions;
301
+ case CatalogType::AGGREGATE_FUNCTION_ENTRY:
302
+ case CatalogType::SCALAR_FUNCTION_ENTRY:
303
+ case CatalogType::MACRO_ENTRY:
304
+ return functions;
305
+ case CatalogType::SEQUENCE_ENTRY:
306
+ return sequences;
307
+ case CatalogType::COLLATION_ENTRY:
308
+ return collations;
309
+ case CatalogType::TYPE_ENTRY:
310
+ return types;
311
+ default:
312
+ throw InternalException("Unsupported catalog type in schema");
313
+ }
314
+ }
315
+
316
+ void DuckSchemaEntry::Verify(Catalog &catalog) {
317
+ CatalogEntry::Verify(catalog);
318
+
319
+ tables.Verify(catalog);
320
+ indexes.Verify(catalog);
321
+ table_functions.Verify(catalog);
322
+ copy_functions.Verify(catalog);
323
+ pragma_functions.Verify(catalog);
324
+ functions.Verify(catalog);
325
+ sequences.Verify(catalog);
326
+ collations.Verify(catalog);
327
+ types.Verify(catalog);
328
+ }
329
+
330
+ } // namespace duckdb