duckdb 0.7.2-dev1734.0 → 0.7.2-dev1867.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 (155) hide show
  1. package/package.json +1 -1
  2. package/src/duckdb/src/catalog/catalog.cpp +27 -27
  3. package/src/duckdb/src/catalog/catalog_entry/duck_schema_entry.cpp +6 -6
  4. package/src/duckdb/src/catalog/catalog_set.cpp +27 -25
  5. package/src/duckdb/src/catalog/default/default_functions.cpp +4 -4
  6. package/src/duckdb/src/catalog/default/default_types.cpp +4 -4
  7. package/src/duckdb/src/catalog/default/default_views.cpp +4 -4
  8. package/src/duckdb/src/catalog/dependency_list.cpp +7 -6
  9. package/src/duckdb/src/catalog/dependency_manager.cpp +44 -38
  10. package/src/duckdb/src/common/serializer/buffered_file_reader.cpp +11 -6
  11. package/src/duckdb/src/common/types/batched_data_collection.cpp +2 -1
  12. package/src/duckdb/src/common/types/column_data_allocator.cpp +1 -0
  13. package/src/duckdb/src/common/types/vector.cpp +2 -2
  14. package/src/duckdb/src/common/types.cpp +2 -2
  15. package/src/duckdb/src/common/vector_operations/vector_copy.cpp +14 -11
  16. package/src/duckdb/src/execution/operator/aggregate/distinct_aggregate_data.cpp +1 -1
  17. package/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +51 -50
  18. package/src/duckdb/src/execution/operator/persistent/physical_batch_insert.cpp +14 -13
  19. package/src/duckdb/src/execution/operator/persistent/physical_insert.cpp +20 -20
  20. package/src/duckdb/src/execution/operator/schema/physical_create_table.cpp +2 -2
  21. package/src/duckdb/src/execution/physical_plan/plan_create_index.cpp +1 -1
  22. package/src/duckdb/src/execution/physical_plan/plan_create_table.cpp +3 -3
  23. package/src/duckdb/src/execution/physical_plan/plan_delete.cpp +1 -1
  24. package/src/duckdb/src/execution/physical_plan/plan_insert.cpp +1 -1
  25. package/src/duckdb/src/execution/physical_plan/plan_update.cpp +1 -1
  26. package/src/duckdb/src/function/aggregate/sorted_aggregate_function.cpp +3 -3
  27. package/src/duckdb/src/function/cast/cast_function_set.cpp +2 -1
  28. package/src/duckdb/src/function/scalar/math/numeric.cpp +57 -0
  29. package/src/duckdb/src/function/scalar/math_functions.cpp +1 -0
  30. package/src/duckdb/src/function/scalar/sequence/nextval.cpp +29 -29
  31. package/src/duckdb/src/function/scalar/string/damerau_levenshtein.cpp +106 -0
  32. package/src/duckdb/src/function/scalar/string/hex.cpp +261 -78
  33. package/src/duckdb/src/function/scalar/string/regexp.cpp +145 -28
  34. package/src/duckdb/src/function/scalar/string_functions.cpp +1 -0
  35. package/src/duckdb/src/function/table/checkpoint.cpp +4 -4
  36. package/src/duckdb/src/function/table/system/duckdb_columns.cpp +24 -24
  37. package/src/duckdb/src/function/table/system/duckdb_constraints.cpp +7 -6
  38. package/src/duckdb/src/function/table/system/duckdb_databases.cpp +1 -1
  39. package/src/duckdb/src/function/table/system/duckdb_dependencies.cpp +11 -11
  40. package/src/duckdb/src/function/table/system/pragma_database_size.cpp +1 -1
  41. package/src/duckdb/src/function/table/system/pragma_table_info.cpp +17 -18
  42. package/src/duckdb/src/function/table/table_scan.cpp +8 -11
  43. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  44. package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +9 -9
  45. package/src/duckdb/src/include/duckdb/catalog/catalog_entry_map.hpp +38 -0
  46. package/src/duckdb/src/include/duckdb/catalog/catalog_transaction.hpp +4 -3
  47. package/src/duckdb/src/include/duckdb/catalog/default/default_functions.hpp +2 -2
  48. package/src/duckdb/src/include/duckdb/catalog/default/default_types.hpp +2 -2
  49. package/src/duckdb/src/include/duckdb/catalog/default/default_views.hpp +2 -2
  50. package/src/duckdb/src/include/duckdb/catalog/dependency.hpp +4 -5
  51. package/src/duckdb/src/include/duckdb/catalog/dependency_list.hpp +4 -5
  52. package/src/duckdb/src/include/duckdb/catalog/dependency_manager.hpp +10 -9
  53. package/src/duckdb/src/include/duckdb/common/allocator.hpp +2 -1
  54. package/src/duckdb/src/include/duckdb/common/bit_utils.hpp +147 -0
  55. package/src/duckdb/src/include/duckdb/common/field_writer.hpp +1 -1
  56. package/src/duckdb/src/include/duckdb/common/helper.hpp +9 -0
  57. package/src/duckdb/src/include/duckdb/common/hugeint.hpp +1 -0
  58. package/src/duckdb/src/include/duckdb/common/optional_ptr.hpp +29 -6
  59. package/src/duckdb/src/include/duckdb/common/serializer/buffered_file_reader.hpp +6 -5
  60. package/src/duckdb/src/include/duckdb/common/serializer.hpp +1 -1
  61. package/src/duckdb/src/include/duckdb/common/string_util.hpp +7 -0
  62. package/src/duckdb/src/include/duckdb/common/types/row_data_collection.hpp +1 -0
  63. package/src/duckdb/src/include/duckdb/common/types.hpp +1 -1
  64. package/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_batch_insert.hpp +2 -2
  65. package/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_insert.hpp +5 -5
  66. package/src/duckdb/src/include/duckdb/execution/operator/schema/physical_create_table.hpp +2 -2
  67. package/src/duckdb/src/include/duckdb/function/cast/default_casts.hpp +3 -2
  68. package/src/duckdb/src/include/duckdb/function/scalar/math_functions.hpp +4 -0
  69. package/src/duckdb/src/include/duckdb/function/scalar/string_functions.hpp +4 -0
  70. package/src/duckdb/src/include/duckdb/main/database_manager.hpp +4 -3
  71. package/src/duckdb/src/include/duckdb/main/query_result.hpp +3 -2
  72. package/src/duckdb/src/include/duckdb/optimizer/filter_combiner.hpp +7 -7
  73. package/src/duckdb/src/include/duckdb/optimizer/matcher/expression_matcher.hpp +11 -11
  74. package/src/duckdb/src/include/duckdb/optimizer/matcher/set_matcher.hpp +8 -8
  75. package/src/duckdb/src/include/duckdb/optimizer/rule/arithmetic_simplification.hpp +1 -1
  76. package/src/duckdb/src/include/duckdb/optimizer/rule/case_simplification.hpp +1 -1
  77. package/src/duckdb/src/include/duckdb/optimizer/rule/comparison_simplification.hpp +1 -1
  78. package/src/duckdb/src/include/duckdb/optimizer/rule/conjunction_simplification.hpp +2 -2
  79. package/src/duckdb/src/include/duckdb/optimizer/rule/constant_folding.hpp +1 -1
  80. package/src/duckdb/src/include/duckdb/optimizer/rule/date_part_simplification.hpp +1 -1
  81. package/src/duckdb/src/include/duckdb/optimizer/rule/distributivity.hpp +1 -1
  82. package/src/duckdb/src/include/duckdb/optimizer/rule/empty_needle_removal.hpp +1 -1
  83. package/src/duckdb/src/include/duckdb/optimizer/rule/enum_comparison.hpp +1 -1
  84. package/src/duckdb/src/include/duckdb/optimizer/rule/equal_or_null_simplification.hpp +1 -1
  85. package/src/duckdb/src/include/duckdb/optimizer/rule/in_clause_simplification.hpp +1 -1
  86. package/src/duckdb/src/include/duckdb/optimizer/rule/like_optimizations.hpp +1 -1
  87. package/src/duckdb/src/include/duckdb/optimizer/rule/move_constants.hpp +1 -1
  88. package/src/duckdb/src/include/duckdb/optimizer/rule/ordered_aggregate_optimizer.hpp +1 -1
  89. package/src/duckdb/src/include/duckdb/optimizer/rule/regex_optimizations.hpp +1 -1
  90. package/src/duckdb/src/include/duckdb/optimizer/rule.hpp +2 -2
  91. package/src/duckdb/src/include/duckdb/parser/base_expression.hpp +1 -1
  92. package/src/duckdb/src/include/duckdb/parser/expression_map.hpp +19 -6
  93. package/src/duckdb/src/include/duckdb/parser/expression_util.hpp +1 -1
  94. package/src/duckdb/src/include/duckdb/planner/expression.hpp +5 -2
  95. package/src/duckdb/src/include/duckdb/planner/expression_binder/base_select_binder.hpp +1 -1
  96. package/src/duckdb/src/include/duckdb/planner/expression_binder/order_binder.hpp +3 -3
  97. package/src/duckdb/src/include/duckdb/storage/buffer/block_handle.hpp +15 -7
  98. package/src/duckdb/src/include/duckdb/storage/buffer/buffer_pool.hpp +3 -0
  99. package/src/duckdb/src/include/duckdb/storage/buffer_manager.hpp +49 -126
  100. package/src/duckdb/src/include/duckdb/storage/compression/chimp/algorithm/chimp128.hpp +1 -0
  101. package/src/duckdb/src/include/duckdb/storage/compression/chimp/algorithm/chimp_utils.hpp +0 -97
  102. package/src/duckdb/src/include/duckdb/storage/compression/patas/algorithm/patas.hpp +1 -0
  103. package/src/duckdb/src/include/duckdb/storage/meta_block_reader.hpp +5 -5
  104. package/src/duckdb/src/include/duckdb/storage/standard_buffer_manager.hpp +159 -0
  105. package/src/duckdb/src/include/duckdb/storage/table/column_segment.hpp +1 -0
  106. package/src/duckdb/src/include/duckdb/transaction/meta_transaction.hpp +6 -5
  107. package/src/duckdb/src/main/client_context.cpp +1 -1
  108. package/src/duckdb/src/main/database.cpp +2 -1
  109. package/src/duckdb/src/main/database_manager.cpp +4 -4
  110. package/src/duckdb/src/optimizer/common_aggregate_optimizer.cpp +2 -2
  111. package/src/duckdb/src/optimizer/cse_optimizer.cpp +4 -4
  112. package/src/duckdb/src/optimizer/deliminator.cpp +13 -11
  113. package/src/duckdb/src/optimizer/expression_rewriter.cpp +2 -2
  114. package/src/duckdb/src/optimizer/filter_combiner.cpp +67 -65
  115. package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +1 -0
  116. package/src/duckdb/src/optimizer/join_order/join_order_optimizer.cpp +26 -25
  117. package/src/duckdb/src/optimizer/matcher/expression_matcher.cpp +23 -21
  118. package/src/duckdb/src/optimizer/rule/arithmetic_simplification.cpp +3 -3
  119. package/src/duckdb/src/optimizer/rule/case_simplification.cpp +2 -2
  120. package/src/duckdb/src/optimizer/rule/comparison_simplification.cpp +6 -7
  121. package/src/duckdb/src/optimizer/rule/conjunction_simplification.cpp +9 -8
  122. package/src/duckdb/src/optimizer/rule/constant_folding.cpp +7 -7
  123. package/src/duckdb/src/optimizer/rule/date_part_simplification.cpp +3 -3
  124. package/src/duckdb/src/optimizer/rule/distributivity.cpp +5 -5
  125. package/src/duckdb/src/optimizer/rule/empty_needle_removal.cpp +6 -6
  126. package/src/duckdb/src/optimizer/rule/enum_comparison.cpp +4 -4
  127. package/src/duckdb/src/optimizer/rule/equal_or_null_simplification.cpp +23 -26
  128. package/src/duckdb/src/optimizer/rule/in_clause_simplification_rule.cpp +2 -3
  129. package/src/duckdb/src/optimizer/rule/like_optimizations.cpp +3 -3
  130. package/src/duckdb/src/optimizer/rule/move_constants.cpp +6 -6
  131. package/src/duckdb/src/optimizer/rule/ordered_aggregate_optimizer.cpp +2 -2
  132. package/src/duckdb/src/optimizer/rule/regex_optimizations.cpp +11 -10
  133. package/src/duckdb/src/parser/expression_util.cpp +6 -6
  134. package/src/duckdb/src/parser/transform/helpers/transform_groupby.cpp +3 -3
  135. package/src/duckdb/src/planner/binder/expression/bind_aggregate_expression.cpp +2 -2
  136. package/src/duckdb/src/planner/binder/query_node/bind_select_node.cpp +3 -3
  137. package/src/duckdb/src/planner/binder/query_node/bind_setop_node.cpp +5 -5
  138. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +2 -2
  139. package/src/duckdb/src/planner/expression_binder/base_select_binder.cpp +4 -4
  140. package/src/duckdb/src/planner/expression_binder/order_binder.cpp +3 -3
  141. package/src/duckdb/src/storage/buffer/block_handle.cpp +7 -6
  142. package/src/duckdb/src/storage/buffer/block_manager.cpp +3 -1
  143. package/src/duckdb/src/storage/buffer/buffer_handle.cpp +1 -0
  144. package/src/duckdb/src/storage/buffer/buffer_pool.cpp +6 -2
  145. package/src/duckdb/src/storage/buffer/buffer_pool_reservation.cpp +7 -4
  146. package/src/duckdb/src/storage/buffer_manager.cpp +35 -726
  147. package/src/duckdb/src/storage/checkpoint_manager.cpp +2 -2
  148. package/src/duckdb/src/storage/meta_block_reader.cpp +6 -5
  149. package/src/duckdb/src/storage/standard_buffer_manager.cpp +801 -0
  150. package/src/duckdb/src/storage/wal_replay.cpp +2 -2
  151. package/src/duckdb/src/transaction/meta_transaction.cpp +13 -13
  152. package/src/duckdb/src/transaction/transaction.cpp +1 -1
  153. package/src/duckdb/src/transaction/transaction_context.cpp +1 -1
  154. package/src/duckdb/ub_src_function_scalar_string.cpp +2 -0
  155. package/src/duckdb/ub_src_storage.cpp +2 -0
@@ -16,7 +16,7 @@ struct DuckDBColumnsData : public GlobalTableFunctionState {
16
16
  DuckDBColumnsData() : offset(0), column_offset(0) {
17
17
  }
18
18
 
19
- vector<CatalogEntry *> entries;
19
+ vector<optional_ptr<CatalogEntry>> entries;
20
20
  idx_t offset;
21
21
  idx_t column_offset;
22
22
  };
@@ -90,12 +90,12 @@ unique_ptr<GlobalTableFunctionState> DuckDBColumnsInit(ClientContext &context, T
90
90
 
91
91
  class ColumnHelper {
92
92
  public:
93
- static unique_ptr<ColumnHelper> Create(CatalogEntry *entry);
93
+ static unique_ptr<ColumnHelper> Create(CatalogEntry &entry);
94
94
 
95
95
  virtual ~ColumnHelper() {
96
96
  }
97
97
 
98
- virtual StandardEntry *Entry() = 0;
98
+ virtual StandardEntry &Entry() = 0;
99
99
  virtual idx_t NumColumns() = 0;
100
100
  virtual const string &ColumnName(idx_t col) = 0;
101
101
  virtual const LogicalType &ColumnType(idx_t col) = 0;
@@ -107,8 +107,8 @@ public:
107
107
 
108
108
  class TableColumnHelper : public ColumnHelper {
109
109
  public:
110
- explicit TableColumnHelper(TableCatalogEntry *entry) : entry(entry) {
111
- for (auto &constraint : entry->GetConstraints()) {
110
+ explicit TableColumnHelper(TableCatalogEntry &entry) : entry(entry) {
111
+ for (auto &constraint : entry.GetConstraints()) {
112
112
  if (constraint->type == ConstraintType::NOT_NULL) {
113
113
  auto &not_null = *reinterpret_cast<NotNullConstraint *>(constraint.get());
114
114
  not_null_cols.insert(not_null.index.index);
@@ -116,20 +116,20 @@ public:
116
116
  }
117
117
  }
118
118
 
119
- StandardEntry *Entry() override {
119
+ StandardEntry &Entry() override {
120
120
  return entry;
121
121
  }
122
122
  idx_t NumColumns() override {
123
- return entry->GetColumns().LogicalColumnCount();
123
+ return entry.GetColumns().LogicalColumnCount();
124
124
  }
125
125
  const string &ColumnName(idx_t col) override {
126
- return entry->GetColumn(LogicalIndex(col)).Name();
126
+ return entry.GetColumn(LogicalIndex(col)).Name();
127
127
  }
128
128
  const LogicalType &ColumnType(idx_t col) override {
129
- return entry->GetColumn(LogicalIndex(col)).Type();
129
+ return entry.GetColumn(LogicalIndex(col)).Type();
130
130
  }
131
131
  const Value ColumnDefault(idx_t col) override {
132
- auto &column = entry->GetColumn(LogicalIndex(col));
132
+ auto &column = entry.GetColumn(LogicalIndex(col));
133
133
  if (column.DefaultValue()) {
134
134
  return Value(column.DefaultValue()->ToString());
135
135
  }
@@ -140,26 +140,26 @@ public:
140
140
  }
141
141
 
142
142
  private:
143
- TableCatalogEntry *entry;
143
+ TableCatalogEntry &entry;
144
144
  std::set<idx_t> not_null_cols;
145
145
  };
146
146
 
147
147
  class ViewColumnHelper : public ColumnHelper {
148
148
  public:
149
- explicit ViewColumnHelper(ViewCatalogEntry *entry) : entry(entry) {
149
+ explicit ViewColumnHelper(ViewCatalogEntry &entry) : entry(entry) {
150
150
  }
151
151
 
152
- StandardEntry *Entry() override {
152
+ StandardEntry &Entry() override {
153
153
  return entry;
154
154
  }
155
155
  idx_t NumColumns() override {
156
- return entry->types.size();
156
+ return entry.types.size();
157
157
  }
158
158
  const string &ColumnName(idx_t col) override {
159
- return entry->aliases[col];
159
+ return entry.aliases[col];
160
160
  }
161
161
  const LogicalType &ColumnType(idx_t col) override {
162
- return entry->types[col];
162
+ return entry.types[col];
163
163
  }
164
164
  const Value ColumnDefault(idx_t col) override {
165
165
  return Value();
@@ -169,15 +169,15 @@ public:
169
169
  }
170
170
 
171
171
  private:
172
- ViewCatalogEntry *entry;
172
+ ViewCatalogEntry &entry;
173
173
  };
174
174
 
175
- unique_ptr<ColumnHelper> ColumnHelper::Create(CatalogEntry *entry) {
176
- switch (entry->type) {
175
+ unique_ptr<ColumnHelper> ColumnHelper::Create(CatalogEntry &entry) {
176
+ switch (entry.type) {
177
177
  case CatalogType::TABLE_ENTRY:
178
- return make_uniq<TableColumnHelper>((TableCatalogEntry *)entry);
178
+ return make_uniq<TableColumnHelper>(entry.Cast<TableCatalogEntry>());
179
179
  case CatalogType::VIEW_ENTRY:
180
- return make_uniq<ViewColumnHelper>((ViewCatalogEntry *)entry);
180
+ return make_uniq<ViewColumnHelper>(entry.Cast<ViewCatalogEntry>());
181
181
  default:
182
182
  throw NotImplementedException("Unsupported catalog type for duckdb_columns");
183
183
  }
@@ -186,7 +186,7 @@ unique_ptr<ColumnHelper> ColumnHelper::Create(CatalogEntry *entry) {
186
186
  void ColumnHelper::WriteColumns(idx_t start_index, idx_t start_col, idx_t end_col, DataChunk &output) {
187
187
  for (idx_t i = start_col; i < end_col; i++) {
188
188
  auto index = start_index + (i - start_col);
189
- auto &entry = *Entry();
189
+ auto &entry = Entry();
190
190
 
191
191
  idx_t col = 0;
192
192
  // database_name, VARCHAR
@@ -284,7 +284,7 @@ void ColumnHelper::WriteColumns(idx_t start_index, idx_t start_col, idx_t end_co
284
284
  }
285
285
 
286
286
  void DuckDBColumnsFunction(ClientContext &context, TableFunctionInput &data_p, DataChunk &output) {
287
- auto &data = (DuckDBColumnsData &)*data_p.global_state;
287
+ auto &data = data_p.global_state->Cast<DuckDBColumnsData>();
288
288
  if (data.offset >= data.entries.size()) {
289
289
  // finished returning values
290
290
  return;
@@ -298,7 +298,7 @@ void DuckDBColumnsFunction(ClientContext &context, TableFunctionInput &data_p, D
298
298
  idx_t column_offset = data.column_offset;
299
299
  idx_t index = 0;
300
300
  while (next < data.entries.size() && index < STANDARD_VECTOR_SIZE) {
301
- auto column_helper = ColumnHelper::Create(data.entries[next]);
301
+ auto column_helper = ColumnHelper::Create(*data.entries[next]);
302
302
  idx_t columns = column_helper->NumColumns();
303
303
 
304
304
  // Check to see if we are going to exceed the maximum index for a DataChunk
@@ -19,7 +19,8 @@
19
19
  namespace duckdb {
20
20
 
21
21
  struct UniqueKeyInfo {
22
- string schema, table;
22
+ string schema;
23
+ string table;
23
24
  vector<LogicalIndex> columns;
24
25
 
25
26
  bool operator==(const UniqueKeyInfo &other) const {
@@ -52,7 +53,7 @@ struct DuckDBConstraintsData : public GlobalTableFunctionState {
52
53
  DuckDBConstraintsData() : offset(0), constraint_offset(0), unique_constraint_offset(0) {
53
54
  }
54
55
 
55
- vector<CatalogEntry *> entries;
56
+ vector<optional_ptr<CatalogEntry>> entries;
56
57
  idx_t offset;
57
58
  idx_t constraint_offset;
58
59
  idx_t unique_constraint_offset;
@@ -125,7 +126,7 @@ unique_ptr<GlobalTableFunctionState> DuckDBConstraintsInit(ClientContext &contex
125
126
  }
126
127
 
127
128
  void DuckDBConstraintsFunction(ClientContext &context, TableFunctionInput &data_p, DataChunk &output) {
128
- auto &data = (DuckDBConstraintsData &)*data_p.global_state;
129
+ auto &data = data_p.global_state->Cast<DuckDBConstraintsData>();
129
130
  if (data.offset >= data.entries.size()) {
130
131
  // finished returning values
131
132
  return;
@@ -134,10 +135,10 @@ void DuckDBConstraintsFunction(ClientContext &context, TableFunctionInput &data_
134
135
  // either fill up the chunk or return all the remaining columns
135
136
  idx_t count = 0;
136
137
  while (data.offset < data.entries.size() && count < STANDARD_VECTOR_SIZE) {
137
- auto &entry = data.entries[data.offset];
138
- D_ASSERT(entry->type == CatalogType::TABLE_ENTRY);
138
+ auto &entry = *data.entries[data.offset];
139
+ D_ASSERT(entry.type == CatalogType::TABLE_ENTRY);
139
140
 
140
- auto &table = entry->Cast<TableCatalogEntry>();
141
+ auto &table = entry.Cast<TableCatalogEntry>();
141
142
  auto &constraints = table.GetConstraints();
142
143
  bool is_duck_table = table.IsDuckTable();
143
144
  for (; data.constraint_offset < constraints.size() && count < STANDARD_VECTOR_SIZE; data.constraint_offset++) {
@@ -8,7 +8,7 @@ struct DuckDBDatabasesData : public GlobalTableFunctionState {
8
8
  DuckDBDatabasesData() : offset(0) {
9
9
  }
10
10
 
11
- vector<AttachedDatabase *> entries;
11
+ vector<optional_ptr<AttachedDatabase>> entries;
12
12
  idx_t offset;
13
13
  };
14
14
 
@@ -9,8 +9,12 @@
9
9
  namespace duckdb {
10
10
 
11
11
  struct DependencyInformation {
12
- CatalogEntry *object;
13
- CatalogEntry *dependent;
12
+ DependencyInformation(CatalogEntry &object, CatalogEntry &dependent, DependencyType type)
13
+ : object(object), dependent(dependent), type(type) {
14
+ }
15
+
16
+ CatalogEntry &object;
17
+ CatalogEntry &dependent;
14
18
  DependencyType type;
15
19
  };
16
20
 
@@ -54,14 +58,10 @@ unique_ptr<GlobalTableFunctionState> DuckDBDependenciesInit(ClientContext &conte
54
58
  // scan all the schemas and collect them
55
59
  auto &catalog = Catalog::GetCatalog(context, INVALID_CATALOG);
56
60
  if (catalog.IsDuckCatalog()) {
57
- auto &duck_catalog = (DuckCatalog &)catalog;
61
+ auto &duck_catalog = catalog.Cast<DuckCatalog>();
58
62
  auto &dependency_manager = duck_catalog.GetDependencyManager();
59
- dependency_manager.Scan([&](CatalogEntry *obj, CatalogEntry *dependent, DependencyType type) {
60
- DependencyInformation info;
61
- info.object = obj;
62
- info.dependent = dependent;
63
- info.type = type;
64
- result->entries.push_back(info);
63
+ dependency_manager.Scan([&](CatalogEntry &obj, CatalogEntry &dependent, DependencyType type) {
64
+ result->entries.emplace_back(obj, dependent, type);
65
65
  });
66
66
  }
67
67
 
@@ -84,13 +84,13 @@ void DuckDBDependenciesFunction(ClientContext &context, TableFunctionInput &data
84
84
  // classid, LogicalType::BIGINT
85
85
  output.SetValue(0, count, Value::BIGINT(0));
86
86
  // objid, LogicalType::BIGINT
87
- output.SetValue(1, count, Value::BIGINT(entry.object->oid));
87
+ output.SetValue(1, count, Value::BIGINT(entry.object.oid));
88
88
  // objsubid, LogicalType::INTEGER
89
89
  output.SetValue(2, count, Value::INTEGER(0));
90
90
  // refclassid, LogicalType::BIGINT
91
91
  output.SetValue(3, count, Value::BIGINT(0));
92
92
  // refobjid, LogicalType::BIGINT
93
- output.SetValue(4, count, Value::BIGINT(entry.dependent->oid));
93
+ output.SetValue(4, count, Value::BIGINT(entry.dependent.oid));
94
94
  // refobjsubid, LogicalType::INTEGER
95
95
  output.SetValue(5, count, Value::INTEGER(0));
96
96
  // deptype, LogicalType::VARCHAR
@@ -15,7 +15,7 @@ struct PragmaDatabaseSizeData : public GlobalTableFunctionState {
15
15
  }
16
16
 
17
17
  idx_t index;
18
- vector<AttachedDatabase *> databases;
18
+ vector<optional_ptr<AttachedDatabase>> databases;
19
19
  Value memory_usage;
20
20
  Value memory_limit;
21
21
  };
@@ -17,10 +17,10 @@
17
17
  namespace duckdb {
18
18
 
19
19
  struct PragmaTableFunctionData : public TableFunctionData {
20
- explicit PragmaTableFunctionData(CatalogEntry *entry_p) : entry(entry_p) {
20
+ explicit PragmaTableFunctionData(CatalogEntry &entry_p) : entry(entry_p) {
21
21
  }
22
22
 
23
- CatalogEntry *entry;
23
+ CatalogEntry &entry;
24
24
  };
25
25
 
26
26
  struct PragmaTableOperatorData : public GlobalTableFunctionState {
@@ -55,20 +55,20 @@ static unique_ptr<FunctionData> PragmaTableInfoBind(ClientContext &context, Tabl
55
55
  // look up the table name in the catalog
56
56
  Binder::BindSchemaOrCatalog(context, qname.catalog, qname.schema);
57
57
  auto entry = Catalog::GetEntry(context, CatalogType::TABLE_ENTRY, qname.catalog, qname.schema, qname.name);
58
- return make_uniq<PragmaTableFunctionData>(entry);
58
+ return make_uniq<PragmaTableFunctionData>(*entry);
59
59
  }
60
60
 
61
61
  unique_ptr<GlobalTableFunctionState> PragmaTableInfoInit(ClientContext &context, TableFunctionInitInput &input) {
62
62
  return make_uniq<PragmaTableOperatorData>();
63
63
  }
64
64
 
65
- static void CheckConstraints(TableCatalogEntry *table, const ColumnDefinition &column, bool &out_not_null,
65
+ static void CheckConstraints(TableCatalogEntry &table, const ColumnDefinition &column, bool &out_not_null,
66
66
  bool &out_pk) {
67
67
  out_not_null = false;
68
68
  out_pk = false;
69
69
  // check all constraints
70
70
  // FIXME: this is pretty inefficient, it probably doesn't matter
71
- for (auto &constraint : table->GetConstraints()) {
71
+ for (auto &constraint : table.GetConstraints()) {
72
72
  switch (constraint->type) {
73
73
  case ConstraintType::NOT_NULL: {
74
74
  auto &not_null = constraint->Cast<NotNullConstraint>();
@@ -79,7 +79,6 @@ static void CheckConstraints(TableCatalogEntry *table, const ColumnDefinition &c
79
79
  }
80
80
  case ConstraintType::UNIQUE: {
81
81
  auto &unique = constraint->Cast<UniqueConstraint>();
82
-
83
82
  if (unique.is_primary_key) {
84
83
  if (unique.index == column.Logical()) {
85
84
  out_pk = true;
@@ -96,20 +95,20 @@ static void CheckConstraints(TableCatalogEntry *table, const ColumnDefinition &c
96
95
  }
97
96
  }
98
97
 
99
- static void PragmaTableInfoTable(PragmaTableOperatorData &data, TableCatalogEntry *table, DataChunk &output) {
100
- if (data.offset >= table->GetColumns().LogicalColumnCount()) {
98
+ static void PragmaTableInfoTable(PragmaTableOperatorData &data, TableCatalogEntry &table, DataChunk &output) {
99
+ if (data.offset >= table.GetColumns().LogicalColumnCount()) {
101
100
  // finished returning values
102
101
  return;
103
102
  }
104
103
  // start returning values
105
104
  // either fill up the chunk or return all the remaining columns
106
- idx_t next = MinValue<idx_t>(data.offset + STANDARD_VECTOR_SIZE, table->GetColumns().LogicalColumnCount());
105
+ idx_t next = MinValue<idx_t>(data.offset + STANDARD_VECTOR_SIZE, table.GetColumns().LogicalColumnCount());
107
106
  output.SetCardinality(next - data.offset);
108
107
 
109
108
  for (idx_t i = data.offset; i < next; i++) {
110
109
  bool not_null, pk;
111
110
  auto index = i - data.offset;
112
- auto &column = table->GetColumn(LogicalIndex(i));
111
+ auto &column = table.GetColumn(LogicalIndex(i));
113
112
  D_ASSERT(column.Oid() < (idx_t)NumericLimits<int32_t>::Maximum());
114
113
  CheckConstraints(table, column, not_null, pk);
115
114
 
@@ -131,20 +130,20 @@ static void PragmaTableInfoTable(PragmaTableOperatorData &data, TableCatalogEntr
131
130
  data.offset = next;
132
131
  }
133
132
 
134
- static void PragmaTableInfoView(PragmaTableOperatorData &data, ViewCatalogEntry *view, DataChunk &output) {
135
- if (data.offset >= view->types.size()) {
133
+ static void PragmaTableInfoView(PragmaTableOperatorData &data, ViewCatalogEntry &view, DataChunk &output) {
134
+ if (data.offset >= view.types.size()) {
136
135
  // finished returning values
137
136
  return;
138
137
  }
139
138
  // start returning values
140
139
  // either fill up the chunk or return all the remaining columns
141
- idx_t next = MinValue<idx_t>(data.offset + STANDARD_VECTOR_SIZE, view->types.size());
140
+ idx_t next = MinValue<idx_t>(data.offset + STANDARD_VECTOR_SIZE, view.types.size());
142
141
  output.SetCardinality(next - data.offset);
143
142
 
144
143
  for (idx_t i = data.offset; i < next; i++) {
145
144
  auto index = i - data.offset;
146
- auto type = view->types[i];
147
- auto &name = view->aliases[i];
145
+ auto type = view.types[i];
146
+ auto &name = view.aliases[i];
148
147
  // return values:
149
148
  // "cid", PhysicalType::INT32
150
149
 
@@ -166,12 +165,12 @@ static void PragmaTableInfoView(PragmaTableOperatorData &data, ViewCatalogEntry
166
165
  static void PragmaTableInfoFunction(ClientContext &context, TableFunctionInput &data_p, DataChunk &output) {
167
166
  auto &bind_data = (PragmaTableFunctionData &)*data_p.bind_data;
168
167
  auto &state = data_p.global_state->Cast<PragmaTableOperatorData>();
169
- switch (bind_data.entry->type) {
168
+ switch (bind_data.entry.type) {
170
169
  case CatalogType::TABLE_ENTRY:
171
- PragmaTableInfoTable(state, (TableCatalogEntry *)bind_data.entry, output);
170
+ PragmaTableInfoTable(state, bind_data.entry.Cast<TableCatalogEntry>(), output);
172
171
  break;
173
172
  case CatalogType::VIEW_ENTRY:
174
- PragmaTableInfoView(state, (ViewCatalogEntry *)bind_data.entry, output);
173
+ PragmaTableInfoView(state, bind_data.entry.Cast<ViewCatalogEntry>(), output);
175
174
  break;
176
175
  default:
177
176
  throw NotImplementedException("Unimplemented catalog type for pragma_table_info");
@@ -185,7 +185,7 @@ BindInfo TableScanGetBindInfo(const FunctionData *bind_data) {
185
185
 
186
186
  void TableScanDependency(DependencyList &entries, const FunctionData *bind_data_p) {
187
187
  auto &bind_data = bind_data_p->Cast<TableScanBindData>();
188
- entries.AddDependency(bind_data.table);
188
+ entries.AddDependency(*bind_data.table);
189
189
  }
190
190
 
191
191
  unique_ptr<NodeStatistics> TableScanCardinality(ClientContext &context, const FunctionData *bind_data_p) {
@@ -302,30 +302,27 @@ void TableScanPushdownComplexFilter(ClientContext &context, LogicalGet &get, Fun
302
302
  ExpressionType low_comparison_type = ExpressionType::INVALID, high_comparison_type = ExpressionType::INVALID;
303
303
  // try to find a matching index for any of the filter expressions
304
304
  for (auto &filter : filters) {
305
- auto expr = filter.get();
305
+ auto &expr = *filter;
306
306
 
307
307
  // create a matcher for a comparison with a constant
308
308
  ComparisonExpressionMatcher matcher;
309
309
  // match on a comparison type
310
310
  matcher.expr_type = make_uniq<ComparisonExpressionTypeMatcher>();
311
311
  // match on a constant comparison with the indexed expression
312
- matcher.matchers.push_back(make_uniq<ExpressionEqualityMatcher>(index_expression.get()));
312
+ matcher.matchers.push_back(make_uniq<ExpressionEqualityMatcher>(*index_expression));
313
313
  matcher.matchers.push_back(make_uniq<ConstantExpressionMatcher>());
314
314
 
315
315
  matcher.policy = SetMatcher::Policy::UNORDERED;
316
316
 
317
- vector<Expression *> bindings;
317
+ vector<reference<Expression>> bindings;
318
318
  if (matcher.Match(expr, bindings)) {
319
319
  // range or equality comparison with constant value
320
320
  // we can use our index here
321
321
  // bindings[0] = the expression
322
322
  // bindings[1] = the index expression
323
323
  // bindings[2] = the constant
324
- auto &comparison = bindings[0]->Cast<BoundComparisonExpression>();
325
- D_ASSERT(bindings[0]->GetExpressionClass() == ExpressionClass::BOUND_COMPARISON);
326
- D_ASSERT(bindings[2]->type == ExpressionType::VALUE_CONSTANT);
327
-
328
- auto constant_value = bindings[2]->Cast<BoundConstantExpression>().value;
324
+ auto &comparison = bindings[0].get().Cast<BoundComparisonExpression>();
325
+ auto constant_value = bindings[2].get().Cast<BoundConstantExpression>().value;
329
326
  auto comparison_type = comparison.type;
330
327
  if (comparison.left->type == ExpressionType::VALUE_CONSTANT) {
331
328
  // the expression is on the right side, we flip them around
@@ -346,9 +343,9 @@ void TableScanPushdownComplexFilter(ClientContext &context, LogicalGet &get, Fun
346
343
  high_value = constant_value;
347
344
  high_comparison_type = comparison_type;
348
345
  }
349
- } else if (expr->type == ExpressionType::COMPARE_BETWEEN) {
346
+ } else if (expr.type == ExpressionType::COMPARE_BETWEEN) {
350
347
  // BETWEEN expression
351
- auto &between = expr->Cast<BoundBetweenExpression>();
348
+ auto &between = expr.Cast<BoundBetweenExpression>();
352
349
  if (!between.input->Equals(index_expression.get())) {
353
350
  // expression doesn't match the current index expression
354
351
  continue;
@@ -1,8 +1,8 @@
1
1
  #ifndef DUCKDB_VERSION
2
- #define DUCKDB_VERSION "0.7.2-dev1734"
2
+ #define DUCKDB_VERSION "0.7.2-dev1867"
3
3
  #endif
4
4
  #ifndef DUCKDB_SOURCE_ID
5
- #define DUCKDB_SOURCE_ID "e8610c85fb"
5
+ #define DUCKDB_SOURCE_ID "084890df27"
6
6
  #endif
7
7
  #include "duckdb/function/table/system_functions.hpp"
8
8
  #include "duckdb/main/database.hpp"
@@ -146,31 +146,31 @@ public:
146
146
  DUCKDB_API CatalogEntry *CreateIndex(ClientContext &context, CreateIndexInfo *info);
147
147
 
148
148
  //! Creates a table in the catalog.
149
- DUCKDB_API CatalogEntry *CreateTable(CatalogTransaction transaction, SchemaCatalogEntry *schema,
149
+ DUCKDB_API CatalogEntry *CreateTable(CatalogTransaction transaction, SchemaCatalogEntry &schema,
150
150
  BoundCreateTableInfo *info);
151
151
  //! Create a table function in the catalog
152
- DUCKDB_API CatalogEntry *CreateTableFunction(CatalogTransaction transaction, SchemaCatalogEntry *schema,
152
+ DUCKDB_API CatalogEntry *CreateTableFunction(CatalogTransaction transaction, SchemaCatalogEntry &schema,
153
153
  CreateTableFunctionInfo *info);
154
154
  //! Create a copy function in the catalog
155
- DUCKDB_API CatalogEntry *CreateCopyFunction(CatalogTransaction transaction, SchemaCatalogEntry *schema,
155
+ DUCKDB_API CatalogEntry *CreateCopyFunction(CatalogTransaction transaction, SchemaCatalogEntry &schema,
156
156
  CreateCopyFunctionInfo *info);
157
157
  //! Create a pragma function in the catalog
158
- DUCKDB_API CatalogEntry *CreatePragmaFunction(CatalogTransaction transaction, SchemaCatalogEntry *schema,
158
+ DUCKDB_API CatalogEntry *CreatePragmaFunction(CatalogTransaction transaction, SchemaCatalogEntry &schema,
159
159
  CreatePragmaFunctionInfo *info);
160
160
  //! Create a scalar or aggregate function in the catalog
161
- DUCKDB_API CatalogEntry *CreateFunction(CatalogTransaction transaction, SchemaCatalogEntry *schema,
161
+ DUCKDB_API CatalogEntry *CreateFunction(CatalogTransaction transaction, SchemaCatalogEntry &schema,
162
162
  CreateFunctionInfo *info);
163
163
  //! Creates a view in the catalog
164
- DUCKDB_API CatalogEntry *CreateView(CatalogTransaction transaction, SchemaCatalogEntry *schema,
164
+ DUCKDB_API CatalogEntry *CreateView(CatalogTransaction transaction, SchemaCatalogEntry &schema,
165
165
  CreateViewInfo *info);
166
166
  //! Creates a table in the catalog.
167
- DUCKDB_API CatalogEntry *CreateSequence(CatalogTransaction transaction, SchemaCatalogEntry *schema,
167
+ DUCKDB_API CatalogEntry *CreateSequence(CatalogTransaction transaction, SchemaCatalogEntry &schema,
168
168
  CreateSequenceInfo *info);
169
169
  //! Creates a enum in the catalog.
170
- DUCKDB_API CatalogEntry *CreateType(CatalogTransaction transaction, SchemaCatalogEntry *schema,
170
+ DUCKDB_API CatalogEntry *CreateType(CatalogTransaction transaction, SchemaCatalogEntry &schema,
171
171
  CreateTypeInfo *info);
172
172
  //! Creates a collation in the catalog
173
- DUCKDB_API CatalogEntry *CreateCollation(CatalogTransaction transaction, SchemaCatalogEntry *schema,
173
+ DUCKDB_API CatalogEntry *CreateCollation(CatalogTransaction transaction, SchemaCatalogEntry &schema,
174
174
  CreateCollationInfo *info);
175
175
 
176
176
  //! Drops an entry from the catalog
@@ -0,0 +1,38 @@
1
+ //===----------------------------------------------------------------------===//
2
+ // DuckDB
3
+ //
4
+ // duckdb/catalog/catalog_entry_map.hpp
5
+ //
6
+ //
7
+ //===----------------------------------------------------------------------===//
8
+
9
+ #pragma once
10
+
11
+ #include "duckdb/common/common.hpp"
12
+ #include "duckdb/common/unordered_set.hpp"
13
+ #include "duckdb/common/unordered_map.hpp"
14
+
15
+ namespace duckdb {
16
+ class CatalogEntry;
17
+
18
+ struct CatalogEntryHashFunction {
19
+ uint64_t operator()(const reference<CatalogEntry> &a) const {
20
+ std::hash<void *> hash_func;
21
+ return hash_func((void *)&a.get());
22
+ }
23
+ };
24
+
25
+ struct CatalogEntryEquality {
26
+ bool operator()(const reference<CatalogEntry> &a, const reference<CatalogEntry> &b) const {
27
+ return RefersToSameObject(a, b);
28
+ }
29
+ };
30
+
31
+ using catalog_entry_set_t = unordered_set<reference<CatalogEntry>, CatalogEntryHashFunction, CatalogEntryEquality>;
32
+
33
+ template <typename T>
34
+ using catalog_entry_map_t = unordered_map<reference<CatalogEntry>, T, CatalogEntryHashFunction, CatalogEntryEquality>;
35
+
36
+ using catalog_entry_vector_t = vector<reference<CatalogEntry>>;
37
+
38
+ } // namespace duckdb
@@ -9,6 +9,7 @@
9
9
  #pragma once
10
10
 
11
11
  #include "duckdb/common/common.hpp"
12
+ #include "duckdb/common/optional_ptr.hpp"
12
13
 
13
14
  namespace duckdb {
14
15
  class Catalog;
@@ -20,9 +21,9 @@ struct CatalogTransaction {
20
21
  CatalogTransaction(Catalog &catalog, ClientContext &context);
21
22
  CatalogTransaction(DatabaseInstance &db, transaction_t transaction_id_p, transaction_t start_time_p);
22
23
 
23
- DatabaseInstance *db;
24
- ClientContext *context;
25
- Transaction *transaction;
24
+ optional_ptr<DatabaseInstance> db;
25
+ optional_ptr<ClientContext> context;
26
+ optional_ptr<Transaction> transaction;
26
27
  transaction_t transaction_id;
27
28
  transaction_t start_time;
28
29
 
@@ -23,9 +23,9 @@ struct DefaultMacro {
23
23
 
24
24
  class DefaultFunctionGenerator : public DefaultGenerator {
25
25
  public:
26
- DefaultFunctionGenerator(Catalog &catalog, SchemaCatalogEntry *schema);
26
+ DefaultFunctionGenerator(Catalog &catalog, SchemaCatalogEntry &schema);
27
27
 
28
- SchemaCatalogEntry *schema;
28
+ SchemaCatalogEntry &schema;
29
29
 
30
30
  DUCKDB_API static unique_ptr<CreateMacroInfo> CreateInternalMacroInfo(DefaultMacro &default_macro);
31
31
  DUCKDB_API static unique_ptr<CreateMacroInfo> CreateInternalTableMacroInfo(DefaultMacro &default_macro);
@@ -16,9 +16,9 @@ class SchemaCatalogEntry;
16
16
 
17
17
  class DefaultTypeGenerator : public DefaultGenerator {
18
18
  public:
19
- DefaultTypeGenerator(Catalog &catalog, SchemaCatalogEntry *schema);
19
+ DefaultTypeGenerator(Catalog &catalog, SchemaCatalogEntry &schema);
20
20
 
21
- SchemaCatalogEntry *schema;
21
+ SchemaCatalogEntry &schema;
22
22
 
23
23
  public:
24
24
  DUCKDB_API static LogicalTypeId GetDefaultType(const string &name);
@@ -16,9 +16,9 @@ class SchemaCatalogEntry;
16
16
 
17
17
  class DefaultViewGenerator : public DefaultGenerator {
18
18
  public:
19
- DefaultViewGenerator(Catalog &catalog, SchemaCatalogEntry *schema);
19
+ DefaultViewGenerator(Catalog &catalog, SchemaCatalogEntry &schema);
20
20
 
21
- SchemaCatalogEntry *schema;
21
+ SchemaCatalogEntry &schema;
22
22
 
23
23
  public:
24
24
  unique_ptr<CatalogEntry> CreateDefaultEntry(ClientContext &context, const string &entry_name) override;
@@ -22,13 +22,13 @@ enum class DependencyType {
22
22
  };
23
23
 
24
24
  struct Dependency {
25
- Dependency(CatalogEntry *entry, DependencyType dependency_type = DependencyType::DEPENDENCY_REGULAR)
25
+ Dependency(CatalogEntry &entry, DependencyType dependency_type = DependencyType::DEPENDENCY_REGULAR)
26
26
  : // NOLINT: Allow implicit conversion from `CatalogEntry`
27
27
  entry(entry), dependency_type(dependency_type) {
28
28
  }
29
29
 
30
30
  //! The catalog entry this depends on
31
- CatalogEntry *entry;
31
+ reference<CatalogEntry> entry;
32
32
  //! The type of dependency
33
33
  DependencyType dependency_type;
34
34
  };
@@ -36,16 +36,15 @@ struct Dependency {
36
36
  struct DependencyHashFunction {
37
37
  uint64_t operator()(const Dependency &a) const {
38
38
  std::hash<void *> hash_func;
39
- return hash_func((void *)a.entry);
39
+ return hash_func((void *)&a.entry.get());
40
40
  }
41
41
  };
42
42
 
43
43
  struct DependencyEquality {
44
44
  bool operator()(const Dependency &a, const Dependency &b) const {
45
- return a.entry == b.entry;
45
+ return RefersToSameObject(a.entry, b.entry);
46
46
  }
47
47
  };
48
-
49
48
  using dependency_set_t = unordered_set<Dependency, DependencyHashFunction, DependencyEquality>;
50
49
 
51
50
  } // namespace duckdb
@@ -8,8 +8,7 @@
8
8
 
9
9
  #pragma once
10
10
 
11
- #include "duckdb/common/common.hpp"
12
- #include "duckdb/common/unordered_set.hpp"
11
+ #include "duckdb/catalog/catalog_entry_map.hpp"
13
12
 
14
13
  namespace duckdb {
15
14
  class Catalog;
@@ -20,11 +19,11 @@ class DependencyList {
20
19
  friend class DependencyManager;
21
20
 
22
21
  public:
23
- DUCKDB_API void AddDependency(CatalogEntry *entry);
22
+ DUCKDB_API void AddDependency(CatalogEntry &entry);
24
23
 
25
- DUCKDB_API void VerifyDependencies(Catalog *catalog, const string &name);
24
+ DUCKDB_API void VerifyDependencies(Catalog &catalog, const string &name);
26
25
 
27
26
  private:
28
- unordered_set<CatalogEntry *> set;
27
+ catalog_entry_set_t set;
29
28
  };
30
29
  } // namespace duckdb