duckdb 0.8.2-dev4025.0 → 0.8.2-dev4142.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.
- package/binding.gyp +1 -0
- package/package.json +1 -1
- package/src/duckdb/extension/json/buffered_json_reader.cpp +76 -74
- package/src/duckdb/extension/json/include/buffered_json_reader.hpp +35 -32
- package/src/duckdb/extension/json/include/json_scan.hpp +9 -6
- package/src/duckdb/extension/json/json_scan.cpp +124 -121
- package/src/duckdb/src/catalog/catalog.cpp +20 -0
- package/src/duckdb/src/catalog/catalog_entry/duck_index_entry.cpp +5 -0
- package/src/duckdb/src/common/arrow/arrow_converter.cpp +3 -0
- package/src/duckdb/src/common/radix_partitioning.cpp +1 -1
- package/src/duckdb/src/common/sort/partition_state.cpp +5 -1
- package/src/duckdb/src/core_functions/aggregate/holistic/mode.cpp +1 -1
- package/src/duckdb/src/core_functions/function_list.cpp +7 -0
- package/src/duckdb/src/core_functions/scalar/list/list_cosine_similarity.cpp +78 -0
- package/src/duckdb/src/core_functions/scalar/list/list_distance.cpp +72 -0
- package/src/duckdb/src/core_functions/scalar/list/list_inner_product.cpp +70 -0
- package/src/duckdb/src/execution/index/art/art.cpp +111 -92
- package/src/duckdb/src/execution/index/art/iterator.cpp +21 -27
- package/src/duckdb/src/execution/index/art/leaf.cpp +72 -153
- package/src/duckdb/src/execution/index/art/node.cpp +109 -203
- package/src/duckdb/src/execution/index/art/node16.cpp +32 -64
- package/src/duckdb/src/execution/index/art/node256.cpp +38 -53
- package/src/duckdb/src/execution/index/art/node4.cpp +31 -62
- package/src/duckdb/src/execution/index/art/node48.cpp +43 -65
- package/src/duckdb/src/execution/index/art/prefix.cpp +70 -141
- package/src/duckdb/src/execution/index/fixed_size_allocator.cpp +345 -0
- package/src/duckdb/src/execution/index/fixed_size_buffer.cpp +74 -0
- package/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +1 -1
- package/src/duckdb/src/execution/operator/schema/physical_create_art_index.cpp +1 -1
- package/src/duckdb/src/function/table/system/duckdb_columns.cpp +3 -1
- package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
- package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +1 -0
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_index_entry.hpp +2 -0
- package/src/duckdb/src/include/duckdb/common/optional_idx.hpp +1 -1
- package/src/duckdb/src/include/duckdb/core_functions/scalar/list_functions.hpp +51 -0
- package/src/duckdb/src/include/duckdb/execution/index/art/art.hpp +17 -7
- package/src/duckdb/src/include/duckdb/execution/index/art/iterator.hpp +5 -5
- package/src/duckdb/src/include/duckdb/execution/index/art/leaf.hpp +10 -16
- package/src/duckdb/src/include/duckdb/execution/index/art/node.hpp +38 -116
- package/src/duckdb/src/include/duckdb/execution/index/art/node16.hpp +17 -18
- package/src/duckdb/src/include/duckdb/execution/index/art/node256.hpp +17 -23
- package/src/duckdb/src/include/duckdb/execution/index/art/node4.hpp +17 -18
- package/src/duckdb/src/include/duckdb/execution/index/art/node48.hpp +17 -24
- package/src/duckdb/src/include/duckdb/execution/index/art/prefix.hpp +16 -22
- package/src/duckdb/src/include/duckdb/execution/index/fixed_size_allocator.hpp +126 -0
- package/src/duckdb/src/include/duckdb/execution/index/fixed_size_buffer.hpp +79 -0
- package/src/duckdb/src/include/duckdb/execution/index/index_pointer.hpp +96 -0
- package/src/duckdb/src/include/duckdb/main/extension_entries.hpp +1 -0
- package/src/duckdb/src/include/duckdb/main/extension_helper.hpp +1 -0
- package/src/duckdb/src/include/duckdb/parallel/task_scheduler.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/block.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/index.hpp +10 -8
- package/src/duckdb/src/include/duckdb/storage/metadata/metadata_writer.hpp +3 -0
- package/src/duckdb/src/main/extension/extension_helper.cpp +17 -0
- package/src/duckdb/src/main/extension/extension_install.cpp +5 -3
- package/src/duckdb/src/main/extension/extension_load.cpp +3 -3
- package/src/duckdb/src/planner/binder/expression/bind_function_expression.cpp +14 -5
- package/src/duckdb/src/storage/checkpoint/table_data_writer.cpp +2 -3
- package/src/duckdb/src/storage/checkpoint_manager.cpp +16 -21
- package/src/duckdb/src/storage/data_table.cpp +3 -3
- package/src/duckdb/src/storage/index.cpp +7 -1
- package/src/duckdb/src/storage/metadata/metadata_manager.cpp +21 -21
- package/src/duckdb/src/storage/standard_buffer_manager.cpp +0 -8
- package/src/duckdb/src/storage/storage_info.cpp +1 -1
- package/src/duckdb/src/storage/table_index_list.cpp +1 -1
- package/src/duckdb/src/transaction/commit_state.cpp +5 -1
- package/src/duckdb/ub_src_core_functions_scalar_list.cpp +6 -0
- package/src/duckdb/ub_src_execution_index.cpp +4 -0
- package/src/duckdb/ub_src_execution_index_art.cpp +0 -2
- package/src/duckdb/src/execution/index/art/fixed_size_allocator.cpp +0 -238
- package/src/duckdb/src/include/duckdb/execution/index/art/fixed_size_allocator.hpp +0 -115
@@ -9,29 +9,10 @@
|
|
9
9
|
#include "duckdb/execution/index/art/node4.hpp"
|
10
10
|
#include "duckdb/execution/index/art/leaf.hpp"
|
11
11
|
#include "duckdb/execution/index/art/prefix.hpp"
|
12
|
-
#include "duckdb/storage/metadata/metadata_reader.hpp"
|
13
|
-
#include "duckdb/storage/metadata/metadata_writer.hpp"
|
14
12
|
#include "duckdb/storage/table_io_manager.hpp"
|
15
13
|
|
16
14
|
namespace duckdb {
|
17
15
|
|
18
|
-
//===--------------------------------------------------------------------===//
|
19
|
-
// Constructors / Destructors
|
20
|
-
//===--------------------------------------------------------------------===//
|
21
|
-
|
22
|
-
Node::Node(MetadataReader &reader) {
|
23
|
-
block_id_t block_id = reader.Read<block_id_t>();
|
24
|
-
auto offset = reader.Read<uint32_t>();
|
25
|
-
Reset();
|
26
|
-
|
27
|
-
if (block_id == INVALID_BLOCK) {
|
28
|
-
return;
|
29
|
-
}
|
30
|
-
|
31
|
-
SetSerialized();
|
32
|
-
SetPtr(block_id, offset);
|
33
|
-
}
|
34
|
-
|
35
16
|
//===--------------------------------------------------------------------===//
|
36
17
|
// New / Free
|
37
18
|
//===--------------------------------------------------------------------===//
|
@@ -60,61 +41,62 @@ void Node::New(ART &art, Node &node, const NType type) {
|
|
60
41
|
|
61
42
|
void Node::Free(ART &art, Node &node) {
|
62
43
|
|
63
|
-
if (!node.
|
64
|
-
return;
|
44
|
+
if (!node.HasMetadata()) {
|
45
|
+
return node.Clear();
|
65
46
|
}
|
66
47
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
case NType::LEAF_INLINED:
|
91
|
-
return node.Reset();
|
92
|
-
}
|
93
|
-
|
94
|
-
Node::GetAllocator(art, type).Free(node);
|
48
|
+
// free the children of the nodes
|
49
|
+
auto type = node.GetType();
|
50
|
+
switch (type) {
|
51
|
+
case NType::PREFIX:
|
52
|
+
// iterative
|
53
|
+
return Prefix::Free(art, node);
|
54
|
+
case NType::LEAF:
|
55
|
+
// iterative
|
56
|
+
return Leaf::Free(art, node);
|
57
|
+
case NType::NODE_4:
|
58
|
+
Node4::Free(art, node);
|
59
|
+
break;
|
60
|
+
case NType::NODE_16:
|
61
|
+
Node16::Free(art, node);
|
62
|
+
break;
|
63
|
+
case NType::NODE_48:
|
64
|
+
Node48::Free(art, node);
|
65
|
+
break;
|
66
|
+
case NType::NODE_256:
|
67
|
+
Node256::Free(art, node);
|
68
|
+
break;
|
69
|
+
case NType::LEAF_INLINED:
|
70
|
+
return node.Clear();
|
95
71
|
}
|
96
72
|
|
97
|
-
|
98
|
-
node.
|
73
|
+
GetAllocator(art, type).Free(node);
|
74
|
+
node.Clear();
|
99
75
|
}
|
100
76
|
|
101
77
|
//===--------------------------------------------------------------------===//
|
102
|
-
//
|
78
|
+
// Get Allocators
|
103
79
|
//===--------------------------------------------------------------------===//
|
104
80
|
|
105
|
-
|
81
|
+
FixedSizeAllocator &Node::GetAllocator(const ART &art, const NType type) {
|
82
|
+
return *(*art.allocators)[static_cast<uint8_t>(type) - 1];
|
83
|
+
}
|
84
|
+
|
85
|
+
//===--------------------------------------------------------------------===//
|
86
|
+
// Inserts
|
87
|
+
//===--------------------------------------------------------------------===//
|
106
88
|
|
107
|
-
|
89
|
+
void Node::ReplaceChild(const ART &art, const uint8_t byte, const Node child) const {
|
108
90
|
|
109
91
|
switch (GetType()) {
|
110
92
|
case NType::NODE_4:
|
111
|
-
return Node4
|
93
|
+
return RefMutable<Node4>(art, *this, NType::NODE_4).ReplaceChild(byte, child);
|
112
94
|
case NType::NODE_16:
|
113
|
-
return Node16
|
95
|
+
return RefMutable<Node16>(art, *this, NType::NODE_16).ReplaceChild(byte, child);
|
114
96
|
case NType::NODE_48:
|
115
|
-
return Node48
|
97
|
+
return RefMutable<Node48>(art, *this, NType::NODE_48).ReplaceChild(byte, child);
|
116
98
|
case NType::NODE_256:
|
117
|
-
return Node256
|
99
|
+
return RefMutable<Node256>(art, *this, NType::NODE_256).ReplaceChild(byte, child);
|
118
100
|
default:
|
119
101
|
throw InternalException("Invalid node type for ReplaceChild.");
|
120
102
|
}
|
@@ -160,133 +142,75 @@ void Node::DeleteChild(ART &art, Node &node, Node &prefix, const uint8_t byte) {
|
|
160
142
|
// Get functions
|
161
143
|
//===--------------------------------------------------------------------===//
|
162
144
|
|
163
|
-
optional_ptr<Node> Node::GetChild(ART &art, const uint8_t byte) const {
|
145
|
+
optional_ptr<const Node> Node::GetChild(ART &art, const uint8_t byte) const {
|
164
146
|
|
165
|
-
D_ASSERT(
|
147
|
+
D_ASSERT(HasMetadata());
|
166
148
|
|
167
|
-
optional_ptr<Node> child;
|
168
149
|
switch (GetType()) {
|
169
150
|
case NType::NODE_4:
|
170
|
-
|
171
|
-
break;
|
151
|
+
return Ref<const Node4>(art, *this, NType::NODE_4).GetChild(byte);
|
172
152
|
case NType::NODE_16:
|
173
|
-
|
174
|
-
break;
|
153
|
+
return Ref<const Node16>(art, *this, NType::NODE_16).GetChild(byte);
|
175
154
|
case NType::NODE_48:
|
176
|
-
|
177
|
-
break;
|
155
|
+
return Ref<const Node48>(art, *this, NType::NODE_48).GetChild(byte);
|
178
156
|
case NType::NODE_256:
|
179
|
-
|
180
|
-
break;
|
157
|
+
return Ref<const Node256>(art, *this, NType::NODE_256).GetChild(byte);
|
181
158
|
default:
|
182
159
|
throw InternalException("Invalid node type for GetChild.");
|
183
160
|
}
|
184
|
-
|
185
|
-
// deserialize the ART node before returning it
|
186
|
-
if (child && child->IsSerialized()) {
|
187
|
-
child->Deserialize(art);
|
188
|
-
}
|
189
|
-
return child;
|
190
161
|
}
|
191
162
|
|
192
|
-
optional_ptr<Node> Node::
|
163
|
+
optional_ptr<Node> Node::GetChildMutable(ART &art, const uint8_t byte) const {
|
193
164
|
|
194
|
-
D_ASSERT(
|
165
|
+
D_ASSERT(HasMetadata());
|
195
166
|
|
196
|
-
optional_ptr<Node> child;
|
197
167
|
switch (GetType()) {
|
198
168
|
case NType::NODE_4:
|
199
|
-
|
200
|
-
break;
|
169
|
+
return RefMutable<Node4>(art, *this, NType::NODE_4).GetChildMutable(byte);
|
201
170
|
case NType::NODE_16:
|
202
|
-
|
203
|
-
break;
|
171
|
+
return RefMutable<Node16>(art, *this, NType::NODE_16).GetChildMutable(byte);
|
204
172
|
case NType::NODE_48:
|
205
|
-
|
206
|
-
break;
|
173
|
+
return RefMutable<Node48>(art, *this, NType::NODE_48).GetChildMutable(byte);
|
207
174
|
case NType::NODE_256:
|
208
|
-
|
209
|
-
break;
|
175
|
+
return RefMutable<Node256>(art, *this, NType::NODE_256).GetChildMutable(byte);
|
210
176
|
default:
|
211
|
-
throw InternalException("Invalid node type for
|
177
|
+
throw InternalException("Invalid node type for GetChildMutable.");
|
212
178
|
}
|
213
|
-
|
214
|
-
// deserialize the ART node before returning it
|
215
|
-
if (child && deserialize && child->IsSerialized()) {
|
216
|
-
child->Deserialize(art);
|
217
|
-
}
|
218
|
-
return child;
|
219
179
|
}
|
220
180
|
|
221
|
-
|
222
|
-
// (De)serialization
|
223
|
-
//===--------------------------------------------------------------------===//
|
181
|
+
optional_ptr<const Node> Node::GetNextChild(ART &art, uint8_t &byte) const {
|
224
182
|
|
225
|
-
|
226
|
-
if (!IsSet()) {
|
227
|
-
return BlockPointer();
|
228
|
-
}
|
229
|
-
if (IsSerialized()) {
|
230
|
-
Deserialize(art);
|
231
|
-
}
|
183
|
+
D_ASSERT(HasMetadata());
|
232
184
|
|
233
185
|
switch (GetType()) {
|
234
|
-
case NType::PREFIX:
|
235
|
-
// iterative
|
236
|
-
return Prefix::Serialize(art, *this, writer);
|
237
|
-
case NType::LEAF:
|
238
|
-
// iterative
|
239
|
-
return Leaf::Serialize(art, *this, writer);
|
240
186
|
case NType::NODE_4:
|
241
|
-
return Node4
|
187
|
+
return Ref<const Node4>(art, *this, NType::NODE_4).GetNextChild(byte);
|
242
188
|
case NType::NODE_16:
|
243
|
-
return Node16
|
189
|
+
return Ref<const Node16>(art, *this, NType::NODE_16).GetNextChild(byte);
|
244
190
|
case NType::NODE_48:
|
245
|
-
return Node48
|
191
|
+
return Ref<const Node48>(art, *this, NType::NODE_48).GetNextChild(byte);
|
246
192
|
case NType::NODE_256:
|
247
|
-
return Node256
|
248
|
-
|
249
|
-
|
193
|
+
return Ref<const Node256>(art, *this, NType::NODE_256).GetNextChild(byte);
|
194
|
+
default:
|
195
|
+
throw InternalException("Invalid node type for GetNextChild.");
|
250
196
|
}
|
251
|
-
throw InternalException("Invalid node type for Serialize.");
|
252
197
|
}
|
253
198
|
|
254
|
-
|
255
|
-
D_ASSERT(IsSet() && IsSerialized());
|
199
|
+
optional_ptr<Node> Node::GetNextChildMutable(ART &art, uint8_t &byte) const {
|
256
200
|
|
257
|
-
|
258
|
-
MetadataReader reader(art.table_io_manager.GetMetadataManager(), pointer);
|
259
|
-
Reset();
|
260
|
-
SetType(reader.Read<uint8_t>());
|
201
|
+
D_ASSERT(HasMetadata());
|
261
202
|
|
262
|
-
|
263
|
-
|
264
|
-
// iterative functions
|
265
|
-
if (decoded_type == NType::PREFIX) {
|
266
|
-
return Prefix::Deserialize(art, *this, reader);
|
267
|
-
}
|
268
|
-
if (decoded_type == NType::LEAF_INLINED) {
|
269
|
-
return SetRowId(reader.Read<row_t>());
|
270
|
-
}
|
271
|
-
if (decoded_type == NType::LEAF) {
|
272
|
-
return Leaf::Deserialize(art, *this, reader);
|
273
|
-
}
|
274
|
-
|
275
|
-
*this = Node::GetAllocator(art, decoded_type).New();
|
276
|
-
SetType((uint8_t)decoded_type);
|
277
|
-
|
278
|
-
// recursive functions
|
279
|
-
switch (decoded_type) {
|
203
|
+
switch (GetType()) {
|
280
204
|
case NType::NODE_4:
|
281
|
-
return Node4
|
205
|
+
return RefMutable<Node4>(art, *this, NType::NODE_4).GetNextChildMutable(byte);
|
282
206
|
case NType::NODE_16:
|
283
|
-
return Node16
|
207
|
+
return RefMutable<Node16>(art, *this, NType::NODE_16).GetNextChildMutable(byte);
|
284
208
|
case NType::NODE_48:
|
285
|
-
return Node48
|
209
|
+
return RefMutable<Node48>(art, *this, NType::NODE_48).GetNextChildMutable(byte);
|
286
210
|
case NType::NODE_256:
|
287
|
-
return Node256
|
211
|
+
return RefMutable<Node256>(art, *this, NType::NODE_256).GetNextChildMutable(byte);
|
288
212
|
default:
|
289
|
-
throw InternalException("Invalid node type for
|
213
|
+
throw InternalException("Invalid node type for GetNextChildMutable.");
|
290
214
|
}
|
291
215
|
}
|
292
216
|
|
@@ -294,40 +218,31 @@ void Node::Deserialize(ART &art) {
|
|
294
218
|
// Utility
|
295
219
|
//===--------------------------------------------------------------------===//
|
296
220
|
|
297
|
-
string Node::VerifyAndToString(ART &art, const bool only_verify) {
|
221
|
+
string Node::VerifyAndToString(ART &art, const bool only_verify) const {
|
298
222
|
|
299
|
-
D_ASSERT(
|
300
|
-
if (IsSerialized()) {
|
301
|
-
return only_verify ? "" : "serialized";
|
302
|
-
}
|
223
|
+
D_ASSERT(HasMetadata());
|
303
224
|
|
304
225
|
if (GetType() == NType::LEAF || GetType() == NType::LEAF_INLINED) {
|
305
|
-
auto str = Leaf::VerifyAndToString(art, *this);
|
226
|
+
auto str = Leaf::VerifyAndToString(art, *this, only_verify);
|
306
227
|
return only_verify ? "" : "\n" + str;
|
307
228
|
}
|
308
229
|
if (GetType() == NType::PREFIX) {
|
309
|
-
auto str = Prefix::
|
230
|
+
auto str = Prefix::VerifyAndToString(art, *this, only_verify);
|
310
231
|
return only_verify ? "" : "\n" + str;
|
311
232
|
}
|
312
233
|
|
313
234
|
string str = "Node" + to_string(GetCapacity()) + ": [";
|
314
235
|
uint8_t byte = 0;
|
315
|
-
auto child = GetNextChild(art, byte
|
236
|
+
auto child = GetNextChild(art, byte);
|
316
237
|
|
317
238
|
while (child) {
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
}
|
322
|
-
} else {
|
323
|
-
str += "(" + to_string(byte) + ", " + child->VerifyAndToString(art, only_verify) + ")";
|
324
|
-
if (byte == NumericLimits<uint8_t>::Maximum()) {
|
325
|
-
break;
|
326
|
-
}
|
239
|
+
str += "(" + to_string(byte) + ", " + child->VerifyAndToString(art, only_verify) + ")";
|
240
|
+
if (byte == NumericLimits<uint8_t>::Maximum()) {
|
241
|
+
break;
|
327
242
|
}
|
328
243
|
|
329
244
|
byte++;
|
330
|
-
child = GetNextChild(art, byte
|
245
|
+
child = GetNextChild(art, byte);
|
331
246
|
}
|
332
247
|
|
333
248
|
return only_verify ? "" : "\n" + str + "]";
|
@@ -335,17 +250,15 @@ string Node::VerifyAndToString(ART &art, const bool only_verify) {
|
|
335
250
|
|
336
251
|
idx_t Node::GetCapacity() const {
|
337
252
|
|
338
|
-
D_ASSERT(!IsSerialized());
|
339
|
-
|
340
253
|
switch (GetType()) {
|
341
254
|
case NType::NODE_4:
|
342
|
-
return
|
255
|
+
return NODE_4_CAPACITY;
|
343
256
|
case NType::NODE_16:
|
344
|
-
return
|
257
|
+
return NODE_16_CAPACITY;
|
345
258
|
case NType::NODE_48:
|
346
|
-
return
|
259
|
+
return NODE_48_CAPACITY;
|
347
260
|
case NType::NODE_256:
|
348
|
-
return
|
261
|
+
return NODE_256_CAPACITY;
|
349
262
|
default:
|
350
263
|
throw InternalException("Invalid node type for GetCapacity.");
|
351
264
|
}
|
@@ -363,18 +276,13 @@ NType Node::GetARTNodeTypeByCount(const idx_t count) {
|
|
363
276
|
return NType::NODE_256;
|
364
277
|
}
|
365
278
|
|
366
|
-
FixedSizeAllocator &Node::GetAllocator(const ART &art, NType type) {
|
367
|
-
return (*art.allocators)[(uint8_t)type - 1];
|
368
|
-
}
|
369
|
-
|
370
279
|
//===--------------------------------------------------------------------===//
|
371
280
|
// Merging
|
372
281
|
//===--------------------------------------------------------------------===//
|
373
282
|
|
374
283
|
void Node::InitializeMerge(ART &art, const ARTFlags &flags) {
|
375
284
|
|
376
|
-
|
377
|
-
D_ASSERT(IsSet() && !IsSerialized());
|
285
|
+
D_ASSERT(HasMetadata());
|
378
286
|
|
379
287
|
switch (GetType()) {
|
380
288
|
case NType::PREFIX:
|
@@ -384,27 +292,27 @@ void Node::InitializeMerge(ART &art, const ARTFlags &flags) {
|
|
384
292
|
// iterative
|
385
293
|
return Leaf::InitializeMerge(art, *this, flags);
|
386
294
|
case NType::NODE_4:
|
387
|
-
Node4
|
295
|
+
RefMutable<Node4>(art, *this, NType::NODE_4).InitializeMerge(art, flags);
|
388
296
|
break;
|
389
297
|
case NType::NODE_16:
|
390
|
-
Node16
|
298
|
+
RefMutable<Node16>(art, *this, NType::NODE_16).InitializeMerge(art, flags);
|
391
299
|
break;
|
392
300
|
case NType::NODE_48:
|
393
|
-
Node48
|
301
|
+
RefMutable<Node48>(art, *this, NType::NODE_48).InitializeMerge(art, flags);
|
394
302
|
break;
|
395
303
|
case NType::NODE_256:
|
396
|
-
Node256
|
304
|
+
RefMutable<Node256>(art, *this, NType::NODE_256).InitializeMerge(art, flags);
|
397
305
|
break;
|
398
306
|
case NType::LEAF_INLINED:
|
399
307
|
return;
|
400
308
|
}
|
401
309
|
|
402
|
-
|
310
|
+
IncreaseBufferId(flags.merge_buffer_counts[static_cast<uint8_t>(GetType()) - 1]);
|
403
311
|
}
|
404
312
|
|
405
313
|
bool Node::Merge(ART &art, Node &other) {
|
406
314
|
|
407
|
-
if (!
|
315
|
+
if (!HasMetadata()) {
|
408
316
|
*this = other;
|
409
317
|
other = Node();
|
410
318
|
return true;
|
@@ -423,7 +331,7 @@ bool MergePrefixContainsOtherPrefix(ART &art, reference<Node> &l_node, reference
|
|
423
331
|
|
424
332
|
// test if the next byte (mismatch_position) in r_node (prefix) exists in l_node
|
425
333
|
auto mismatch_byte = Prefix::GetByte(art, r_node, mismatch_position);
|
426
|
-
auto child_node = l_node.get().
|
334
|
+
auto child_node = l_node.get().GetChildMutable(art, mismatch_byte);
|
427
335
|
|
428
336
|
// update the prefix of r_node to only consist of the bytes after mismatch_position
|
429
337
|
Prefix::Reduce(art, r_node, mismatch_position);
|
@@ -431,7 +339,7 @@ bool MergePrefixContainsOtherPrefix(ART &art, reference<Node> &l_node, reference
|
|
431
339
|
if (!child_node) {
|
432
340
|
// insert r_node as a child of l_node at the empty position
|
433
341
|
Node::InsertChild(art, l_node, mismatch_byte, r_node);
|
434
|
-
r_node.get().
|
342
|
+
r_node.get().Clear();
|
435
343
|
return true;
|
436
344
|
}
|
437
345
|
|
@@ -454,14 +362,14 @@ void MergePrefixesDiffer(ART &art, reference<Node> &l_node, reference<Node> &r_n
|
|
454
362
|
Prefix::Reduce(art, r_node, mismatch_position);
|
455
363
|
Node4::InsertChild(art, l_node, r_byte, r_node);
|
456
364
|
|
457
|
-
r_node.get().
|
365
|
+
r_node.get().Clear();
|
458
366
|
}
|
459
367
|
|
460
368
|
bool Node::ResolvePrefixes(ART &art, Node &other) {
|
461
369
|
|
462
370
|
// NOTE: we always merge into the left ART
|
463
371
|
|
464
|
-
D_ASSERT(
|
372
|
+
D_ASSERT(HasMetadata() && other.HasMetadata());
|
465
373
|
|
466
374
|
// case 1: both nodes have no prefix
|
467
375
|
if (GetType() != NType::PREFIX && other.GetType() != NType::PREFIX) {
|
@@ -506,7 +414,7 @@ bool Node::ResolvePrefixes(ART &art, Node &other) {
|
|
506
414
|
|
507
415
|
bool Node::MergeInternal(ART &art, Node &other) {
|
508
416
|
|
509
|
-
D_ASSERT(
|
417
|
+
D_ASSERT(HasMetadata() && other.HasMetadata());
|
510
418
|
D_ASSERT(GetType() != NType::PREFIX && other.GetType() != NType::PREFIX);
|
511
419
|
|
512
420
|
// always try to merge the smaller node into the bigger node
|
@@ -532,14 +440,14 @@ bool Node::MergeInternal(ART &art, Node &other) {
|
|
532
440
|
}
|
533
441
|
|
534
442
|
uint8_t byte = 0;
|
535
|
-
auto r_child = r_node.
|
443
|
+
auto r_child = r_node.GetNextChildMutable(art, byte);
|
536
444
|
|
537
445
|
// while r_node still has children to merge
|
538
446
|
while (r_child) {
|
539
|
-
auto l_child = l_node.
|
447
|
+
auto l_child = l_node.GetChildMutable(art, byte);
|
540
448
|
if (!l_child) {
|
541
449
|
// insert child at empty byte
|
542
|
-
|
450
|
+
InsertChild(art, l_node, byte, *r_child);
|
543
451
|
r_node.ReplaceChild(art, byte, empty_node);
|
544
452
|
|
545
453
|
} else {
|
@@ -553,10 +461,10 @@ bool Node::MergeInternal(ART &art, Node &other) {
|
|
553
461
|
break;
|
554
462
|
}
|
555
463
|
byte++;
|
556
|
-
r_child = r_node.
|
464
|
+
r_child = r_node.GetNextChildMutable(art, byte);
|
557
465
|
}
|
558
466
|
|
559
|
-
|
467
|
+
Free(art, r_node);
|
560
468
|
return true;
|
561
469
|
}
|
562
470
|
|
@@ -566,12 +474,10 @@ bool Node::MergeInternal(ART &art, Node &other) {
|
|
566
474
|
|
567
475
|
void Node::Vacuum(ART &art, const ARTFlags &flags) {
|
568
476
|
|
569
|
-
D_ASSERT(
|
570
|
-
if (IsSerialized()) {
|
571
|
-
return;
|
572
|
-
}
|
477
|
+
D_ASSERT(HasMetadata());
|
573
478
|
|
574
479
|
auto node_type = GetType();
|
480
|
+
auto node_type_idx = static_cast<uint8_t>(node_type);
|
575
481
|
|
576
482
|
// iterative functions
|
577
483
|
if (node_type == NType::PREFIX) {
|
@@ -581,29 +487,29 @@ void Node::Vacuum(ART &art, const ARTFlags &flags) {
|
|
581
487
|
return;
|
582
488
|
}
|
583
489
|
if (node_type == NType::LEAF) {
|
584
|
-
if (flags.vacuum_flags[
|
490
|
+
if (flags.vacuum_flags[node_type_idx - 1]) {
|
585
491
|
Leaf::Vacuum(art, *this);
|
586
492
|
}
|
587
493
|
return;
|
588
494
|
}
|
589
495
|
|
590
|
-
auto &allocator =
|
591
|
-
auto needs_vacuum = flags.vacuum_flags[
|
496
|
+
auto &allocator = GetAllocator(art, node_type);
|
497
|
+
auto needs_vacuum = flags.vacuum_flags[node_type_idx - 1] && allocator.NeedsVacuum(*this);
|
592
498
|
if (needs_vacuum) {
|
593
499
|
*this = allocator.VacuumPointer(*this);
|
594
|
-
|
500
|
+
SetMetadata(node_type_idx);
|
595
501
|
}
|
596
502
|
|
597
503
|
// recursive functions
|
598
504
|
switch (node_type) {
|
599
505
|
case NType::NODE_4:
|
600
|
-
return Node4
|
506
|
+
return RefMutable<Node4>(art, *this, NType::NODE_4).Vacuum(art, flags);
|
601
507
|
case NType::NODE_16:
|
602
|
-
return Node16
|
508
|
+
return RefMutable<Node16>(art, *this, NType::NODE_16).Vacuum(art, flags);
|
603
509
|
case NType::NODE_48:
|
604
|
-
return Node48
|
510
|
+
return RefMutable<Node48>(art, *this, NType::NODE_48).Vacuum(art, flags);
|
605
511
|
case NType::NODE_256:
|
606
|
-
return Node256
|
512
|
+
return RefMutable<Node256>(art, *this, NType::NODE_256).Vacuum(art, flags);
|
607
513
|
default:
|
608
514
|
throw InternalException("Invalid node type for Vacuum.");
|
609
515
|
}
|