diff --git a/src/duckdb/src/common/file_system.cpp b/src/duckdb/src/common/file_system.cpp index a7879ec30..81a265cbd 100644 --- a/src/duckdb/src/common/file_system.cpp +++ b/src/duckdb/src/common/file_system.cpp @@ -289,6 +289,16 @@ string FileSystem::GetWorkingDirectory() { #endif string FileSystem::JoinPath(const string &a, const string &b) { + // A remote URL may carry a "?query" suffix (object version, requester-pays, an SSE-C key, ...). + // Appending a path segment after it would bury the query mid-path and corrupt both the query and + // the object path, so join onto the path without the query and keep the query at the very end. + auto scheme = a.find("://"); + if (scheme != string::npos) { + auto query = a.find('?', scheme + 3); + if (query != string::npos) { + return Path::FromString(a.substr(0, query)).Join(b).ToString() + a.substr(query); + } + } return Path::FromString(a).Join(b).ToString(); } diff --git a/src/duckdb/src/execution/index/art/art.cpp b/src/duckdb/src/execution/index/art/art.cpp index e9b7ef2ea..0448539b7 100644 --- a/src/duckdb/src/execution/index/art/art.cpp +++ b/src/duckdb/src/execution/index/art/art.cpp @@ -151,7 +151,7 @@ ART::ART(const Identifier &name, const IndexConstraintType index_constraint_type } // Set the root node and initialize the allocators. - tree.Set(info.root); + root_ptr.Set(info.root); InitAllocators(info); // Set the storage version of the ART @@ -536,7 +536,7 @@ void ART::GenerateKeyVectors(ArenaAllocator &allocator, DataChunk &input, const ARTConflictType ART::Build(unsafe_vector &keys, unsafe_vector &row_ids, const idx_t row_count) { ArenaAllocator arena(BufferAllocator::Get(db)); ARTBuilder builder(arena, *this, keys, row_ids); - builder.Init(tree, row_count - 1); + builder.Init(root_ptr, row_count - 1); auto result = builder.Build(); if (result != ARTConflictType::NO_CONFLICT) { @@ -546,7 +546,7 @@ ARTConflictType ART::Build(unsafe_vector &keys, unsafe_vector &r #ifdef DEBUG set row_ids_debug; Iterator it(*this); - it.FindMinimum(tree); + it.FindMinimum(root_ptr); ARTKey empty_key = ARTKey(); RowIdSetOutput output(row_ids_debug, NumericLimits().Maximum()); it.Scan(empty_key, output, false); @@ -585,15 +585,15 @@ ErrorData ART::InsertKeys(ArenaAllocator &arena, unsafe_vector &keys, un optional_ptr chunk) { auto conflict_type = ARTConflictType::NO_CONFLICT; optional_idx conflict_idx; - auto was_empty = !tree.HasMetadata(); + auto was_empty = !root_ptr.HasMetadata(); // Insert the entries into the index. for (idx_t i = 0; i < row_count; i++) { if (keys[i].Empty()) { continue; } - conflict_type = ARTOperator::Insert(arena, *this, tree, keys[i], 0, row_id_keys[i], GateStatus::GATE_NOT_SET, - delete_info, append_mode); + conflict_type = ARTOperator::Insert(arena, *this, root_ptr, keys[i], 0, row_id_keys[i], + GateStatus::GATE_NOT_SET, delete_info, append_mode); if (conflict_type != ARTConflictType::NO_CONFLICT) { conflict_idx = i; break; @@ -607,8 +607,8 @@ ErrorData ART::InsertKeys(ArenaAllocator &arena, unsafe_vector &keys, un if (keys[i].Empty()) { continue; } - D_ASSERT(tree.GetGateStatus() == GateStatus::GATE_NOT_SET); - ARTOperator::Delete(*this, tree, keys[i], row_id_keys[i]); + D_ASSERT(root_ptr.GetGateStatus() == GateStatus::GATE_NOT_SET); + ARTOperator::Delete(*this, root_ptr, keys[i], row_id_keys[i]); } } @@ -628,9 +628,9 @@ ErrorData ART::InsertKeys(ArenaAllocator &arena, unsafe_vector &keys, un if (keys[i].Empty()) { continue; } - auto leaf = ARTOperator::Lookup(*this, tree, keys[i], 0); - D_ASSERT(leaf); - D_ASSERT(ARTOperator::LookupInLeaf(*this, leaf.Get(), row_id_keys[i])); + auto leaf_ptr = ARTOperator::Lookup(*this, root_ptr, keys[i], 0); + D_ASSERT(leaf_ptr); + D_ASSERT(ARTOperator::LookupInLeaf(*this, leaf_ptr.Get(), row_id_keys[i])); } #endif return ErrorData(); @@ -677,7 +677,7 @@ void ART::ResetStorage(IndexLock &index_lock) { for (auto &allocator : *allocators) { allocator->Reset(); } - tree.Clear(); + root_ptr.Clear(); } idx_t ART::TryDelete(IndexLock &state, DataChunk &entries, Vector &row_ids, optional_ptr deleted_sel, @@ -705,8 +705,8 @@ idx_t ART::DeleteKeys(unsafe_vector &keys, unsafe_vector &row_id for (idx_t i = 0; i < row_count; i++) { bool deleted = true; if (!keys[i].Empty()) { - D_ASSERT(tree.GetGateStatus() == GateStatus::GATE_NOT_SET); - deleted = ARTOperator::Delete(*this, tree, keys[i], row_id_keys[i]); + D_ASSERT(root_ptr.GetGateStatus() == GateStatus::GATE_NOT_SET); + deleted = ARTOperator::Delete(*this, root_ptr, keys[i], row_id_keys[i]); } if (deleted) { if (deleted_sel) { @@ -719,7 +719,7 @@ idx_t ART::DeleteKeys(unsafe_vector &keys, unsafe_vector &row_id } } - if (!tree.HasMetadata()) { + if (!root_ptr.HasMetadata()) { // No more allocations. VerifyAllocationsInternal(); } @@ -729,9 +729,9 @@ idx_t ART::DeleteKeys(unsafe_vector &keys, unsafe_vector &row_id if (keys[i].Empty()) { continue; } - auto leaf = ARTOperator::Lookup(*this, tree, keys[i], 0); - if (leaf) { - auto contains_row_id = ARTOperator::LookupInLeaf(*this, leaf.Get(), row_id_keys[i]); + auto leaf_ptr = ARTOperator::Lookup(*this, root_ptr, keys[i], 0); + if (leaf_ptr) { + auto contains_row_id = ARTOperator::LookupInLeaf(*this, leaf_ptr.Get(), row_id_keys[i]); D_ASSERT(!contains_row_id); } } @@ -748,20 +748,20 @@ bool ART::HasLegacyGeometryKeys() const { // Point and range lookups //===--------------------------------------------------------------------===// ARTSearchResult ART::SearchEqual(const ARTKey &key, RowIdVectorOutput &row_ids) const { - auto leaf = ARTOperator::Lookup(*this, tree, key, 0); - if (!leaf) { + auto leaf_ptr = ARTOperator::Lookup(*this, root_ptr, key, 0); + if (!leaf_ptr) { return ARTSearchResult::COMPLETED; } Iterator it(*this); - it.FindMinimum(leaf.Get()); + it.FindMinimum(leaf_ptr.Get()); const auto empty_key = ARTKey(); return it.Scan(empty_key, row_ids, false) == ARTScanProgress::COMPLETED ? ARTSearchResult::COMPLETED : ARTSearchResult::CAPACITY_EXCEEDED; } ARTSearchResult ART::SearchGreater(const ARTKey &key, bool equal, RowIdVectorOutput &row_ids) const { - if (!tree.HasMetadata()) { + if (!root_ptr.HasMetadata()) { return ARTSearchResult::COMPLETED; } @@ -769,7 +769,7 @@ ARTSearchResult ART::SearchGreater(const ARTKey &key, bool equal, RowIdVectorOut Iterator it(*this); // Early-out, if the maximum value in the ART is lower than the lower bound. - if (!it.LowerBound(tree, key, equal)) { + if (!it.LowerBound(root_ptr, key, equal)) { return ARTSearchResult::COMPLETED; } @@ -780,13 +780,13 @@ ARTSearchResult ART::SearchGreater(const ARTKey &key, bool equal, RowIdVectorOut } ARTSearchResult ART::SearchLess(const ARTKey &upper_bound, bool equal, RowIdVectorOutput &row_ids) const { - if (!tree.HasMetadata()) { + if (!root_ptr.HasMetadata()) { return ARTSearchResult::COMPLETED; } // Find the minimum value in the ART: we start scanning from this value. Iterator it(*this); - it.FindMinimum(tree); + it.FindMinimum(root_ptr); // Early-out, if the minimum value is higher than the upper bound. if (it.current_key.GreaterThan(upper_bound, equal, it.GetNestedDepth())) { @@ -800,7 +800,7 @@ ARTSearchResult ART::SearchLess(const ARTKey &upper_bound, bool equal, RowIdVect ARTSearchResult ART::SearchCloseRange(const ARTKey &lower_bound, const ARTKey &upper_bound, bool left_equal, bool right_equal, RowIdVectorOutput &row_ids) const { - if (!tree.HasMetadata()) { + if (!root_ptr.HasMetadata()) { return ARTSearchResult::COMPLETED; } @@ -808,7 +808,7 @@ ARTSearchResult ART::SearchCloseRange(const ARTKey &lower_bound, const ARTKey &u Iterator it(*this); // Early-out, if the maximum value in the ART is lower than the lower bound. - if (!it.LowerBound(tree, lower_bound, left_equal)) { + if (!it.LowerBound(root_ptr, lower_bound, left_equal)) { return ARTSearchResult::COMPLETED; } @@ -953,28 +953,28 @@ string ART::GenerateConstraintErrorMessage(VerifyExistenceType verify_type, cons } } -void ART::VerifyLeaf(const NodePtr &leaf, const ARTKey &key, DeleteIndexInfo delete_index_info, +void ART::VerifyLeaf(const NodePtr &leaf_ptr, const ARTKey &key, DeleteIndexInfo delete_index_info, ConflictManager &manager, optional_idx &conflict_idx, idx_t i) const { // Get the set of deleted row ids for this value if we have any delete indexes vector deleted_row_ids; if (delete_index_info.delete_indexes) { for (auto &index : *delete_index_info.delete_indexes) { auto &delete_art = index.get().Cast(); - auto deleted_leaf = ARTOperator::Lookup(delete_art, delete_art.tree, key, 0); - if (!deleted_leaf) { + auto deleted_leaf_ptr = ARTOperator::Lookup(delete_art, delete_art.root_ptr, key, 0); + if (!deleted_leaf_ptr) { continue; } // All leaves in the delete ART are inlined. - if (deleted_leaf.Get().GetType() != NType::LEAF_INLINED) { + if (deleted_leaf_ptr.Get().GetType() != NType::LEAF_INLINED) { throw InternalException("Non-inlined leaf?"); } - auto deleted_row_id = deleted_leaf.Get().GetRowId(); + auto deleted_row_id = deleted_leaf_ptr.Get().GetRowId(); deleted_row_ids.push_back(deleted_row_id); } } - if (leaf.GetType() == NType::LEAF_INLINED) { - auto this_row_id = leaf.GetRowId(); + if (leaf_ptr.GetType() == NType::LEAF_INLINED) { + auto this_row_id = leaf_ptr.GetRowId(); if (!deleted_row_ids.empty()) { // The leaf is inlined, and the same key exists in the delete ART. // check if the row-id matches - if it does there is no conflict @@ -1005,7 +1005,7 @@ void ART::VerifyLeaf(const NodePtr &leaf, const ARTKey &key, DeleteIndexInfo del // Scan the two row IDs in the leaf. Iterator it(*this); - it.FindMinimum(leaf); + it.FindMinimum(leaf_ptr); ARTKey empty_key = ARTKey(); set row_ids; RowIdSetOutput output(row_ids, 2); @@ -1053,11 +1053,11 @@ void ART::VerifyConstraint(DataChunk &chunk, IndexAppendInfo &info, ConflictMana continue; } - auto leaf = ARTOperator::Lookup(*this, tree, keys[i], 0); - if (!leaf) { + auto leaf_ptr = ARTOperator::Lookup(*this, root_ptr, keys[i], 0); + if (!leaf_ptr) { continue; } - VerifyLeaf(leaf.Get(), keys[i], DeleteIndexInfo(info.delete_indexes), manager, conflict_idx, i); + VerifyLeaf(leaf_ptr.Get(), keys[i], DeleteIndexInfo(info.delete_indexes), manager, conflict_idx, i); } manager.FinishLookup(); @@ -1094,8 +1094,8 @@ void ART::TransformToDeprecated() { make_uniq(std::move(deprecated_allocator)); // Transform all leaves, and possibly the prefixes. - if (tree.HasMetadata()) { - NodePtr::TransformToDeprecated(*this, tree, *state); + if (root_ptr.HasMetadata()) { + NodePtr::TransformToDeprecated(*this, root_ptr, *state); } // Replace the prefix allocator with the deprecated allocator. @@ -1115,7 +1115,7 @@ IndexStorageInfo ART::PrepareSerialize(const case_insensitive_map_t &opti } IndexStorageInfo info(name); - info.root = tree.Get(); + info.root = root_ptr.Get(); info.options = options; // It never hurts to serialize the storage version, even to older formats @@ -1202,7 +1202,7 @@ void ART::Deserialize(const BlockPointer &pointer) { auto &metadata_manager = table_io_manager.GetMetadataManager(); MetadataReader reader(metadata_manager, pointer); - tree = reader.Read(); + root_ptr = reader.Read(); for (idx_t i = 0; i < DEPRECATED_ALLOCATOR_COUNT; i++) { (*allocators)[i]->Deserialize(metadata_manager, reader.Read()); @@ -1277,8 +1277,8 @@ void ART::FinalizeVacuum(const unordered_set &indexes) { } } -static void VacuumPointerIfNeeded(ART &art, const unordered_set &indexes, NodePtr &node) { - const auto type = node.GetType(); +static void VacuumPointerIfNeeded(ART &art, const unordered_set &indexes, NodePtr &node_ptr) { + const auto type = node_ptr.GetType(); if (type == NType::LEAF_INLINED) { return; } @@ -1287,20 +1287,20 @@ static void VacuumPointerIfNeeded(ART &art, const unordered_set &indexe return; } auto &allocator = NodePtr::GetAllocator(art, type); - if (!allocator.NeedsVacuum(node)) { + if (!allocator.NeedsVacuum(node_ptr)) { return; } - const auto status = node.GetGateStatus(); - node = allocator.VacuumPointer(node); - node.SetMetadata(static_cast(type)); - node.SetGateStatus(status); + const auto status = node_ptr.GetGateStatus(); + node_ptr = allocator.VacuumPointer(node_ptr); + node_ptr.SetMetadata(static_cast(type)); + node_ptr.SetGateStatus(status); } void ART::Vacuum(IndexLock &state) { state.AssertHeld(*this); D_ASSERT(owns_data); - if (!tree.HasMetadata()) { + if (!root_ptr.HasMetadata()) { for (auto &allocator : *allocators) { allocator->Reset(); } @@ -1318,27 +1318,27 @@ void ART::Vacuum(IndexLock &state) { auto &art = *this; const auto vacuum_deprecated_leaves = indexes.find(NodePtr::GetAllocatorIdx(NType::LEAF)) != indexes.end(); - auto child_handler = [&](NodePtr &child) -> OptionalNodePtr { + auto child_handler = [&](NodePtr &child_ptr) -> OptionalNodePtr { // Vacuums the pointer if needed and updates in place within the parent. - VacuumPointerIfNeeded(art, indexes, child); - if (child.GetType() == NType::LEAF_INLINED) { + VacuumPointerIfNeeded(art, indexes, child_ptr); + if (child_ptr.GetType() == NType::LEAF_INLINED) { return OptionalNodePtr(); } // Push the updated pointer onto the stack to continue vacuum traversal on the subtree. - return child; + return child_ptr; }; - auto on_pop = [&](NodePtr current) -> ARTScanNodeResult { - D_ASSERT(current.HasMetadata()); - if (current.GetType() == NType::LEAF) { + auto on_pop = [&](NodePtr current_ptr) -> ARTScanNodeResult { + D_ASSERT(current_ptr.HasMetadata()); + if (current_ptr.GetType() == NType::LEAF) { if (vacuum_deprecated_leaves) { // Vacuum the internal pointers in the deprecated leaf chain. - Leaf::DeprecatedVacuum(art, current); + Leaf::DeprecatedVacuum(art, current_ptr); } return ARTScanNodeResult::SKIP; } return ARTScanNodeResult::SCAN_CHILDREN; }; - ARTScanPreorder(art, tree, child_handler, on_pop); + ARTScanPreorder(art, root_ptr, child_handler, on_pop); // Finalize the vacuum operation. FinalizeVacuum(indexes); @@ -1355,12 +1355,12 @@ void ART::InitializeMergeUpperBounds(unsafe_vector &upper_bounds) { } } -void ART::InitializeMerge(NodePtr &other_tree, unsafe_vector &upper_bounds) { - D_ASSERT(other_tree.HasMetadata()); +void ART::InitializeMerge(NodePtr &other_root_ptr, unsafe_vector &upper_bounds) { + D_ASSERT(other_root_ptr.HasMetadata()); - auto child_handler = [&](NodePtr &child) -> OptionalNodePtr { - D_ASSERT(child.HasMetadata()); - auto type = child.GetType(); + auto child_handler = [&](NodePtr &child_ptr) -> OptionalNodePtr { + D_ASSERT(child_ptr.HasMetadata()); + auto type = child_ptr.GetType(); // no-op if (type == NType::LEAF_INLINED) { return OptionalNodePtr(); @@ -1369,10 +1369,10 @@ void ART::InitializeMerge(NodePtr &other_tree, unsafe_vector &upper_bound if (type == NType::LEAF) { throw InternalException("deprecated ART storage in InitializeMerge"); } - auto original = child; + auto original_ptr = child_ptr; // remap BufferId in-place within the parent. auto idx = NodePtr::GetAllocatorIdx(type); - child.IncreaseBufferId(upper_bounds[idx]); + child_ptr.IncreaseBufferId(upper_bounds[idx]); switch (type) { case NType::NODE_7_LEAF: @@ -1386,24 +1386,24 @@ void ART::InitializeMerge(NodePtr &other_tree, unsafe_vector &upper_bound case NType::NODE_48: case NType::NODE_256: // Original pointer is pushed onto the stack. - return original; + return original_ptr; default: throw InternalException("invalid node type for InitializeMerge: %d", type); } }; - auto on_pop = [](NodePtr node) -> ARTScanNodeResult { - D_ASSERT(node.HasMetadata()); + auto on_pop = [](NodePtr node_ptr) -> ARTScanNodeResult { + D_ASSERT(node_ptr.HasMetadata()); return ARTScanNodeResult::SCAN_CHILDREN; }; - ARTScanPreorder(*this, other_tree, child_handler, on_pop); + ARTScanPreorder(*this, other_root_ptr, child_handler, on_pop); } bool ART::MergeIndexes(IndexLock &state, BoundIndex &source_index) { state.AssertHeld(*this); auto &other_art = source_index.Cast(); - if (!other_art.tree.HasMetadata()) { + if (!other_art.root_ptr.HasMetadata()) { return true; } @@ -1418,11 +1418,11 @@ bool ART::MergeIndexes(IndexLock &state, BoundIndex &source_index) { "Failed to merge ARTs - Node256Leaf segment sizes do not match (target %llu, source %llu)", target_size, source_size); } - if (tree.HasMetadata()) { + if (root_ptr.HasMetadata()) { // Fully deserialize other_index, and traverse it to increment its buffer IDs. unsafe_vector upper_bounds; InitializeMergeUpperBounds(upper_bounds); - other_art.InitializeMerge(other_art.tree, upper_bounds); + other_art.InitializeMerge(other_art.root_ptr, upper_bounds); } // Merge the node storage. @@ -1432,16 +1432,16 @@ bool ART::MergeIndexes(IndexLock &state, BoundIndex &source_index) { } // Merge the ARTs. - D_ASSERT(tree.GetGateStatus() == other_art.tree.GetGateStatus()); - if (tree.HasMetadata()) { + D_ASSERT(root_ptr.GetGateStatus() == other_art.root_ptr.GetGateStatus()); + if (root_ptr.HasMetadata()) { ArenaAllocator arena(Allocator::Get(db)); ARTMerger merger(arena, *this); - merger.Init(tree, other_art.tree); + merger.Init(root_ptr, other_art.root_ptr); return merger.Merge() == ARTConflictType::NO_CONFLICT; } - tree = other_art.tree; - other_art.tree.Clear(); + root_ptr = other_art.root_ptr; + other_art.root_ptr.Clear(); return true; } @@ -1450,7 +1450,7 @@ bool ART::MergeIndexes(IndexLock &state, BoundIndex &source_index) { void ART::RemovalMerge(IndexLock &state, BoundIndex &source_index) { state.AssertHeld(*this); auto &source = source_index.Cast(); - if (!source.tree.HasMetadata()) { + if (!source.root_ptr.HasMetadata()) { return; } @@ -1459,7 +1459,7 @@ void ART::RemovalMerge(IndexLock &state, BoundIndex &source_index) { idx_t delete_count = 0; Iterator it(source); - it.FindMinimum(source.tree); + it.FindMinimum(source.root_ptr); unsafe_vector keys(STANDARD_VECTOR_SIZE); unsafe_vector row_id_keys(STANDARD_VECTOR_SIZE); @@ -1493,14 +1493,14 @@ void ART::RemovalMerge(BoundIndex &source_index) { ErrorData ART::InsertMerge(IndexLock &state, BoundIndex &source_index, IndexAppendMode append_mode) { state.AssertHeld(*this); auto &source = source_index.Cast(); - if (!source.tree.HasMetadata()) { + if (!source.root_ptr.HasMetadata()) { return ErrorData(); } ArenaAllocator arena(BufferAllocator::Get(db)); Iterator it(source); - it.FindMinimum(source.tree); + it.FindMinimum(source.root_ptr); unsafe_vector keys(STANDARD_VECTOR_SIZE); unsafe_vector row_id_keys(STANDARD_VECTOR_SIZE); @@ -1550,8 +1550,9 @@ string ART::ToString(IndexLock &l, bool display_ascii) { } string ART::ToStringInternal(bool display_ascii) { - if (tree.HasMetadata()) { - return "\nART: \n" + tree.ToString(*this, ToStringOptions(false, display_ascii, nullptr, 0, 0, true, false)); + if (root_ptr.HasMetadata()) { + return "\nART: \n" + + root_ptr.ToString(*this, ToStringOptions(false, display_ascii, nullptr, 0, 0, true, false)); } return "[empty]"; } @@ -1562,8 +1563,8 @@ void ART::Verify(IndexLock &l) { } void ART::VerifyInternal() { - if (tree.HasMetadata()) { - tree.Verify(*this); + if (root_ptr.HasMetadata()) { + root_ptr.Verify(*this); } } @@ -1579,8 +1580,8 @@ void ART::VerifyAllocationsInternal() { node_counts[NumericCast(i)] = 0; } - if (tree.HasMetadata()) { - tree.VerifyAllocations(*this, node_counts); + if (root_ptr.HasMetadata()) { + root_ptr.VerifyAllocations(*this, node_counts); } for (idx_t i = 0; i < allocators->size(); i++) { diff --git a/src/duckdb/src/execution/index/art/art_builder.cpp b/src/duckdb/src/execution/index/art/art_builder.cpp index 41679830a..47ade0b2d 100644 --- a/src/duckdb/src/execution/index/art/art_builder.cpp +++ b/src/duckdb/src/execution/index/art/art_builder.cpp @@ -35,13 +35,13 @@ ARTConflictType ARTBuilder::Build() { return ARTConflictType::CONSTRAINT; } - reference node_ref(entry.node); + reference node_ptr_ref(entry.node_ptr); auto count = UnsafeNumericCast(start.len - prefix_depth); - Prefix::New(art, node_ref, start, prefix_depth, count); + Prefix::New(art, node_ptr_ref, start, prefix_depth, count); // Inline the row ID. if (row_id_count == 1) { - Leaf::New(node_ref, row_ids[entry.start].GetRowId()); + Leaf::New(node_ptr_ref, row_ids[entry.start].GetRowId()); continue; } @@ -49,17 +49,17 @@ ARTConflictType ARTBuilder::Build() { // We cannot iterate into the nested leaf with the builder // because row IDs are not sorted. for (idx_t i = entry.start; i < entry.start + row_id_count; i++) { - ARTOperator::Insert(arena, art, node_ref, row_ids[i], 0, row_ids[i], GateStatus::GATE_SET, + ARTOperator::Insert(arena, art, node_ptr_ref, row_ids[i], 0, row_ids[i], GateStatus::GATE_SET, DeleteIndexInfo(), IndexAppendMode::DEFAULT); } - node_ref.get().SetGateStatus(GateStatus::GATE_SET); + node_ptr_ref.get().SetGateStatus(GateStatus::GATE_SET); continue; } // Create the prefix. Returns early, if the prefix_length is zero. - reference node_ref(entry.node); + reference node_ptr_ref(entry.node_ptr); auto prefix_length = entry.depth - prefix_depth; - Prefix::New(art, node_ref, start, prefix_depth, prefix_length); + Prefix::New(art, node_ptr_ref, start, prefix_depth, prefix_length); vector child_offsets; child_offsets.emplace_back(entry.start); @@ -70,16 +70,16 @@ ARTConflictType ARTBuilder::Build() { } // Create a new node containing the children. - NodePtr::New(art, node_ref, NodePtr::GetInternalNodeType(child_offsets.size())); + NodePtr::New(art, node_ptr_ref, NodePtr::GetInternalNodeType(child_offsets.size())); auto start_offset = child_offsets[0]; for (idx_t i = 1; i <= child_offsets.size(); i++) { auto child_byte = keys[start_offset].data[entry.depth]; // FIXME: Improve performance by either returning a reference to the child directly, // FIXME: or by calling InsertChild after processing the child (at the end of the stack loop). - NodePtr::InsertChild(art, node_ref, child_byte); - auto child = node_ref.get().NodePtr::GetChildMutable(art, child_byte, true); + NodePtr::InsertChild(art, node_ptr_ref, child_byte); + auto child_ptr_ref = node_ptr_ref.get().NodePtr::GetChildMutable(art, child_byte, true); auto end_offset = i != child_offsets.size() ? child_offsets[i] - 1 : entry.end; - s.emplace(*child, start_offset, end_offset, entry.depth + 1); + s.emplace(*child_ptr_ref, start_offset, end_offset, entry.depth + 1); start_offset = end_offset + 1; } } diff --git a/src/duckdb/src/execution/index/art/art_index.cpp b/src/duckdb/src/execution/index/art/art_index.cpp index 0e82653ea..4ac0bc43a 100644 --- a/src/duckdb/src/execution/index/art/art_index.cpp +++ b/src/duckdb/src/execution/index/art/art_index.cpp @@ -98,10 +98,10 @@ void ARTBuildSinkUnsorted(IndexBuildSinkInput &input, DataChunk &key_chunk, Data // Insert each key and its corresponding row ID. for (idx_t i = 0; i < row_count; i++) { - auto status = art.tree.GetGateStatus(); + auto status = art.root_ptr.GetGateStatus(); auto conflict_type = - ARTOperator::Insert(l_state.arena_allocator, art, art.tree, l_state.keys[i], 0, l_state.row_ids[i], status, - DeleteIndexInfo(), IndexAppendMode::DEFAULT); + ARTOperator::Insert(l_state.arena_allocator, art, art.root_ptr, l_state.keys[i], 0, l_state.row_ids[i], + status, DeleteIndexInfo(), IndexAppendMode::DEFAULT); if (conflict_type == ARTConflictType::CONSTRAINT) { throw ConstraintException("Data contains duplicates on indexed column(s)"); } diff --git a/src/duckdb/src/execution/index/art/art_merger.cpp b/src/duckdb/src/execution/index/art/art_merger.cpp index cc4b8b39e..283f7b608 100644 --- a/src/duckdb/src/execution/index/art/art_merger.cpp +++ b/src/duckdb/src/execution/index/art/art_merger.cpp @@ -13,8 +13,8 @@ namespace duckdb { -void ARTMerger::Init(NodePtr &left, NodePtr &right) { - Emplace(left, right, GateStatus::GATE_NOT_SET, 0); +void ARTMerger::Init(NodePtr &left_ptr, NodePtr &right_ptr) { + Emplace(left_ptr, right_ptr, GateStatus::GATE_NOT_SET, 0); } ARTConflictType ARTMerger::Merge() { @@ -23,13 +23,13 @@ ARTConflictType ARTMerger::Merge() { auto entry = s.top(); s.pop(); - const auto left_type = entry.left.GetType(); - const auto right_type = entry.right.GetType(); + const auto left_type = entry.left_ptr.GetType(); + const auto right_type = entry.right_ptr.GetType(); // Early-out due to a constraint violation. // If right is LEAF_INLINED, then left is also LEAF_INLINED. const auto duplicate_key = - right_type == NType::LEAF_INLINED || entry.right.GetGateStatus() == GateStatus::GATE_SET; + right_type == NType::LEAF_INLINED || entry.right_ptr.GetGateStatus() == GateStatus::GATE_SET; if (art.IsUnique() && duplicate_key) { return ARTConflictType::CONSTRAINT; } @@ -37,7 +37,7 @@ ARTConflictType ARTMerger::Merge() { if (left_type == NType::LEAF_INLINED) { // Both left and right are inlined leaves. D_ASSERT(right_type == NType::LEAF_INLINED); - Leaf::MergeInlined(arena, art, entry.left, entry.right, entry.status, entry.depth); + Leaf::MergeInlined(arena, art, entry.left_ptr, entry.right_ptr, entry.status, entry.depth); continue; } @@ -50,14 +50,14 @@ ARTConflictType ARTMerger::Merge() { continue; } - if (entry.right.IsNestedLeaf()) { + if (entry.right_ptr.IsNestedLeaf()) { // Both left and right are nested leaves. - D_ASSERT(entry.left.IsNestedLeaf()); + D_ASSERT(entry.left_ptr.IsNestedLeaf()); MergeLeaves(entry); continue; } - if (entry.left.IsInternalNode() && entry.right.IsInternalNode()) { + if (entry.left_ptr.IsInternalNode() && entry.right_ptr.IsInternalNode()) { // Both left and right are internal nodes. MergeNodes(entry); continue; @@ -70,128 +70,128 @@ ARTConflictType ARTMerger::Merge() { continue; } // Left is a node, right is a PREFIX. - MergeNodeAndPrefix(entry.left, entry.right, entry.status, entry.depth); + MergeNodeAndPrefix(entry.left_ptr, entry.right_ptr, entry.status, entry.depth); } // We exhausted the stack. return ARTConflictType::NO_CONFLICT; } -void ARTMerger::Emplace(NodePtr &left, NodePtr &right, const GateStatus parent_status, const idx_t depth) { - const auto left_type = left.GetType(); - const auto right_type = right.GetType(); +void ARTMerger::Emplace(NodePtr &left_ptr, NodePtr &right_ptr, const GateStatus parent_status, const idx_t depth) { + const auto left_type = left_ptr.GetType(); + const auto right_type = right_ptr.GetType(); if (left_type == NType::LEAF_INLINED) { - swap(left, right); + swap(left_ptr, right_ptr); } else if (left_type == NType::PREFIX && right_type != NType::LEAF_INLINED) { - swap(left, right); + swap(left_ptr, right_ptr); } // left ONLY has GATE_SET, if it is the gate node. // When outside the gate, we propagate the parent_status (GATE_NOT_SET) and the depth. // When inside the gate, we already reset the depth, and we propagate the parent_status (GATE_SET). - if (left.GetGateStatus() == GateStatus::GATE_NOT_SET) { - s.emplace(left, right, parent_status, depth); + if (left_ptr.GetGateStatus() == GateStatus::GATE_NOT_SET) { + s.emplace(left_ptr, right_ptr, parent_status, depth); return; } // Enter a gate. // Reset the depth. D_ASSERT(parent_status == GateStatus::GATE_NOT_SET); - s.emplace(left, right, GateStatus::GATE_SET, 0); + s.emplace(left_ptr, right_ptr, GateStatus::GATE_SET, 0); } ARTConflictType ARTMerger::MergeNodeAndInlined(NodeEntry &entry) { - D_ASSERT(entry.right.GetType() == NType::LEAF_INLINED); + D_ASSERT(entry.right_ptr.GetType() == NType::LEAF_INLINED); D_ASSERT(entry.status == GateStatus::GATE_SET); // We fall back to the ART insertion code. - auto row_id_key = ARTKey::CreateARTKey(arena, entry.right.GetRowId()); - return ARTOperator::Insert(arena, art, entry.left, row_id_key, entry.depth, row_id_key, GateStatus::GATE_SET, + auto row_id_key = ARTKey::CreateARTKey(arena, entry.right_ptr.GetRowId()); + return ARTOperator::Insert(arena, art, entry.left_ptr, row_id_key, entry.depth, row_id_key, GateStatus::GATE_SET, DeleteIndexInfo(), IndexAppendMode::DEFAULT); } -array_ptr ARTMerger::GetBytes(NodePtr &leaf) { - const auto type = leaf.GetType(); +array_ptr ARTMerger::GetBytes(NodePtr &leaf_ptr) { + const auto type = leaf_ptr.GetType(); switch (type) { case NType::NODE_7_LEAF: - return NodePtr::Ref(art, leaf, type).GetBytes(); + return NodePtr::Ref(art, leaf_ptr, type).GetBytes(); case NType::NODE_15_LEAF: - return NodePtr::Ref(art, leaf, type).GetBytes(); + return NodePtr::Ref(art, leaf_ptr, type).GetBytes(); case NType::NODE_256_LEAF: - return NodePtr::Ref(art, leaf, type).GetBytes(arena); + return NodePtr::Ref(art, leaf_ptr, type).GetBytes(arena); default: throw InternalException("invalid node type for ARTMerger::GetBytes: %s", EnumUtil::ToString(type)); } } void ARTMerger::MergeLeaves(NodeEntry &entry) { - D_ASSERT(entry.left.IsNestedLeaf()); - D_ASSERT(entry.right.IsNestedLeaf()); - D_ASSERT(entry.left.GetGateStatus() == GateStatus::GATE_NOT_SET); - D_ASSERT(entry.right.GetGateStatus() == GateStatus::GATE_NOT_SET); + D_ASSERT(entry.left_ptr.IsNestedLeaf()); + D_ASSERT(entry.right_ptr.IsNestedLeaf()); + D_ASSERT(entry.left_ptr.GetGateStatus() == GateStatus::GATE_NOT_SET); + D_ASSERT(entry.right_ptr.GetGateStatus() == GateStatus::GATE_NOT_SET); // Merge the smaller leaf into the bigger leaf. - if (entry.left.GetType() < entry.right.GetType()) { - swap(entry.left, entry.right); + if (entry.left_ptr.GetType() < entry.right_ptr.GetType()) { + swap(entry.left_ptr, entry.right_ptr); } // Get the bytes of the right node. // Then, copy them into left. - auto bytes = GetBytes(entry.right); + auto bytes = GetBytes(entry.right_ptr); // FIXME: Obtain a reference to left once and // FIXME: handle the different node type combinations. for (idx_t i = 0; i < bytes.size(); i++) { - NodePtr::InsertChild(art, entry.left, bytes[i]); + NodePtr::InsertChild(art, entry.left_ptr, bytes[i]); } - NodePtr::FreeNode(art, entry.right); + NodePtr::FreeNode(art, entry.right_ptr); } -NodeChildren ARTMerger::ExtractChildren(NodePtr &node) { - const auto type = node.GetType(); +NodeChildren ARTMerger::ExtractChildren(NodePtr &node_ptr) { + const auto type = node_ptr.GetType(); switch (type) { case NType::NODE_4: - return NodePtr::Ref(art, node, type).ExtractChildren(arena); + return NodePtr::Ref(art, node_ptr, type).ExtractChildren(arena); case NType::NODE_16: - return NodePtr::Ref(art, node, type).ExtractChildren(arena); + return NodePtr::Ref(art, node_ptr, type).ExtractChildren(arena); case NType::NODE_48: - return NodePtr::Ref(art, node, type).ExtractChildren(arena); + return NodePtr::Ref(art, node_ptr, type).ExtractChildren(arena); case NType::NODE_256: - return NodePtr::Ref(art, node, type).ExtractChildren(arena); + return NodePtr::Ref(art, node_ptr, type).ExtractChildren(arena); default: throw InternalException("invalid node type for ARTMerger::GetChildren: %s", EnumUtil::ToString(type)); } } void ARTMerger::MergeNodes(NodeEntry &entry) { - D_ASSERT(entry.left.IsInternalNode()); - D_ASSERT(entry.right.IsInternalNode()); + D_ASSERT(entry.left_ptr.IsInternalNode()); + D_ASSERT(entry.right_ptr.IsInternalNode()); // Merge the smaller node into the bigger node. - if (entry.left.GetType() < entry.right.GetType()) { - swap(entry.left, entry.right); + if (entry.left_ptr.GetType() < entry.right_ptr.GetType()) { + swap(entry.left_ptr, entry.right_ptr); } // Get the children of the right node. // Then, copy them into left. - auto children = ExtractChildren(entry.right); + auto children = ExtractChildren(entry.right_ptr); // As long as the arena is valid, // the copied-out nodes (and their references) are valid. - NodePtr::FreeNode(art, entry.right); + NodePtr::FreeNode(art, entry.right_ptr); // First, we iterate and insert children. // This might grow the node, so we need to do it prior to Emplace. vector remaining; for (idx_t i = 0; i < children.bytes.size(); i++) { const auto byte = children.bytes[i]; - auto child = entry.left.GetChildMutable(art, byte); + auto child_ptr_ref = entry.left_ptr.GetChildMutable(art, byte); - if (!child) { + if (!child_ptr_ref) { // There is no child at this byte. // We can insert the right node's child at byte and are done. - auto &right_child = children.children[i]; - NodePtr::InsertChild(art, entry.left, byte, right_child); + auto &right_child_ptr = children.children[i]; + NodePtr::InsertChild(art, entry.left_ptr, byte, right_child_ptr); continue; } // There is a left and a right child at this byte. @@ -202,47 +202,47 @@ void ARTMerger::MergeNodes(NodeEntry &entry) { // Emplace all remaining children. for (idx_t i = 0; i < remaining.size(); i++) { const auto byte = children.bytes[remaining[i]]; - auto &right_child = children.children[remaining[i]]; - auto child = entry.left.GetChildMutable(art, byte); - Emplace(*child, right_child, entry.status, entry.depth + 1); + auto &right_child_ptr = children.children[remaining[i]]; + auto child_ptr_ref = entry.left_ptr.GetChildMutable(art, byte); + Emplace(*child_ptr_ref, right_child_ptr, entry.status, entry.depth + 1); } } -void ARTMerger::MergeNodeAndPrefix(NodePtr &node, NodePtr &prefix, const GateStatus parent_status, +void ARTMerger::MergeNodeAndPrefix(NodePtr &node_ptr, NodePtr &prefix_ptr, const GateStatus parent_status, const idx_t parent_depth, const uint8_t pos) { - D_ASSERT(node.IsInternalNode()); - D_ASSERT(prefix.GetType() == NType::PREFIX); + D_ASSERT(node_ptr.IsInternalNode()); + D_ASSERT(prefix_ptr.GetType() == NType::PREFIX); // Get the child at the prefix byte, or nullptr, if there is no child. - const auto byte = Prefix::GetByte(art, prefix, pos); - auto child = node.GetChildMutable(art, byte); + const auto byte = Prefix::GetByte(art, prefix_ptr, pos); + auto child_ptr_ref = node_ptr.GetChildMutable(art, byte); // Reduce the prefix to the bytes after pos. - Prefix::Reduce(art, prefix, pos); + Prefix::Reduce(art, prefix_ptr, pos); - if (child) { + if (child_ptr_ref) { // Iterate on the child and the remaining prefix. - Emplace(*child, prefix, parent_status, parent_depth + 1); + Emplace(*child_ptr_ref, prefix_ptr, parent_status, parent_depth + 1); return; } // There is no child at this prefix byte, // so we can insert the remaining prefix and are done. - NodePtr::InsertChild(art, node, byte, prefix); - prefix.Clear(); + NodePtr::InsertChild(art, node_ptr, byte, prefix_ptr); + prefix_ptr.Clear(); } -void ARTMerger::MergeNodeAndPrefix(NodePtr &node, NodePtr &prefix, const GateStatus parent_status, +void ARTMerger::MergeNodeAndPrefix(NodePtr &node_ptr, NodePtr &prefix_ptr, const GateStatus parent_status, const idx_t parent_depth) { - D_ASSERT(node.IsInternalNode()); - D_ASSERT(prefix.GetType() == NType::PREFIX); + D_ASSERT(node_ptr.IsInternalNode()); + D_ASSERT(prefix_ptr.GetType() == NType::PREFIX); - MergeNodeAndPrefix(node, prefix, parent_status, parent_depth, 0); + MergeNodeAndPrefix(node_ptr, prefix_ptr, parent_status, parent_depth, 0); } void ARTMerger::MergePrefixes(NodeEntry &entry) { - D_ASSERT(entry.left.GetType() == NType::PREFIX); - D_ASSERT(entry.right.GetType() == NType::PREFIX); + D_ASSERT(entry.left_ptr.GetType() == NType::PREFIX); + D_ASSERT(entry.right_ptr.GetType() == NType::PREFIX); // We traverse prefixes until we // Case 1: find a position where they differ. @@ -255,8 +255,8 @@ void ARTMerger::MergePrefixes(NodeEntry &entry) { // the prefixes are the same. That means, we only need to keep // one of them around. - Prefix l_prefix(art, entry.left, true); - Prefix r_prefix(art, entry.right, true); + Prefix l_prefix(art, entry.left_ptr, true); + Prefix r_prefix(art, entry.right_ptr, true); const auto count = art.PrefixCount(); // Find a byte at pos where the prefixes differ. @@ -276,18 +276,18 @@ void ARTMerger::MergePrefixes(NodeEntry &entry) { // Then, we insert both remainders into a new Node4. // Then, we are done. const auto split_pos = UnsafeNumericCast(pos.GetIndex()); - const auto l_byte = Prefix::GetByte(art, entry.left, split_pos); - const auto r_byte = Prefix::GetByte(art, entry.right, split_pos); + const auto l_byte = Prefix::GetByte(art, entry.left_ptr, split_pos); + const auto r_byte = Prefix::GetByte(art, entry.right_ptr, split_pos); // Split and reduce. - NodePtr branching_node4; - Node4::New(art, branching_node4); - auto l_child = PrefixHandle::Split(art, entry.left, branching_node4, split_pos); - Prefix::Reduce(art, entry.right, split_pos); - - Node4::InsertChild(art, branching_node4, l_byte, l_child); - Node4::InsertChild(art, branching_node4, r_byte, entry.right); - entry.right.Clear(); + NodePtr branching_node4_ptr; + Node4::New(art, branching_node4_ptr); + auto l_child_ptr = PrefixHandle::Split(art, entry.left_ptr, branching_node4_ptr, split_pos); + Prefix::Reduce(art, entry.right_ptr, split_pos); + + Node4::InsertChild(art, branching_node4_ptr, l_byte, l_child_ptr); + Node4::InsertChild(art, branching_node4_ptr, r_byte, entry.right_ptr); + entry.right_ptr.Clear(); return; } @@ -295,12 +295,12 @@ void ARTMerger::MergePrefixes(NodeEntry &entry) { // The prefixes match. // Free the right prefix, but keep the reference to its child alive. // Then, iterate on the left and right (reduced) child. - auto r_child = *r_prefix.child_slot; - NodePtr::FreeNode(art, entry.right); - entry.right = r_child; + auto r_child_ptr = *r_prefix.child_slot; + NodePtr::FreeNode(art, entry.right_ptr); + entry.right_ptr = r_child_ptr; auto depth = entry.depth + l_prefix.data[count]; - Emplace(*l_prefix.child_slot, entry.right, entry.status, depth); + Emplace(*l_prefix.child_slot, entry.right_ptr, entry.status, depth); return; } @@ -308,13 +308,13 @@ void ARTMerger::MergePrefixes(NodeEntry &entry) { if (r_prefix.data[count] == max_count) { // We exhausted the right prefix. // Ensure that we continue merging into left. - swap(entry.left, entry.right); - MergeNodeAndPrefix(*r_prefix.child_slot, entry.right, entry.status, entry.depth + max_count, max_count); + swap(entry.left_ptr, entry.right_ptr); + MergeNodeAndPrefix(*r_prefix.child_slot, entry.right_ptr, entry.status, entry.depth + max_count, max_count); return; } // We exhausted the left prefix. - MergeNodeAndPrefix(*l_prefix.child_slot, entry.right, entry.status, entry.depth + max_count, max_count); + MergeNodeAndPrefix(*l_prefix.child_slot, entry.right_ptr, entry.status, entry.depth + max_count, max_count); } } // namespace duckdb diff --git a/src/duckdb/src/execution/index/art/base_leaf.cpp b/src/duckdb/src/execution/index/art/base_leaf.cpp index 7de99ffc3..7f30cac18 100644 --- a/src/duckdb/src/execution/index/art/base_leaf.cpp +++ b/src/duckdb/src/execution/index/art/base_leaf.cpp @@ -30,8 +30,8 @@ void BaseLeaf::InsertByteInternal(BaseLeaf &n, const uint8_ } template -NodeHandle BaseLeaf::DeleteByteInternal(ART &art, NodePtr &node, const uint8_t byte) { - NodeHandle handle(art, node); +NodeHandle BaseLeaf::DeleteByteInternal(ART &art, NodePtr &node_ptr, const uint8_t byte) { + NodeHandle handle(art, node_ptr); auto &n = handle.Get>(); uint8_t child_pos = 0; @@ -53,9 +53,9 @@ NodeHandle BaseLeaf::DeleteByteInternal(ART &art, NodePtr & // Node7Leaf //===--------------------------------------------------------------------===// -void Node7Leaf::InsertByte(ART &art, NodePtr &node, const uint8_t byte) { +void Node7Leaf::InsertByte(ART &art, NodePtr &node_ptr, const uint8_t byte) { { - NodeHandle handle(art, node); + NodeHandle handle(art, node_ptr); auto &n7 = handle.Get(); if (n7.count != CAPACITY) { @@ -64,15 +64,15 @@ void Node7Leaf::InsertByte(ART &art, NodePtr &node, const uint8_t byte) { } } // The node is full. Grow to Node15. - auto node7 = node; - Node15Leaf::GrowNode7Leaf(art, node, node7); - Node15Leaf::InsertByte(art, node, byte); + auto node7_leaf_ptr = node_ptr; + Node15Leaf::GrowNode7Leaf(art, node_ptr, node7_leaf_ptr); + Node15Leaf::InsertByte(art, node_ptr, byte); } -void Node7Leaf::DeleteByte(ART &art, NodePtr &node, NodePtr &prefix, const uint8_t byte, const ARTKey &row_id) { +void Node7Leaf::DeleteByte(ART &art, NodePtr &node_ptr, NodePtr &parent_ptr, const uint8_t byte, const ARTKey &row_id) { idx_t remainder; { - auto n7_handle = DeleteByteInternal(art, node, byte); + auto n7_handle = DeleteByteInternal(art, node_ptr, byte); auto &n7 = n7_handle.Get(); if (n7.count != 1) { @@ -80,97 +80,97 @@ void Node7Leaf::DeleteByte(ART &art, NodePtr &node, NodePtr &prefix, const uint8 } // Compress one-way nodes. - D_ASSERT(node.GetGateStatus() == GateStatus::GATE_NOT_SET); + D_ASSERT(node_ptr.GetGateStatus() == GateStatus::GATE_NOT_SET); // Get the remaining row ID. remainder = UnsafeNumericCast(row_id.GetRowId()) & AND_LAST_BYTE; remainder |= UnsafeNumericCast(n7.key[0]); } // Free the prefix (nodes) and inline the remainder. - if (prefix.GetType() == NType::PREFIX) { - NodePtr::FreeTree(art, prefix); - Leaf::New(prefix, UnsafeNumericCast(remainder)); + if (parent_ptr.GetType() == NType::PREFIX) { + NodePtr::FreeTree(art, parent_ptr); + Leaf::New(parent_ptr, UnsafeNumericCast(remainder)); return; } // Free the Node7Leaf and inline the remainder. - NodePtr::FreeNode(art, node); - Leaf::New(node, UnsafeNumericCast(remainder)); + NodePtr::FreeNode(art, node_ptr); + Leaf::New(node_ptr, UnsafeNumericCast(remainder)); } -void Node7Leaf::ShrinkNode15Leaf(ART &art, NodePtr &node7_leaf, NodePtr &node15_leaf) { +void Node7Leaf::ShrinkNode15Leaf(ART &art, NodePtr &node7_leaf_ptr, NodePtr &node15_leaf_ptr) { { - auto n7_handle = New(art, node7_leaf); + auto n7_handle = New(art, node7_leaf_ptr); auto &n7 = n7_handle.Get(); - NodeHandle n15_handle(art, node15_leaf); + NodeHandle n15_handle(art, node15_leaf_ptr); auto &n15 = n15_handle.Get(); - node7_leaf.SetGateStatus(node15_leaf.GetGateStatus()); + node7_leaf_ptr.SetGateStatus(node15_leaf_ptr.GetGateStatus()); n7.count = n15.count; for (uint8_t i = 0; i < n15.count; i++) { n7.key[i] = n15.key[i]; } } - NodePtr::FreeNode(art, node15_leaf); + NodePtr::FreeNode(art, node15_leaf_ptr); } //===--------------------------------------------------------------------===// // Node15Leaf //===--------------------------------------------------------------------===// -void Node15Leaf::InsertByte(ART &art, NodePtr &node, const uint8_t byte) { +void Node15Leaf::InsertByte(ART &art, NodePtr &node_ptr, const uint8_t byte) { { - NodeHandle n15_handle(art, node); + NodeHandle n15_handle(art, node_ptr); auto &n15 = n15_handle.Get(); if (n15.count != CAPACITY) { InsertByteInternal(n15, byte); return; } } - auto node15 = node; - Node256Leaf::GrowNode15Leaf(art, node, node15); - Node256Leaf::InsertByte(art, node, byte); + auto node15_leaf_ptr = node_ptr; + Node256Leaf::GrowNode15Leaf(art, node_ptr, node15_leaf_ptr); + Node256Leaf::InsertByte(art, node_ptr, byte); } -void Node15Leaf::DeleteByte(ART &art, NodePtr &node, const uint8_t byte) { +void Node15Leaf::DeleteByte(ART &art, NodePtr &node_ptr, const uint8_t byte) { { - auto n15_handle = DeleteByteInternal(art, node, byte); + auto n15_handle = DeleteByteInternal(art, node_ptr, byte); auto &n15 = n15_handle.Get(); if (n15.count >= Node7Leaf::CAPACITY) { return; } } - auto node15 = node; - Node7Leaf::ShrinkNode15Leaf(art, node, node15); + auto node15_leaf_ptr = node_ptr; + Node7Leaf::ShrinkNode15Leaf(art, node_ptr, node15_leaf_ptr); } -void Node15Leaf::GrowNode7Leaf(ART &art, NodePtr &node15_leaf, NodePtr &node7_leaf) { +void Node15Leaf::GrowNode7Leaf(ART &art, NodePtr &node15_leaf_ptr, NodePtr &node7_leaf_ptr) { { - NodeHandle n7_handle(art, node7_leaf); + NodeHandle n7_handle(art, node7_leaf_ptr); auto &n7 = n7_handle.Get(); - auto n15_handle = New(art, node15_leaf); + auto n15_handle = New(art, node15_leaf_ptr); auto &n15 = n15_handle.Get(); - node15_leaf.SetGateStatus(node7_leaf.GetGateStatus()); + node15_leaf_ptr.SetGateStatus(node7_leaf_ptr.GetGateStatus()); n15.count = n7.count; for (uint8_t i = 0; i < n7.count; i++) { n15.key[i] = n7.key[i]; } } - NodePtr::FreeNode(art, node7_leaf); + NodePtr::FreeNode(art, node7_leaf_ptr); } -void Node15Leaf::ShrinkNode256Leaf(ART &art, NodePtr &node15_leaf, NodePtr &node256_leaf) { +void Node15Leaf::ShrinkNode256Leaf(ART &art, NodePtr &node15_leaf_ptr, NodePtr &node256_leaf_ptr) { { - auto n15_handle = New(art, node15_leaf); + auto n15_handle = New(art, node15_leaf_ptr); auto &n15 = n15_handle.Get(); - NodeHandle n256_handle(art, node256_leaf); + NodeHandle n256_handle(art, node256_leaf_ptr); auto &n256 = n256_handle.Get(); - node15_leaf.SetGateStatus(node256_leaf.GetGateStatus()); + node15_leaf_ptr.SetGateStatus(node256_leaf_ptr.GetGateStatus()); ValidityMask mask(&n256.mask[0], Node256::CAPACITY); for (uint16_t i = 0; i < Node256::CAPACITY; i++) { @@ -180,7 +180,7 @@ void Node15Leaf::ShrinkNode256Leaf(ART &art, NodePtr &node15_leaf, NodePtr &node } } } - NodePtr::FreeNode(art, node256_leaf); + NodePtr::FreeNode(art, node256_leaf_ptr); } } // namespace duckdb diff --git a/src/duckdb/src/execution/index/art/base_node.cpp b/src/duckdb/src/execution/index/art/base_node.cpp index d0f41cf03..1ea9af303 100644 --- a/src/duckdb/src/execution/index/art/base_node.cpp +++ b/src/duckdb/src/execution/index/art/base_node.cpp @@ -11,7 +11,7 @@ namespace duckdb { //===--------------------------------------------------------------------===// template -void BaseNode::InsertChildInternal(BaseNode &n, const uint8_t byte, const NodePtr child) { +void BaseNode::InsertChildInternal(BaseNode &n, const uint8_t byte, const NodePtr child_ptr) { // Still space. Insert the child. uint8_t child_pos = 0; while (child_pos < n.count && n.key[child_pos] < byte) { @@ -25,13 +25,13 @@ void BaseNode::InsertChildInternal(BaseNode &n, const uint8 } n.key[child_pos] = byte; - n.children[child_pos] = child; + n.children[child_pos] = child_ptr; n.count++; } template -NodeHandle BaseNode::DeleteChildInternal(ART &art, NodePtr &node, const uint8_t byte) { - NodeHandle handle(art, node); +NodeHandle BaseNode::DeleteChildInternal(ART &art, NodePtr &node_ptr, const uint8_t byte) { + NodeHandle handle(art, node_ptr); auto &n = handle.Get>(); uint8_t child_pos = 0; @@ -58,29 +58,29 @@ NodeHandle BaseNode::DeleteChildInternal(ART &art, NodePtr // Node4 //===--------------------------------------------------------------------===// -void Node4::InsertChild(ART &art, NodePtr &node, const uint8_t byte, const NodePtr child) { +void Node4::InsertChild(ART &art, NodePtr &node_ptr, const uint8_t byte, const NodePtr child_ptr) { { - NodeHandle handle(art, node); + NodeHandle handle(art, node_ptr); auto &n = handle.Get(); if (n.count != CAPACITY) { - InsertChildInternal(n, byte, child); + InsertChildInternal(n, byte, child_ptr); return; } } // The node is full. // Grow to Node16. - auto node4 = node; - Node16::GrowNode4(art, node, node4); - Node16::InsertChild(art, node, byte, child); + auto node4_ptr = node_ptr; + Node16::GrowNode4(art, node_ptr, node4_ptr); + Node16::InsertChild(art, node_ptr, byte, child_ptr); } -void Node4::DeleteChild(ART &art, NodePtr &node, NodePtr &parent, const uint8_t byte, const GateStatus status) { - NodePtr child; +void Node4::DeleteChild(ART &art, NodePtr &node_ptr, NodePtr &parent_ptr, const uint8_t byte, const GateStatus status) { + NodePtr child_ptr; uint8_t remaining_byte; { - auto handle = DeleteChildInternal(art, node, byte); + auto handle = DeleteChildInternal(art, node_ptr, byte); auto &n = handle.Get(); if (n.count != 1) { @@ -88,24 +88,24 @@ void Node4::DeleteChild(ART &art, NodePtr &node, NodePtr &parent, const uint8_t } // Compress one-way nodes. - child = n.children[0]; + child_ptr = n.children[0]; remaining_byte = n.key[0]; } - auto prev_node4_status = node.GetGateStatus(); - NodePtr::FreeNode(art, node); + auto prev_node4_status = node_ptr.GetGateStatus(); + NodePtr::FreeNode(art, node_ptr); // Propagate both the prev_node_4 status and the general gate status (if the gate was earlier on), // since the concatenation logic depends on both. - Prefix::Concat(art, parent, node, child, remaining_byte, prev_node4_status, status); + Prefix::Concat(art, parent_ptr, node_ptr, child_ptr, remaining_byte, prev_node4_status, status); } -void Node4::ShrinkNode16(ART &art, NodePtr &node4, NodePtr &node16) { +void Node4::ShrinkNode16(ART &art, NodePtr &node4_ptr, NodePtr &node16_ptr) { { - auto n4_handle = New(art, node4); + auto n4_handle = New(art, node4_ptr); auto &n4 = n4_handle.Get(); - node4.SetGateStatus(node16.GetGateStatus()); + node4_ptr.SetGateStatus(node16_ptr.GetGateStatus()); - NodeHandle n16_handle(art, node16); + NodeHandle n16_handle(art, node16_ptr); auto &n16 = n16_handle.Get(); n4.count = n16.count; @@ -114,50 +114,50 @@ void Node4::ShrinkNode16(ART &art, NodePtr &node4, NodePtr &node16) { n4.children[i] = n16.children[i]; } } - NodePtr::FreeNode(art, node16); + NodePtr::FreeNode(art, node16_ptr); } //===--------------------------------------------------------------------===// // Node16 //===--------------------------------------------------------------------===// -void Node16::InsertChild(ART &art, NodePtr &node, const uint8_t byte, const NodePtr child) { +void Node16::InsertChild(ART &art, NodePtr &node_ptr, const uint8_t byte, const NodePtr child_ptr) { { - NodeHandle handle(art, node); + NodeHandle handle(art, node_ptr); auto &n = handle.Get(); if (n.count != CAPACITY) { - InsertChildInternal(n, byte, child); + InsertChildInternal(n, byte, child_ptr); return; } } // The node is full. // Grow to Node48. - auto node16 = node; - Node48::GrowNode16(art, node, node16); - Node48::InsertChild(art, node, byte, child); + auto node16_ptr = node_ptr; + Node48::GrowNode16(art, node_ptr, node16_ptr); + Node48::InsertChild(art, node_ptr, byte, child_ptr); } -void Node16::DeleteChild(ART &art, NodePtr &node, const uint8_t byte) { +void Node16::DeleteChild(ART &art, NodePtr &node_ptr, const uint8_t byte) { { - auto handle = DeleteChildInternal(art, node, byte); + auto handle = DeleteChildInternal(art, node_ptr, byte); auto &n = handle.Get(); if (n.count >= Node4::CAPACITY) { return; } } // Shrink node to Node4. - auto node16 = node; - Node4::ShrinkNode16(art, node, node16); + auto node16_ptr = node_ptr; + Node4::ShrinkNode16(art, node_ptr, node16_ptr); } -void Node16::GrowNode4(ART &art, NodePtr &node16, NodePtr &node4) { +void Node16::GrowNode4(ART &art, NodePtr &node16_ptr, NodePtr &node4_ptr) { { - NodeHandle n4_handle(art, node4); + NodeHandle n4_handle(art, node4_ptr); auto &n4 = n4_handle.Get(); - auto n16_handle = New(art, node16); + auto n16_handle = New(art, node16_ptr); auto &n16 = n16_handle.Get(); - node16.SetGateStatus(node4.GetGateStatus()); + node16_ptr.SetGateStatus(node4_ptr.GetGateStatus()); n16.count = n4.count; for (uint8_t i = 0; i < n4.count; i++) { @@ -165,16 +165,16 @@ void Node16::GrowNode4(ART &art, NodePtr &node16, NodePtr &node4) { n16.children[i] = n4.children[i]; } } - NodePtr::FreeNode(art, node4); + NodePtr::FreeNode(art, node4_ptr); } -void Node16::ShrinkNode48(ART &art, NodePtr &node16, NodePtr &node48) { +void Node16::ShrinkNode48(ART &art, NodePtr &node16_ptr, NodePtr &node48_ptr) { { - auto n16_handle = New(art, node16); + auto n16_handle = New(art, node16_ptr); auto &n16 = n16_handle.Get(); - node16.SetGateStatus(node48.GetGateStatus()); + node16_ptr.SetGateStatus(node48_ptr.GetGateStatus()); - NodeHandle n48_handle(art, node48); + NodeHandle n48_handle(art, node48_ptr); auto &n48 = n48_handle.Get(); n16.count = 0; @@ -186,7 +186,7 @@ void Node16::ShrinkNode48(ART &art, NodePtr &node16, NodePtr &node48) { } } } - NodePtr::FreeNode(art, node48); + NodePtr::FreeNode(art, node48_ptr); } } // namespace duckdb diff --git a/src/duckdb/src/execution/index/art/const_prefix_handle.cpp b/src/duckdb/src/execution/index/art/const_prefix_handle.cpp index a03eddbd4..67d16be3b 100644 --- a/src/duckdb/src/execution/index/art/const_prefix_handle.cpp +++ b/src/duckdb/src/execution/index/art/const_prefix_handle.cpp @@ -16,7 +16,7 @@ constexpr uint8_t PREFIX_ASCII_PRINTABLE_MIN = 32; constexpr uint8_t PREFIX_ASCII_PRINTABLE_MAX = 126; } // namespace -string ConstPrefixHandle::ToString(ART &art, const NodePtr &node, const ToStringOptions &options) { +string ConstPrefixHandle::ToString(ART &art, const NodePtr &node_ptr, const ToStringOptions &options) { auto format_byte = [&](const uint8_t byte) { if (!options.inside_gate && options.display_ascii && byte >= PREFIX_ASCII_PRINTABLE_MIN && byte <= PREFIX_ASCII_PRINTABLE_MAX) { @@ -28,15 +28,15 @@ string ConstPrefixHandle::ToString(ART &art, const NodePtr &node, const ToString // Print prefix bytes (single branch, child follows on next line) auto str = StringUtil::Format("%s%sPrefix: |", options.tree_prefix, PREFIX_BRANCH_END); auto child_options = options; - auto tail = - Iterator(art, node, true, [&](const ConstNodeHandle &handle, const_data_ptr_t data, const NodePtr &child) { - for (idx_t i = 0; i < data[art.PrefixCount()]; i++) { - str += StringUtil::Format("%s|", format_byte(data[i])); - if (options.key_path) { - child_options.key_depth++; - } - } - }); + auto tail = Iterator(art, node_ptr, true, + [&](const ConstNodeHandle &handle, const_data_ptr_t data, const NodePtr &child_ptr) { + for (idx_t i = 0; i < data[art.PrefixCount()]; i++) { + str += StringUtil::Format("%s|", format_byte(data[i])); + if (options.key_path) { + child_options.key_depth++; + } + } + }); str += "\n"; // Child is printed indented under the prefix (not as a sibling) @@ -45,12 +45,12 @@ string ConstPrefixHandle::ToString(ART &art, const NodePtr &node, const ToString return str; } -void ConstPrefixHandle::Verify(ART &art, const NodePtr &node) { - auto tail = - Iterator(art, node, true, [&](const ConstNodeHandle &handle, const_data_ptr_t data, const NodePtr &child) { - D_ASSERT(data[art.PrefixCount()] != 0); - D_ASSERT(data[art.PrefixCount()] <= art.PrefixCount()); - }); +void ConstPrefixHandle::Verify(ART &art, const NodePtr &node_ptr) { + auto tail = Iterator(art, node_ptr, true, + [&](const ConstNodeHandle &handle, const_data_ptr_t data, const NodePtr &child_ptr) { + D_ASSERT(data[art.PrefixCount()] != 0); + D_ASSERT(data[art.PrefixCount()] <= art.PrefixCount()); + }); tail.Verify(art); } diff --git a/src/duckdb/src/execution/index/art/iterator.cpp b/src/duckdb/src/execution/index/art/iterator.cpp index f1a0d72b7..a05340a7d 100644 --- a/src/duckdb/src/execution/index/art/iterator.cpp +++ b/src/duckdb/src/execution/index/art/iterator.cpp @@ -94,9 +94,9 @@ ARTScanProgress Iterator::Scan(const ARTKey &upper_bound, Output &output, bool e auto key_len = current_key.Size() - nested_depth; output.SetKey(current_key, key_len); - switch (last_leaf.GetType()) { + switch (last_leaf_ptr.GetType()) { case NType::LEAF_INLINED: { - if (!output.TryAdd(last_leaf.GetRowId())) { + if (!output.TryAdd(last_leaf_ptr.GetRowId())) { return ARTScanProgress::PAUSED; } break; @@ -105,7 +105,8 @@ ARTScanProgress Iterator::Scan(const ARTKey &upper_bound, Output &output, bool e D_ASSERT(nested_depth == 0); if (!resume_state.has_cached_row_ids) { resume_state.cached_row_ids.clear(); - Leaf::DeprecatedGetRowIds(art, last_leaf, resume_state.cached_row_ids, NumericLimits::Maximum()); + Leaf::DeprecatedGetRowIds(art, last_leaf_ptr, resume_state.cached_row_ids, + NumericLimits::Maximum()); resume_state.cached_row_ids_it = resume_state.cached_row_ids.begin(); resume_state.has_cached_row_ids = true; } @@ -130,7 +131,7 @@ ARTScanProgress Iterator::Scan(const ARTKey &upper_bound, Output &output, bool e resume_state.nested_started = true; } // Try to output the next inlined leaf. - while (last_leaf.GetNextByte(art, resume_state.nested_byte)) { + while (last_leaf_ptr.GetNextByte(art, resume_state.nested_byte)) { row_id[ROW_ID_SIZE - 1] = resume_state.nested_byte; ARTKey rid_key(&row_id[0], ROW_ID_SIZE); if (!output.TryAdd(rid_key.GetRowId())) { @@ -161,16 +162,16 @@ template ARTScanProgress Iterator::Scan(const ARTKey &, RowIdSet template ARTScanProgress Iterator::Scan(const ARTKey &, RowIdVectorOutput &, bool); template ARTScanProgress Iterator::Scan(const ARTKey &, KeyRowIdOutput &, bool); -void Iterator::FindMinimum(NodePtr current) { - while (current.HasMetadata()) { +void Iterator::FindMinimum(NodePtr current_ptr) { + while (current_ptr.HasMetadata()) { // Found the minimum. - if (current.IsAnyLeaf()) { - last_leaf = current; + if (current_ptr.IsAnyLeaf()) { + last_leaf_ptr = current_ptr; return; } // We are passing a gate node. - if (current.GetGateStatus() == GateStatus::GATE_SET) { + if (current_ptr.GetGateStatus() == GateStatus::GATE_SET) { D_ASSERT(status == GateStatus::GATE_NOT_SET); status = GateStatus::GATE_SET; entered_nested_leaf = true; @@ -178,10 +179,10 @@ void Iterator::FindMinimum(NodePtr current) { } // Traverse the prefix. - if (current.GetType() == NType::PREFIX) { - NodePtr child; + if (current_ptr.GetType() == NType::PREFIX) { + NodePtr child_ptr; { - ConstNodeHandle handle(art, current); + ConstNodeHandle handle(art, current_ptr); auto data = handle.GetPtr(); auto count = data[art.PrefixCount()]; @@ -194,17 +195,17 @@ void Iterator::FindMinimum(NodePtr current) { } } // Copy the child locator before releasing the prefix handle. - child = ConstPrefixHandle::ChildRef(art, handle); + child_ptr = ConstPrefixHandle::ChildRef(art, handle); } - nodes.emplace(current, 0); - current = child; + nodes.emplace(current_ptr, 0); + current_ptr = child_ptr; continue; } // Go to the leftmost entry in the current node. uint8_t byte = 0; - auto child = current.GetNextChildNode(art, byte); - D_ASSERT(child); + auto child_ptr = current_ptr.GetNextChildNode(art, byte); + D_ASSERT(child_ptr); // Move to the leftmost node. current_key.Push(byte); @@ -213,73 +214,73 @@ void Iterator::FindMinimum(NodePtr current) { nested_depth++; D_ASSERT(nested_depth < Prefix::ROW_ID_SIZE); } - nodes.emplace(current, byte); - current = child.Get(); + nodes.emplace(current_ptr, byte); + current_ptr = child_ptr.Get(); } // Should always have a node with metadata. throw InternalException("ART Iterator::FindMinimum: Reached node without metadata"); } -bool Iterator::LowerBound(NodePtr current, const ARTKey &key, const bool equal) { +bool Iterator::LowerBound(NodePtr current_ptr, const ARTKey &key, const bool equal) { idx_t depth = 0; - while (current.HasMetadata()) { + while (current_ptr.HasMetadata()) { // We found any leaf node, or a gate. - if (current.IsAnyLeaf() || current.GetGateStatus() == GateStatus::GATE_SET) { + if (current_ptr.IsAnyLeaf() || current_ptr.GetGateStatus() == GateStatus::GATE_SET) { D_ASSERT(status == GateStatus::GATE_NOT_SET); D_ASSERT(current_key.Size() == key.len); if (!equal && current_key.Contains(key)) { return Next(); } - if (current.GetGateStatus() == GateStatus::GATE_SET) { - FindMinimum(current); + if (current_ptr.GetGateStatus() == GateStatus::GATE_SET) { + FindMinimum(current_ptr); } else { - last_leaf = current; + last_leaf_ptr = current_ptr; } return true; } - D_ASSERT(current.GetGateStatus() == GateStatus::GATE_NOT_SET); - if (current.GetType() != NType::PREFIX) { + D_ASSERT(current_ptr.GetGateStatus() == GateStatus::GATE_NOT_SET); + if (current_ptr.GetType() != NType::PREFIX) { auto next_byte = key[depth]; - auto child = current.GetNextChildNode(art, next_byte); + auto child_ptr = current_ptr.GetNextChildNode(art, next_byte); // The key is greater than any key in this subtree. - if (!child) { + if (!child_ptr) { return Next(); } current_key.Push(next_byte); - nodes.emplace(current, next_byte); + nodes.emplace(current_ptr, next_byte); // We return the minimum because all keys are greater than the lower bound. if (next_byte > key[depth]) { - FindMinimum(child.Get()); + FindMinimum(child_ptr.Get()); return true; } // Move to the child and increment depth. - current = child.Get(); + current_ptr = child_ptr.Get(); depth++; continue; } // Copy the prefix bytes and child while the prefix is pinned. uint8_t prefix_count; - NodePtr prefix_child; + NodePtr prefix_child_ptr; const auto prefix_offset = current_key.Size(); { - ConstNodeHandle handle(art, current); + ConstNodeHandle handle(art, current_ptr); auto data = handle.GetPtr(); prefix_count = data[art.PrefixCount()]; // Copy the child locator before releasing the prefix handle. - prefix_child = ConstPrefixHandle::ChildRef(art, handle); + prefix_child_ptr = ConstPrefixHandle::ChildRef(art, handle); for (idx_t i = 0; i < prefix_count; i++) { current_key.Push(data[i]); } - nodes.emplace(current, 0); + nodes.emplace(current_ptr, 0); } // Compare the copied prefix bytes with the key bytes. @@ -295,14 +296,14 @@ bool Iterator::LowerBound(NodePtr current, const ARTKey &key, const bool equal) // I.e., the subsequent node is greater than the key. Thus, the minimum is // the lower bound. if (current_key[prefix_offset + i] > key[depth + i]) { - FindMinimum(prefix_child); + FindMinimum(prefix_child_ptr); return true; } } // The prefix matches the key. depth += prefix_count; - current = prefix_child; + current_ptr = prefix_child_ptr; } // Should always have a node with metadata. throw InternalException("ART Iterator::LowerBound: Reached node without metadata"); @@ -311,9 +312,9 @@ bool Iterator::LowerBound(NodePtr current, const ARTKey &key, const bool equal) bool Iterator::Next() { while (!nodes.empty()) { auto &top = nodes.top(); - D_ASSERT(!top.node.IsAnyLeaf()); + D_ASSERT(!top.node_ptr.IsAnyLeaf()); - if (top.node.GetType() == NType::PREFIX) { + if (top.node_ptr.GetType() == NType::PREFIX) { PopNode(); continue; } @@ -326,8 +327,8 @@ bool Iterator::Next() { } top.byte++; - auto child = top.node.GetNextChildNode(art, top.byte); - if (!child) { + auto child_ptr = top.node_ptr.GetNextChildNode(art, top.byte); + if (!child_ptr) { // No more children of this node. // Move up the tree by popping the key byte of the current node. PopNode(); @@ -340,17 +341,17 @@ bool Iterator::Next() { row_id[nested_depth - 1] = top.byte; } - FindMinimum(child.Get()); + FindMinimum(child_ptr.Get()); return true; } return false; } void Iterator::PopNode() { - auto gate_status = nodes.top().node.GetGateStatus(); + auto gate_status = nodes.top().node_ptr.GetGateStatus(); // Pop the byte and the node. - if (nodes.top().node.GetType() != NType::PREFIX) { + if (nodes.top().node_ptr.GetType() != NType::PREFIX) { current_key.Pop(1); if (status == GateStatus::GATE_SET) { nested_depth--; @@ -359,7 +360,7 @@ void Iterator::PopNode() { } else { // Pop all prefix bytes and the node. - ConstNodeHandle handle(art, nodes.top().node); + ConstNodeHandle handle(art, nodes.top().node_ptr); auto data = handle.GetPtr(); auto prefix_byte_count = data[art.PrefixCount()]; current_key.Pop(prefix_byte_count); diff --git a/src/duckdb/src/execution/index/art/leaf.cpp b/src/duckdb/src/execution/index/art/leaf.cpp index 7064df238..d2901c546 100644 --- a/src/duckdb/src/execution/index/art/leaf.cpp +++ b/src/duckdb/src/execution/index/art/leaf.cpp @@ -13,17 +13,17 @@ namespace duckdb { -void Leaf::New(NodePtr &node, const row_t row_id) { +void Leaf::New(NodePtr &node_ptr, const row_t row_id) { D_ASSERT(row_id < MAX_ROW_ID_LOCAL); - node.Clear(); - node.SetMetadata(static_cast(INLINED)); - node.SetRowId(row_id); + node_ptr.Clear(); + node_ptr.SetMetadata(static_cast(INLINED)); + node_ptr.SetRowId(row_id); } -void Leaf::MergeInlined(ArenaAllocator &arena, ART &art, NodePtr &left, NodePtr &right, GateStatus status, +void Leaf::MergeInlined(ArenaAllocator &arena, ART &art, NodePtr &left_ptr, NodePtr &right_ptr, GateStatus status, idx_t depth) { - D_ASSERT(left.GetType() == NType::LEAF_INLINED); - D_ASSERT(right.GetType() == NType::LEAF_INLINED); + D_ASSERT(left_ptr.GetType() == NType::LEAF_INLINED); + D_ASSERT(right_ptr.GetType() == NType::LEAF_INLINED); status = status == GateStatus::GATE_NOT_SET ? GateStatus::GATE_SET : GateStatus::GATE_NOT_SET; if (status == GateStatus::GATE_SET) { @@ -36,8 +36,8 @@ void Leaf::MergeInlined(ArenaAllocator &arena, ART &art, NodePtr &left, NodePtr // a prefix with an inlined leaf as its only child. // Get the corresponding row IDs and their ART keys. - auto left_row_id = left.GetRowId(); - auto right_row_id = right.GetRowId(); + auto left_row_id = left_ptr.GetRowId(); + auto right_row_id = right_ptr.GetRowId(); auto left_key = ARTKey::CreateARTKey(arena, left_row_id); auto right_key = ARTKey::CreateARTKey(arena, right_row_id); @@ -58,80 +58,80 @@ void Leaf::MergeInlined(ArenaAllocator &arena, ART &art, NodePtr &left, NodePtr // with a single inlined leaf as their child. Node4::New(art, merged_root_ptr); - NodePtr left_child; - Leaf::New(left_child, left_row_id); - Node4::InsertChild(art, merged_root_ptr, left_byte, left_child); + NodePtr left_child_ptr; + Leaf::New(left_child_ptr, left_row_id); + Node4::InsertChild(art, merged_root_ptr, left_byte, left_child_ptr); - NodePtr right_child; - Leaf::New(right_child, right_row_id); - Node4::InsertChild(art, merged_root_ptr, right_byte, right_child); + NodePtr right_child_ptr; + Leaf::New(right_child_ptr, right_row_id); + Node4::InsertChild(art, merged_root_ptr, right_byte, right_child_ptr); } if (pos != depth) { // The row IDs share a prefix. auto chain = PrefixHandle::New(art, left_key, depth, pos - depth); chain.tail.Child(art) = merged_root_ptr; - merged_root_ptr = chain.root; + merged_root_ptr = chain.root_ptr; } merged_root_ptr.SetGateStatus(status); - left = merged_root_ptr; + left_ptr = merged_root_ptr; } -void Leaf::TransformToNested(ART &art, NodePtr &node) { - D_ASSERT(node.GetType() == LEAF); +void Leaf::TransformToNested(ART &art, NodePtr &node_ptr) { + D_ASSERT(node_ptr.GetType() == LEAF); ArenaAllocator arena(Allocator::Get(art.db)); - NodePtr root = NodePtr(); + NodePtr root_ptr = NodePtr(); // Move all row IDs into the nested leaf. - NodePtr current = node; - while (current.HasMetadata()) { - ConstNodeHandle handle(art, current); + NodePtr current_ptr = node_ptr; + while (current_ptr.HasMetadata()) { + ConstNodeHandle handle(art, current_ptr); auto &leaf = handle.Get(); for (uint8_t i = 0; i < leaf.count; i++) { auto row_id = ARTKey::CreateARTKey(arena, leaf.row_ids[i]); - auto conflict_type = ARTOperator::Insert(arena, art, root, row_id, 0, row_id, GateStatus::GATE_SET, + auto conflict_type = ARTOperator::Insert(arena, art, root_ptr, row_id, 0, row_id, GateStatus::GATE_SET, DeleteIndexInfo(), IndexAppendMode::INSERT_DUPLICATES); if (conflict_type != ARTConflictType::NO_CONFLICT) { throw InternalException("invalid conflict type in Leaf::TransformToNested"); } } - current = leaf.next_leaf; + current_ptr = leaf.next_leaf_ptr; } - root.SetGateStatus(GateStatus::GATE_SET); - DeprecatedFree(art, node); - node = root; + root_ptr.SetGateStatus(GateStatus::GATE_SET); + DeprecatedFree(art, node_ptr); + node_ptr = root_ptr; } -void Leaf::TransformToDeprecated(ART &art, NodePtr &node) { - D_ASSERT(node.GetGateStatus() == GateStatus::GATE_SET || node.GetType() == LEAF); +void Leaf::TransformToDeprecated(ART &art, NodePtr &node_ptr) { + D_ASSERT(node_ptr.GetGateStatus() == GateStatus::GATE_SET || node_ptr.GetType() == LEAF); // Early-out, if we never transformed this leaf. - if (node.GetGateStatus() == GateStatus::GATE_NOT_SET) { + if (node_ptr.GetGateStatus() == GateStatus::GATE_NOT_SET) { return; } // Collect all row IDs and free the nested leaf. set row_ids; Iterator it(art); - it.FindMinimum(node); + it.FindMinimum(node_ptr); ARTKey empty_key = ARTKey(); RowIdSetOutput output(row_ids, NumericLimits().Maximum()); it.Scan(empty_key, output, false); - NodePtr::FreeTree(art, node); + NodePtr::FreeTree(art, node_ptr); D_ASSERT(row_ids.size() > 1); // Create the deprecated leaves. idx_t remaining = row_ids.size(); auto row_ids_it = row_ids.begin(); - reference leaf_ref(node); + reference leaf_ptr_ref(node_ptr); while (remaining) { - leaf_ref.get() = NodePtr::GetAllocator(art, LEAF).New(); - leaf_ref.get().SetMetadata(static_cast(LEAF)); + leaf_ptr_ref.get() = NodePtr::GetAllocator(art, LEAF).New(); + leaf_ptr_ref.get().SetMetadata(static_cast(LEAF)); - auto &leaf = NodePtr::Ref(art, leaf_ref, LEAF); + auto &leaf = NodePtr::Ref(art, leaf_ptr_ref, LEAF); auto min = MinValue(UnsafeNumericCast(LEAF_SIZE), remaining); leaf.count = UnsafeNumericCast(min); @@ -141,8 +141,8 @@ void Leaf::TransformToDeprecated(ART &art, NodePtr &node) { } remaining -= leaf.count; - leaf_ref = leaf.next_leaf; - leaf.next_leaf.Clear(); + leaf_ptr_ref = leaf.next_leaf_ptr; + leaf.next_leaf_ptr.Clear(); } } @@ -150,26 +150,26 @@ void Leaf::TransformToDeprecated(ART &art, NodePtr &node) { // Deprecated code paths. //===--------------------------------------------------------------------===// -void Leaf::DeprecatedFree(ART &art, NodePtr &node) { - D_ASSERT(node.GetType() == LEAF); - while (node.HasMetadata()) { - NodePtr next; +void Leaf::DeprecatedFree(ART &art, NodePtr &node_ptr) { + D_ASSERT(node_ptr.GetType() == LEAF); + while (node_ptr.HasMetadata()) { + NodePtr next_ptr; { - ConstNodeHandle handle(art, node); - next = handle.Get().next_leaf; + ConstNodeHandle handle(art, node_ptr); + next_ptr = handle.Get().next_leaf_ptr; } - NodePtr::FreeNode(art, node); - node = next; + NodePtr::FreeNode(art, node_ptr); + node_ptr = next_ptr; } - node.Clear(); + node_ptr.Clear(); } -bool Leaf::DeprecatedGetRowIds(const ART &art, const NodePtr &node, set &row_ids, const idx_t max_count) { - D_ASSERT(node.GetType() == LEAF); +bool Leaf::DeprecatedGetRowIds(const ART &art, const NodePtr &node_ptr, set &row_ids, const idx_t max_count) { + D_ASSERT(node_ptr.GetType() == LEAF); - NodePtr current = node; - while (current.HasMetadata()) { - ConstNodeHandle handle(art, current); + NodePtr current_ptr = node_ptr; + while (current_ptr.HasMetadata()) { + ConstNodeHandle handle(art, current_ptr); auto &leaf = handle.Get(); if (row_ids.size() + leaf.count > max_count) { return false; @@ -177,28 +177,28 @@ bool Leaf::DeprecatedGetRowIds(const ART &art, const NodePtr &node, set & for (uint8_t i = 0; i < leaf.count; i++) { row_ids.insert(leaf.row_ids[i]); } - current = leaf.next_leaf; + current_ptr = leaf.next_leaf_ptr; } return true; } -void Leaf::DeprecatedVacuum(ART &art, NodePtr node) { - D_ASSERT(node.HasMetadata()); - D_ASSERT(node.GetType() == LEAF); +void Leaf::DeprecatedVacuum(ART &art, NodePtr node_ptr) { + D_ASSERT(node_ptr.HasMetadata()); + D_ASSERT(node_ptr.GetType() == LEAF); auto &allocator = NodePtr::GetAllocator(art, LEAF); - while (node.HasMetadata()) { - NodeHandle handle(art, node); + while (node_ptr.HasMetadata()) { + NodeHandle handle(art, node_ptr); auto &leaf = handle.Get(); - if (leaf.next_leaf.HasMetadata() && allocator.NeedsVacuum(leaf.next_leaf)) { - leaf.next_leaf = allocator.VacuumPointer(leaf.next_leaf); - leaf.next_leaf.SetMetadata(static_cast(LEAF)); + if (leaf.next_leaf_ptr.HasMetadata() && allocator.NeedsVacuum(leaf.next_leaf_ptr)) { + leaf.next_leaf_ptr = allocator.VacuumPointer(leaf.next_leaf_ptr); + leaf.next_leaf_ptr.SetMetadata(static_cast(LEAF)); } - node = leaf.next_leaf; + node_ptr = leaf.next_leaf_ptr; } } -string Leaf::DeprecatedToString(ART &art, const NodePtr &node, const ToStringOptions &options) { +string Leaf::DeprecatedToString(ART &art, const NodePtr &node_ptr, const ToStringOptions &options) { string str = ""; if (!options.print_deprecated_leaves) { @@ -206,45 +206,45 @@ string Leaf::DeprecatedToString(ART &art, const NodePtr &node, const ToStringOpt return str; } - reference leaf_ref(node); + reference leaf_ptr_ref(node_ptr); - while (leaf_ref.get().HasMetadata()) { - auto &leaf = NodePtr::Ref(art, leaf_ref, LEAF); + while (leaf_ptr_ref.get().HasMetadata()) { + auto &leaf = NodePtr::Ref(art, leaf_ptr_ref, LEAF); str += options.tree_prefix + "Leaf [count: " + to_string(leaf.count) + ", row IDs: "; for (uint8_t i = 0; i < leaf.count; i++) { str += to_string(leaf.row_ids[i]) + "-"; } str += "]\n"; - leaf_ref = leaf.next_leaf; + leaf_ptr_ref = leaf.next_leaf_ptr; } return str; } -void Leaf::DeprecatedVerify(ART &art, const NodePtr &node) { - D_ASSERT(node.GetType() == LEAF); +void Leaf::DeprecatedVerify(ART &art, const NodePtr &node_ptr) { + D_ASSERT(node_ptr.GetType() == LEAF); - NodePtr current = node; - while (current.HasMetadata()) { - ConstNodeHandle handle(art, current); + NodePtr current_ptr = node_ptr; + while (current_ptr.HasMetadata()) { + ConstNodeHandle handle(art, current_ptr); auto &leaf = handle.Get(); D_ASSERT(leaf.count <= LEAF_SIZE); - current = leaf.next_leaf; + current_ptr = leaf.next_leaf_ptr; } } -void Leaf::DeprecatedVerifyAllocations(ART &art, const NodePtr &node, unordered_map &node_counts) { - D_ASSERT(node.GetType() == LEAF); +void Leaf::DeprecatedVerifyAllocations(ART &art, const NodePtr &node_ptr, unordered_map &node_counts) { + D_ASSERT(node_ptr.GetType() == LEAF); auto idx = NodePtr::GetAllocatorIdx(LEAF); - NodePtr current = node; - while (current.HasMetadata()) { + NodePtr current_ptr = node_ptr; + while (current_ptr.HasMetadata()) { node_counts[idx]++; - ConstNodeHandle handle(art, current); + ConstNodeHandle handle(art, current_ptr); auto &leaf = handle.Get(); - current = leaf.next_leaf; + current_ptr = leaf.next_leaf_ptr; } } diff --git a/src/duckdb/src/execution/index/art/node.cpp b/src/duckdb/src/execution/index/art/node.cpp index d84506850..7c7eedee0 100644 --- a/src/duckdb/src/execution/index/art/node.cpp +++ b/src/duckdb/src/execution/index/art/node.cpp @@ -23,58 +23,58 @@ namespace duckdb { // New and free //===--------------------------------------------------------------------===// -void NodePtr::New(ART &art, NodePtr &node, NType type) { +void NodePtr::New(ART &art, NodePtr &node_ptr, NType type) { switch (type) { case NType::NODE_7_LEAF: - Node7Leaf::New(art, node); + Node7Leaf::New(art, node_ptr); break; case NType::NODE_15_LEAF: - Node15Leaf::New(art, node); + Node15Leaf::New(art, node_ptr); break; case NType::NODE_256_LEAF: - Node256Leaf::New(art, node); + Node256Leaf::New(art, node_ptr); break; case NType::NODE_4: - Node4::New(art, node); + Node4::New(art, node_ptr); break; case NType::NODE_16: - Node16::New(art, node); + Node16::New(art, node_ptr); break; case NType::NODE_48: - Node48::New(art, node); + Node48::New(art, node_ptr); break; case NType::NODE_256: - Node256::New(art, node); + Node256::New(art, node_ptr); break; default: throw InternalException("Invalid node type for New: %d.", type); } } -void NodePtr::FreeNode(ART &art, NodePtr &node) { - D_ASSERT(node.HasMetadata()); - GetAllocator(art, node.GetType()).Free(node); - node.Clear(); +void NodePtr::FreeNode(ART &art, NodePtr &node_ptr) { + D_ASSERT(node_ptr.HasMetadata()); + GetAllocator(art, node_ptr.GetType()).Free(node_ptr); + node_ptr.Clear(); } -void NodePtr::FreeTree(ART &art, NodePtr &tree) { - if (!tree.HasMetadata()) { +void NodePtr::FreeTree(ART &art, NodePtr &subtree_root_ptr) { + if (!subtree_root_ptr.HasMetadata()) { return; } // All nodes should be pushed onto the stack. - auto child_handler = [](NodePtr &child) -> OptionalNodePtr { - D_ASSERT(child.HasMetadata()); - return child; + auto child_handler = [](NodePtr &child_ptr) -> OptionalNodePtr { + D_ASSERT(child_ptr.HasMetadata()); + return child_ptr; }; // We freed the subtree pointed to by the current node. Free the node. - auto post_handler = [&](NodePtr current) { - D_ASSERT(current.HasMetadata()); - auto type = current.GetType(); + auto post_handler = [&](NodePtr current_ptr) { + D_ASSERT(current_ptr.HasMetadata()); + auto type = current_ptr.GetType(); switch (type) { case NType::LEAF_INLINED: break; case NType::LEAF: - Leaf::DeprecatedFree(art, current); + Leaf::DeprecatedFree(art, current_ptr); break; case NType::NODE_7_LEAF: case NType::NODE_15_LEAF: @@ -84,14 +84,14 @@ void NodePtr::FreeTree(ART &art, NodePtr &tree) { case NType::NODE_16: case NType::NODE_48: case NType::NODE_256: - FreeNode(art, current); + FreeNode(art, current_ptr); break; default: throw InternalException("invalid node type for FreeTree: %d", type); } }; - ARTScanPostorder(art, tree, child_handler, post_handler); - tree.Clear(); + ARTScanPostorder(art, subtree_root_ptr, child_handler, post_handler); + subtree_root_ptr.Clear(); } //===--------------------------------------------------------------------===// @@ -131,43 +131,43 @@ uint8_t NodePtr::GetAllocatorIdx(const NType type) { // Inserts //===--------------------------------------------------------------------===// -void NodePtr::ReplaceChild(const ART &art, const uint8_t byte, const NodePtr child) const { +void NodePtr::ReplaceChild(const ART &art, const uint8_t byte, const NodePtr child_ptr) const { D_ASSERT(HasMetadata()); auto type = GetType(); switch (type) { case NType::NODE_4: - return Node4::ReplaceChild(Ref(art, *this, type), byte, child); + return Node4::ReplaceChild(Ref(art, *this, type), byte, child_ptr); case NType::NODE_16: - return Node16::ReplaceChild(Ref(art, *this, type), byte, child); + return Node16::ReplaceChild(Ref(art, *this, type), byte, child_ptr); case NType::NODE_48: - return Ref(art, *this, type).ReplaceChild(byte, child); + return Ref(art, *this, type).ReplaceChild(byte, child_ptr); case NType::NODE_256: - return Ref(art, *this, type).ReplaceChild(byte, child); + return Ref(art, *this, type).ReplaceChild(byte, child_ptr); default: throw InternalException("Invalid node type for ReplaceChild: %d.", type); } } -void NodePtr::InsertChild(ART &art, NodePtr &node, const uint8_t byte, const NodePtr child) { - D_ASSERT(node.HasMetadata()); +void NodePtr::InsertChild(ART &art, NodePtr &node_ptr, const uint8_t byte, const NodePtr child_ptr) { + D_ASSERT(node_ptr.HasMetadata()); - auto type = node.GetType(); + auto type = node_ptr.GetType(); switch (type) { case NType::NODE_4: - return Node4::InsertChild(art, node, byte, child); + return Node4::InsertChild(art, node_ptr, byte, child_ptr); case NType::NODE_16: - return Node16::InsertChild(art, node, byte, child); + return Node16::InsertChild(art, node_ptr, byte, child_ptr); case NType::NODE_48: - return Node48::InsertChild(art, node, byte, child); + return Node48::InsertChild(art, node_ptr, byte, child_ptr); case NType::NODE_256: - return Node256::InsertChild(art, node, byte, child); + return Node256::InsertChild(art, node_ptr, byte, child_ptr); case NType::NODE_7_LEAF: - return Node7Leaf::InsertByte(art, node, byte); + return Node7Leaf::InsertByte(art, node_ptr, byte); case NType::NODE_15_LEAF: - return Node15Leaf::InsertByte(art, node, byte); + return Node15Leaf::InsertByte(art, node_ptr, byte); case NType::NODE_256_LEAF: - return Node256Leaf::InsertByte(art, node, byte); + return Node256Leaf::InsertByte(art, node_ptr, byte); default: throw InternalException("Invalid node type for InsertChild: %d.", type); } @@ -177,26 +177,26 @@ void NodePtr::InsertChild(ART &art, NodePtr &node, const uint8_t byte, const Nod // Delete //===--------------------------------------------------------------------===// -void NodePtr::DeleteChild(ART &art, NodePtr &node, NodePtr &prefix, const uint8_t byte, const GateStatus status, +void NodePtr::DeleteChild(ART &art, NodePtr &node_ptr, NodePtr &parent_ptr, const uint8_t byte, const GateStatus status, const ARTKey &row_id) { - D_ASSERT(node.HasMetadata()); + D_ASSERT(node_ptr.HasMetadata()); - auto type = node.GetType(); + auto type = node_ptr.GetType(); switch (type) { case NType::NODE_4: - return Node4::DeleteChild(art, node, prefix, byte, status); + return Node4::DeleteChild(art, node_ptr, parent_ptr, byte, status); case NType::NODE_16: - return Node16::DeleteChild(art, node, byte); + return Node16::DeleteChild(art, node_ptr, byte); case NType::NODE_48: - return Node48::DeleteChild(art, node, byte); + return Node48::DeleteChild(art, node_ptr, byte); case NType::NODE_256: - return Node256::DeleteChild(art, node, byte); + return Node256::DeleteChild(art, node_ptr, byte); case NType::NODE_7_LEAF: - return Node7Leaf::DeleteByte(art, node, prefix, byte, row_id); + return Node7Leaf::DeleteByte(art, node_ptr, parent_ptr, byte, row_id); case NType::NODE_15_LEAF: - return Node15Leaf::DeleteByte(art, node, byte); + return Node15Leaf::DeleteByte(art, node_ptr, byte); case NType::NODE_256_LEAF: - return Node256Leaf::DeleteByte(art, node, byte); + return Node256Leaf::DeleteByte(art, node_ptr, byte); default: throw InternalException("Invalid node type for DeleteChild: %d.", type); } @@ -207,19 +207,19 @@ void NodePtr::DeleteChild(ART &art, NodePtr &node, NodePtr &prefix, const uint8_ //===--------------------------------------------------------------------===// template -static unsafe_optional_ptr GetChildInternal(ART &art, NODE &node, const uint8_t byte, const bool unsafe) { - D_ASSERT(node.HasMetadata()); +static unsafe_optional_ptr GetChildInternal(ART &art, NODE &node_ptr, const uint8_t byte, const bool unsafe) { + D_ASSERT(node_ptr.HasMetadata()); - auto type = node.GetType(); + auto type = node_ptr.GetType(); switch (type) { case NType::NODE_4: - return Node4::GetChild(NodePtr::Ref(art, node, type), byte, unsafe); + return Node4::GetChild(NodePtr::Ref(art, node_ptr, type), byte, unsafe); case NType::NODE_16: - return Node16::GetChild(NodePtr::Ref(art, node, type), byte, unsafe); + return Node16::GetChild(NodePtr::Ref(art, node_ptr, type), byte, unsafe); case NType::NODE_48: - return Node48::GetChild(NodePtr::Ref(art, node, type), byte, unsafe); + return Node48::GetChild(NodePtr::Ref(art, node_ptr, type), byte, unsafe); case NType::NODE_256: { - return Node256::GetChild(NodePtr::Ref(art, node, type), byte, unsafe); + return Node256::GetChild(NodePtr::Ref(art, node_ptr, type), byte, unsafe); } default: throw InternalException("Invalid node type for GetChildInternal: %d.", type); @@ -271,19 +271,19 @@ OptionalNodePtr NodePtr::GetNextChildNode(const ART &art, uint8_t &byte) const { } template -unsafe_optional_ptr GetNextChildInternal(ART &art, NODE &node, uint8_t &byte) { - D_ASSERT(node.HasMetadata()); +unsafe_optional_ptr GetNextChildInternal(ART &art, NODE &node_ptr, uint8_t &byte) { + D_ASSERT(node_ptr.HasMetadata()); - auto type = node.GetType(); + auto type = node_ptr.GetType(); switch (type) { case NType::NODE_4: - return Node4::GetNextChild(NodePtr::Ref(art, node, type), byte); + return Node4::GetNextChild(NodePtr::Ref(art, node_ptr, type), byte); case NType::NODE_16: - return Node16::GetNextChild(NodePtr::Ref(art, node, type), byte); + return Node16::GetNextChild(NodePtr::Ref(art, node_ptr, type), byte); case NType::NODE_48: - return Node48::GetNextChild(NodePtr::Ref(art, node, type), byte); + return Node48::GetNextChild(NodePtr::Ref(art, node_ptr, type), byte); case NType::NODE_256: - return Node256::GetNextChild(NodePtr::Ref(art, node, type), byte); + return Node256::GetNextChild(NodePtr::Ref(art, node_ptr, type), byte); default: throw InternalException("Invalid node type for GetNextChildInternal: %d.", type); } @@ -402,18 +402,18 @@ bool NodePtr::IsAnyLeaf() const { // TransformToDeprecated //===--------------------------------------------------------------------===// -void NodePtr::TransformToDeprecated(ART &art, NodePtr &node, TransformToDeprecatedState &state) { - auto child_handler = [&](NodePtr &child) -> OptionalNodePtr { - D_ASSERT(child.HasMetadata()); - if (child.GetGateStatus() == GateStatus::GATE_SET) { - Leaf::TransformToDeprecated(art, child); +void NodePtr::TransformToDeprecated(ART &art, NodePtr &node_ptr, TransformToDeprecatedState &state) { + auto child_handler = [&](NodePtr &child_ptr) -> OptionalNodePtr { + D_ASSERT(child_ptr.HasMetadata()); + if (child_ptr.GetGateStatus() == GateStatus::GATE_SET) { + Leaf::TransformToDeprecated(art, child_ptr); return OptionalNodePtr(); } - auto type = child.GetType(); + auto type = child_ptr.GetType(); switch (type) { case NType::PREFIX: // An empty node stops the traversal. - return PrefixHandle::TransformToDeprecated(art, child, state); + return PrefixHandle::TransformToDeprecated(art, child_ptr, state); case NType::LEAF_INLINED: case NType::LEAF: return OptionalNodePtr(); @@ -424,24 +424,24 @@ void NodePtr::TransformToDeprecated(ART &art, NodePtr &node, TransformToDeprecat case NType::NODE_7_LEAF: case NType::NODE_15_LEAF: case NType::NODE_256_LEAF: - return child; + return child_ptr; default: throw InternalException("invalid node type for TransformToDeprecated: %d", type); } }; - auto on_pop = [&](NodePtr current) -> ARTScanNodeResult { - auto type = current.GetType(); + auto on_pop = [&](NodePtr current_ptr) -> ARTScanNodeResult { + auto type = current_ptr.GetType(); if (type == NType::NODE_4 || type == NType::NODE_16 || type == NType::NODE_48 || type == NType::NODE_256) { auto &alloc = NodePtr::GetAllocator(art, type); - if (!alloc.LoadedFromStorage(current)) { + if (!alloc.LoadedFromStorage(current_ptr)) { return ARTScanNodeResult::SKIP; } } return ARTScanNodeResult::SCAN_CHILDREN; }; - ARTScanPreorder(art, node, child_handler, on_pop); + ARTScanPreorder(art, node_ptr, child_handler, on_pop); } //===--------------------------------------------------------------------===// @@ -468,14 +468,14 @@ void NodePtr::Verify(ART &art) const { if (!IsNestedLeaf()) { uint8_t byte = 0; - auto child = GetNextChild(art, byte); - while (child) { - child->Verify(art); + auto child_ptr = GetNextChild(art, byte); + while (child_ptr) { + child_ptr->Verify(art); if (byte == NumericLimits::Maximum()) { break; } byte++; - child = GetNextChild(art, byte); + child_ptr = GetNextChild(art, byte); } } } @@ -483,14 +483,14 @@ void NodePtr::Verify(ART &art) const { void NodePtr::VerifyAllocations(ART &art, unordered_map &node_counts) const { D_ASSERT(HasMetadata()); - auto child_handler = [&](const NodePtr &child) -> OptionalNodePtr { - D_ASSERT(child.HasMetadata()); - auto type = child.GetType(); + auto child_handler = [&](const NodePtr &child_ptr) -> OptionalNodePtr { + D_ASSERT(child_ptr.HasMetadata()); + auto type = child_ptr.GetType(); switch (type) { case NType::LEAF_INLINED: return OptionalNodePtr(); case NType::LEAF: { - Leaf::DeprecatedVerifyAllocations(art, child, node_counts); + Leaf::DeprecatedVerifyAllocations(art, child_ptr, node_counts); return OptionalNodePtr(); } case NType::NODE_7_LEAF: @@ -504,7 +504,7 @@ void NodePtr::VerifyAllocations(ART &art, unordered_map &node_co case NType::NODE_48: case NType::NODE_256: node_counts[GetAllocatorIdx(type)]++; - return child; + return child_ptr; default: throw InternalException("invalid node type for VerifyAllocations: %d", type); } @@ -565,14 +565,14 @@ string NodePtr::ToStringChildren(ART &art, const ToStringOptions &options) const // Collect all children first to know which is last vector> children; uint8_t byte = 0; - auto child = GetNextChild(art, byte); - while (child) { - children.emplace_back(byte, child.get()); + auto child_ptr = GetNextChild(art, byte); + while (child_ptr) { + children.emplace_back(byte, child_ptr.get()); if (byte == NumericLimits::Maximum()) { break; } byte++; - child = GetNextChild(art, byte); + child_ptr = GetNextChild(art, byte); } uint8_t expected_byte = 0; diff --git a/src/duckdb/src/execution/index/art/node256.cpp b/src/duckdb/src/execution/index/art/node256.cpp index 9f7dd6449..aaeb32446 100644 --- a/src/duckdb/src/execution/index/art/node256.cpp +++ b/src/duckdb/src/execution/index/art/node256.cpp @@ -4,16 +4,16 @@ namespace duckdb { -void Node256::InsertChild(ART &art, NodePtr &node, const uint8_t byte, const NodePtr child) { - NodeHandle handle(art, node); +void Node256::InsertChild(ART &art, NodePtr &node_ptr, const uint8_t byte, const NodePtr child_ptr) { + NodeHandle handle(art, node_ptr); auto &n = handle.Get(); n.count++; - n.children[byte] = child; + n.children[byte] = child_ptr; } -void Node256::DeleteChild(ART &art, NodePtr &node, const uint8_t byte) { +void Node256::DeleteChild(ART &art, NodePtr &node_ptr, const uint8_t byte) { { - NodeHandle handle(art, node); + NodeHandle handle(art, node_ptr); auto &n = handle.Get(); // Free the child and decrease the count. @@ -26,18 +26,18 @@ void Node256::DeleteChild(ART &art, NodePtr &node, const uint8_t byte) { } // Shrink to Node48. - auto node256 = node; - Node48::ShrinkNode256(art, node, node256); + auto node256_ptr = node_ptr; + Node48::ShrinkNode256(art, node_ptr, node256_ptr); } -void Node256::GrowNode48(ART &art, NodePtr &node256, NodePtr &node48) { +void Node256::GrowNode48(ART &art, NodePtr &node256_ptr, NodePtr &node48_ptr) { { - NodeHandle n48_handle(art, node48); + NodeHandle n48_handle(art, node48_ptr); auto &n48 = n48_handle.Get(); - auto n256_handle = New(art, node256); + auto n256_handle = New(art, node256_ptr); auto &n256 = n256_handle.Get(); - node256.SetGateStatus(node48.GetGateStatus()); + node256_ptr.SetGateStatus(node48_ptr.GetGateStatus()); n256.count = n48.count; for (uint16_t i = 0; i < CAPACITY; i++) { @@ -46,7 +46,7 @@ void Node256::GrowNode48(ART &art, NodePtr &node256, NodePtr &node48) { } } } - NodePtr::FreeNode(art, node48); + NodePtr::FreeNode(art, node48_ptr); } } // namespace duckdb diff --git a/src/duckdb/src/execution/index/art/node256_leaf.cpp b/src/duckdb/src/execution/index/art/node256_leaf.cpp index 44c20c72f..143499905 100644 --- a/src/duckdb/src/execution/index/art/node256_leaf.cpp +++ b/src/duckdb/src/execution/index/art/node256_leaf.cpp @@ -5,11 +5,11 @@ namespace duckdb { -NodeHandle Node256Leaf::New(ART &art, NodePtr &node) { - node = NodePtr::GetAllocator(art, NODE_256_LEAF).New(); - node.SetMetadata(static_cast(NODE_256_LEAF)); +NodeHandle Node256Leaf::New(ART &art, NodePtr &node_ptr) { + node_ptr = NodePtr::GetAllocator(art, NODE_256_LEAF).New(); + node_ptr.SetMetadata(static_cast(NODE_256_LEAF)); - NodeHandle handle(art, node); + NodeHandle handle(art, node_ptr); auto &n = handle.Get(); n.count = 0; @@ -19,8 +19,8 @@ NodeHandle Node256Leaf::New(ART &art, NodePtr &node) { return handle; } -void Node256Leaf::InsertByte(ART &art, NodePtr &node, const uint8_t byte) { - NodeHandle handle(art, node); +void Node256Leaf::InsertByte(ART &art, NodePtr &node_ptr, const uint8_t byte) { + NodeHandle handle(art, node_ptr); auto &n = handle.Get(); n.count++; @@ -28,9 +28,9 @@ void Node256Leaf::InsertByte(ART &art, NodePtr &node, const uint8_t byte) { mask.SetValid(byte); } -void Node256Leaf::DeleteByte(ART &art, NodePtr &node, const uint8_t byte) { +void Node256Leaf::DeleteByte(ART &art, NodePtr &node_ptr, const uint8_t byte) { { - NodeHandle handle(art, node); + NodeHandle handle(art, node_ptr); auto &n = handle.Get(); n.count--; @@ -42,8 +42,8 @@ void Node256Leaf::DeleteByte(ART &art, NodePtr &node, const uint8_t byte) { } } // Shrink node to Node15. - auto node256 = node; - Node15Leaf::ShrinkNode256Leaf(art, node, node256); + auto node256_leaf_ptr = node_ptr; + Node15Leaf::ShrinkNode256Leaf(art, node_ptr, node256_leaf_ptr); } bool Node256Leaf::HasByte(const uint8_t byte) const { @@ -82,14 +82,14 @@ bool Node256Leaf::GetNextByte(uint8_t &byte) const { return false; } -void Node256Leaf::GrowNode15Leaf(ART &art, NodePtr &node256_leaf, NodePtr &node15_leaf) { +void Node256Leaf::GrowNode15Leaf(ART &art, NodePtr &node256_leaf_ptr, NodePtr &node15_leaf_ptr) { { - NodeHandle n15_handle(art, node15_leaf); + NodeHandle n15_handle(art, node15_leaf_ptr); auto &n15 = n15_handle.Get(); - auto n256_handle = New(art, node256_leaf); + auto n256_handle = New(art, node256_leaf_ptr); auto &n256 = n256_handle.Get(); - node256_leaf.SetGateStatus(node15_leaf.GetGateStatus()); + node256_leaf_ptr.SetGateStatus(node15_leaf_ptr.GetGateStatus()); n256.count = n15.count; ValidityMask mask(&n256.mask[0], Node256::CAPACITY); @@ -97,7 +97,7 @@ void Node256Leaf::GrowNode15Leaf(ART &art, NodePtr &node256_leaf, NodePtr &node1 mask.SetValid(n15.key[i]); } } - NodePtr::FreeNode(art, node15_leaf); + NodePtr::FreeNode(art, node15_leaf_ptr); } } // namespace duckdb diff --git a/src/duckdb/src/execution/index/art/node48.cpp b/src/duckdb/src/execution/index/art/node48.cpp index 971c7251d..cb3b9d709 100644 --- a/src/duckdb/src/execution/index/art/node48.cpp +++ b/src/duckdb/src/execution/index/art/node48.cpp @@ -5,9 +5,9 @@ namespace duckdb { -void Node48::InsertChild(ART &art, NodePtr &node, const uint8_t byte, const NodePtr child) { +void Node48::InsertChild(ART &art, NodePtr &node_ptr, const uint8_t byte, const NodePtr child_ptr) { { - NodeHandle handle(art, node); + NodeHandle handle(art, node_ptr); auto &n = handle.Get(); if (n.count != CAPACITY) { @@ -21,7 +21,7 @@ void Node48::InsertChild(ART &art, NodePtr &node, const uint8_t byte, const Node } } - n.children[child_pos] = child; + n.children[child_pos] = child_ptr; n.child_index[byte] = child_pos; n.count++; return; @@ -30,14 +30,14 @@ void Node48::InsertChild(ART &art, NodePtr &node, const uint8_t byte, const Node // The node is full. // Grow to Node256. - auto node48 = node; - Node256::GrowNode48(art, node, node48); - Node256::InsertChild(art, node, byte, child); + auto node48_ptr = node_ptr; + Node256::GrowNode48(art, node_ptr, node48_ptr); + Node256::InsertChild(art, node_ptr, byte, child_ptr); } -void Node48::DeleteChild(ART &art, NodePtr &node, const uint8_t byte) { +void Node48::DeleteChild(ART &art, NodePtr &node_ptr, const uint8_t byte) { { - NodeHandle handle(art, node); + NodeHandle handle(art, node_ptr); auto &n = handle.Get(); // Free the child and decrease the count. @@ -51,18 +51,18 @@ void Node48::DeleteChild(ART &art, NodePtr &node, const uint8_t byte) { } // Shrink to Node16. - auto node48 = node; - Node16::ShrinkNode48(art, node, node48); + auto node48_ptr = node_ptr; + Node16::ShrinkNode48(art, node_ptr, node48_ptr); } -void Node48::GrowNode16(ART &art, NodePtr &node48, NodePtr &node16) { +void Node48::GrowNode16(ART &art, NodePtr &node48_ptr, NodePtr &node16_ptr) { { - NodeHandle n16_handle(art, node16); + NodeHandle n16_handle(art, node16_ptr); auto &n16 = n16_handle.Get(); - auto n48_handle = New(art, node48); + auto n48_handle = New(art, node48_ptr); auto &n48 = n48_handle.Get(); - node48.SetGateStatus(node16.GetGateStatus()); + node48_ptr.SetGateStatus(node16_ptr.GetGateStatus()); n48.count = n16.count; for (uint8_t i = 0; i < n16.count; i++) { @@ -70,16 +70,16 @@ void Node48::GrowNode16(ART &art, NodePtr &node48, NodePtr &node16) { n48.children[i] = n16.children[i]; } } - NodePtr::FreeNode(art, node16); + NodePtr::FreeNode(art, node16_ptr); } -void Node48::ShrinkNode256(ART &art, NodePtr &node48, NodePtr &node256) { +void Node48::ShrinkNode256(ART &art, NodePtr &node48_ptr, NodePtr &node256_ptr) { { - auto n48_handle = New(art, node48); + auto n48_handle = New(art, node48_ptr); auto &n48 = n48_handle.Get(); - node48.SetGateStatus(node256.GetGateStatus()); + node48_ptr.SetGateStatus(node256_ptr.GetGateStatus()); - NodeHandle n256_handle(art, node256); + NodeHandle n256_handle(art, node256_ptr); auto &n256 = n256_handle.Get(); n48.count = 0; @@ -92,7 +92,7 @@ void Node48::ShrinkNode256(ART &art, NodePtr &node48, NodePtr &node256) { n48.count++; } } - NodePtr::FreeNode(art, node256); + NodePtr::FreeNode(art, node256_ptr); } } // namespace duckdb diff --git a/src/duckdb/src/execution/index/art/node_handle.cpp b/src/duckdb/src/execution/index/art/node_handle.cpp index 1b23b05b1..bf806d286 100644 --- a/src/duckdb/src/execution/index/art/node_handle.cpp +++ b/src/duckdb/src/execution/index/art/node_handle.cpp @@ -4,14 +4,14 @@ namespace duckdb { -NodeHandle::NodeHandle(ART &art, const NodePtr node) - : handle(NodePtr::GetAllocator(art, node.GetType()).GetHandle(node)), type(node.GetType()) { +NodeHandle::NodeHandle(ART &art, const NodePtr node_ptr) + : handle(NodePtr::GetAllocator(art, node_ptr.GetType()).GetHandle(node_ptr)), type(node_ptr.GetType()) { handle.MarkModified(); } -NodeHandle::NodeHandle(FixedSizeAllocator &allocator, const NodePtr node, NType type) - : handle(allocator.GetHandle(node)), type(type) { - D_ASSERT(node.GetType() == type); +NodeHandle::NodeHandle(FixedSizeAllocator &allocator, const NodePtr node_ptr, NType type) + : handle(allocator.GetHandle(node_ptr)), type(type) { + D_ASSERT(node_ptr.GetType() == type); handle.MarkModified(); } @@ -26,8 +26,8 @@ NodeHandle &NodeHandle::operator=(NodeHandle &&other) noexcept { return *this; } -ConstNodeHandle::ConstNodeHandle(const ART &art, const NodePtr node) - : handle(NodePtr::GetAllocator(art, node.GetType()).GetHandle(node)), type(node.GetType()) { +ConstNodeHandle::ConstNodeHandle(const ART &art, const NodePtr node_ptr) + : handle(NodePtr::GetAllocator(art, node_ptr.GetType()).GetHandle(node_ptr)), type(node_ptr.GetType()) { } } // namespace duckdb diff --git a/src/duckdb/src/execution/index/art/prefix.cpp b/src/duckdb/src/execution/index/art/prefix.cpp index 32bc3441d..2dd1a35a5 100644 --- a/src/duckdb/src/execution/index/art/prefix.cpp +++ b/src/duckdb/src/execution/index/art/prefix.cpp @@ -12,11 +12,11 @@ namespace duckdb { -Prefix::Prefix(const ART &art, const NodePtr node, const bool is_mutable, const bool set_in_memory) { +Prefix::Prefix(const ART &art, const NodePtr node_ptr, const bool is_mutable, const bool set_in_memory) { if (!set_in_memory) { - data = NodePtr::GetAllocator(art, PREFIX).Get(node, is_mutable); + data = NodePtr::GetAllocator(art, PREFIX).Get(node_ptr, is_mutable); } else { - data = NodePtr::GetAllocator(art, PREFIX).GetIfLoaded(node); + data = NodePtr::GetAllocator(art, PREFIX).GetIfLoaded(node_ptr); if (!data) { child_slot = nullptr; in_memory = false; @@ -27,23 +27,24 @@ Prefix::Prefix(const ART &art, const NodePtr node, const bool is_mutable, const in_memory = true; } -Prefix::Prefix(FixedSizeAllocator &allocator, const NodePtr node, const idx_t count) { - data = allocator.Get(node, true); +Prefix::Prefix(FixedSizeAllocator &allocator, const NodePtr node_ptr, const idx_t count) { + data = allocator.Get(node_ptr, true); child_slot = &PrefixHandle::ChildRefWithCount(data, count); in_memory = true; } -uint8_t Prefix::GetByte(const ART &art, const NodePtr &node, const uint8_t pos) { - D_ASSERT(node.GetType() == PREFIX); - ConstPrefixHandle prefix(art, node); +uint8_t Prefix::GetByte(const ART &art, const NodePtr &node_ptr, const uint8_t pos) { + D_ASSERT(node_ptr.GetType() == PREFIX); + ConstPrefixHandle prefix(art, node_ptr); return prefix.GetByte(pos); } -Prefix Prefix::NewInternal(ART &art, NodePtr &node, const data_ptr_t data, const uint8_t count, const idx_t offset) { - node = NodePtr::GetAllocator(art, PREFIX).New(); - node.SetMetadata(static_cast(PREFIX)); +Prefix Prefix::NewInternal(ART &art, NodePtr &node_ptr, const data_ptr_t data, const uint8_t count, + const idx_t offset) { + node_ptr = NodePtr::GetAllocator(art, PREFIX).New(); + node_ptr.SetMetadata(static_cast(PREFIX)); - Prefix prefix(art, node, true); + Prefix prefix(art, node_ptr, true); prefix.data[art.PrefixCount()] = count; if (data) { D_ASSERT(count); @@ -53,21 +54,21 @@ Prefix Prefix::NewInternal(ART &art, NodePtr &node, const data_ptr_t data, const return prefix; } -void Prefix::New(ART &art, reference &node_ref, const ARTKey &key, const idx_t depth, idx_t count) { +void Prefix::New(ART &art, reference &node_ptr_ref, const ARTKey &key, const idx_t depth, idx_t count) { idx_t offset = 0; while (count) { auto min = MinValue(UnsafeNumericCast(art.PrefixCount()), count); auto this_count = UnsafeNumericCast(min); - auto prefix = NewInternal(art, node_ref, key.data, this_count, offset + depth); + auto prefix = NewInternal(art, node_ptr_ref, key.data, this_count, offset + depth); - node_ref = *prefix.child_slot; + node_ptr_ref = *prefix.child_slot; offset += this_count; count -= this_count; } } -void Prefix::Concat(ART &art, NodePtr &parent, NodePtr &node4, const NodePtr child, uint8_t byte, +void Prefix::Concat(ART &art, NodePtr &parent_ptr, NodePtr &node4_ptr, const NodePtr child_ptr, uint8_t byte, const GateStatus node4_status, const GateStatus status) { // We have four situations from which we enter here: // 1: PREFIX (parent) - Node4 (prev_node4) - PREFIX (child) - INLINED_LEAF, or @@ -75,39 +76,39 @@ void Prefix::Concat(ART &art, NodePtr &parent, NodePtr &node4, const NodePtr chi // 3: INTERNAL_NODE (parent) - Node4 (prev_node4) - PREFIX (child) - INLINED_LEAF, or // 4: INTERNAL_NODE (parent) - Node4 (prev_node4) - INLINED_LEAF (child). - D_ASSERT(!parent.IsAnyLeaf()); - D_ASSERT(child.HasMetadata()); + D_ASSERT(!parent_ptr.IsAnyLeaf()); + D_ASSERT(child_ptr.HasMetadata()); // The Node4 was a gate. if (node4_status == GateStatus::GATE_SET) { - D_ASSERT(parent.GetGateStatus() == GateStatus::GATE_NOT_SET); - D_ASSERT(child.GetGateStatus() == GateStatus::GATE_NOT_SET); - ConcatNode4WasGate(art, node4, child, byte); + D_ASSERT(parent_ptr.GetGateStatus() == GateStatus::GATE_NOT_SET); + D_ASSERT(child_ptr.GetGateStatus() == GateStatus::GATE_NOT_SET); + ConcatNode4WasGate(art, node4_ptr, child_ptr, byte); return; } // The child is a gate. - if (child.GetGateStatus() == GateStatus::GATE_SET) { + if (child_ptr.GetGateStatus() == GateStatus::GATE_SET) { D_ASSERT(node4_status == GateStatus::GATE_NOT_SET); - ConcatChildIsGate(art, parent, node4, child, byte); + ConcatChildIsGate(art, parent_ptr, node4_ptr, child_ptr, byte); return; } - ConcatInternal(art, parent, node4, child, byte, status); + ConcatInternal(art, parent_ptr, node4_ptr, child_ptr, byte, status); } -void Prefix::Reduce(ART &art, NodePtr &node, const idx_t pos) { - D_ASSERT(node.HasMetadata()); +void Prefix::Reduce(ART &art, NodePtr &node_ptr, const idx_t pos) { + D_ASSERT(node_ptr.HasMetadata()); D_ASSERT(pos < art.PrefixCount()); // We always reduce by at least one byte, // thus, if the prefix was a gate, it no longer is. - node.SetGateStatus(GateStatus::GATE_NOT_SET); + node_ptr.SetGateStatus(GateStatus::GATE_NOT_SET); - Prefix prefix(art, node); + Prefix prefix(art, node_ptr); if (pos == idx_t(prefix.data[art.PrefixCount()] - 1)) { - auto next = *prefix.child_slot; - NodePtr::FreeNode(art, node); - node = next; + auto next_ptr = *prefix.child_slot; + NodePtr::FreeNode(art, node_ptr); + node_ptr = next_ptr; return; } @@ -131,138 +132,139 @@ Prefix Prefix::Append(ART &art, const uint8_t byte) { return prefix.Append(art, byte); } -void Prefix::Append(ART &art, NodePtr other) { - D_ASSERT(other.HasMetadata()); +void Prefix::Append(ART &art, NodePtr other_ptr) { + D_ASSERT(other_ptr.HasMetadata()); Prefix prefix = *this; - while (other.GetType() == PREFIX) { - if (other.GetGateStatus() == GateStatus::GATE_SET) { - *prefix.child_slot = other; + while (other_ptr.GetType() == PREFIX) { + if (other_ptr.GetGateStatus() == GateStatus::GATE_SET) { + *prefix.child_slot = other_ptr; return; } - Prefix other_prefix(art, other, true); + Prefix other_prefix(art, other_ptr, true); for (idx_t i = 0; i < other_prefix.data[art.PrefixCount()]; i++) { prefix = prefix.Append(art, other_prefix.data[i]); } *prefix.child_slot = *other_prefix.child_slot; - NodePtr::FreeNode(art, other); - other = *prefix.child_slot; + NodePtr::FreeNode(art, other_ptr); + other_ptr = *prefix.child_slot; } } -Prefix Prefix::GetTail(ART &art, const NodePtr &node) { - Prefix prefix(art, node, true); +Prefix Prefix::GetTail(ART &art, const NodePtr &node_ptr) { + Prefix prefix(art, node_ptr, true); while (prefix.child_slot->GetType() == PREFIX) { prefix = Prefix(art, *prefix.child_slot, true); } return prefix; } -void Prefix::ConcatInternal(ART &art, NodePtr &parent, NodePtr &node4, const NodePtr child, uint8_t byte, +void Prefix::ConcatInternal(ART &art, NodePtr &parent_ptr, NodePtr &node4_ptr, const NodePtr child_ptr, uint8_t byte, const GateStatus status) { - if (child.GetType() == NType::LEAF_INLINED) { + if (child_ptr.GetType() == NType::LEAF_INLINED) { if (status == GateStatus::GATE_SET) { - if (parent.GetType() == NType::PREFIX) { + if (parent_ptr.GetType() == NType::PREFIX) { // The parent only contained the Node4, so we can now inline 'all the way up', // and the gate is no longer nested. - while (parent.GetType() == NType::PREFIX) { - Prefix prefix(art, parent, true); - auto temp = *prefix.child_slot; - NodePtr::FreeNode(art, parent); - parent = temp; + while (parent_ptr.GetType() == NType::PREFIX) { + Prefix prefix(art, parent_ptr, true); + auto temp_ptr = *prefix.child_slot; + NodePtr::FreeNode(art, parent_ptr); + parent_ptr = temp_ptr; } - parent = child; + parent_ptr = child_ptr; return; } // The parent is any node inside the gate. // Inside gates, inlined row IDs are not prefixed, // so we directly inline into the previous Node4. - node4 = child; + node4_ptr = child_ptr; return; } // Not inside a gate. - if (parent.GetType() == NType::PREFIX) { + if (parent_ptr.GetType() == NType::PREFIX) { // Append the byte to the prefix, and then inline the child. - auto tail = GetTail(art, parent); + auto tail = GetTail(art, parent_ptr); tail = tail.Append(art, byte); - *tail.child_slot = child; + *tail.child_slot = child_ptr; return; } - auto prefix = NewInternal(art, node4, &byte, 1, 0); - *prefix.child_slot = child; + auto prefix = NewInternal(art, node4_ptr, &byte, 1, 0); + *prefix.child_slot = child_ptr; return; } // The child is not inlined. - if (parent.GetType() == NType::PREFIX) { + if (parent_ptr.GetType() == NType::PREFIX) { // Append the byte to the prefix. - auto tail = GetTail(art, parent); + auto tail = GetTail(art, parent_ptr); tail = tail.Append(art, byte); // Append the child to the prefix. - if (child.GetType() == NType::PREFIX) { - tail.Append(art, child); + if (child_ptr.GetType() == NType::PREFIX) { + tail.Append(art, child_ptr); return; } - *tail.child_slot = child; + *tail.child_slot = child_ptr; return; } // The child is not inlined, and the parent is not a prefix. - auto prefix = NewInternal(art, node4, &byte, 1, 0); - if (child.GetType() == NType::PREFIX) { - prefix.Append(art, child); + auto prefix = NewInternal(art, node4_ptr, &byte, 1, 0); + if (child_ptr.GetType() == NType::PREFIX) { + prefix.Append(art, child_ptr); return; } - *prefix.child_slot = child; + *prefix.child_slot = child_ptr; } -void Prefix::ConcatNode4WasGate(ART &art, NodePtr &node4, const NodePtr child, uint8_t byte) { - D_ASSERT(child.HasMetadata()); +void Prefix::ConcatNode4WasGate(ART &art, NodePtr &node4_ptr, const NodePtr child_ptr, uint8_t byte) { + D_ASSERT(child_ptr.HasMetadata()); - if (child.GetType() == NType::LEAF_INLINED) { + if (child_ptr.GetType() == NType::LEAF_INLINED) { // Inside gates, inlined row IDs are not prefixed. // The child is inlined, so we inline into the previous Node4. // There is no longer a nested leaf. - node4 = child; + node4_ptr = child_ptr; return; } - if (child.GetType() == PREFIX) { + if (child_ptr.GetType() == PREFIX) { // At least one more row ID in this gate and the child is a prefix. // We create a new prefix of length one containing the remaining byte. // Then, we append the child prefix. - auto prefix = NewInternal(art, node4, &byte, 1, 0); + auto prefix = NewInternal(art, node4_ptr, &byte, 1, 0); prefix.child_slot->Clear(); - prefix.Append(art, child); - node4.SetGateStatus(GateStatus::GATE_SET); + prefix.Append(art, child_ptr); + node4_ptr.SetGateStatus(GateStatus::GATE_SET); return; } // At least one more row ID in this gate and the child is not a prefix. // We create a new prefix of length one containing the remaining byte. // then, we append the child. - auto prefix = NewInternal(art, node4, &byte, 1, 0); - *prefix.child_slot = child; - node4.SetGateStatus(GateStatus::GATE_SET); + auto prefix = NewInternal(art, node4_ptr, &byte, 1, 0); + *prefix.child_slot = child_ptr; + node4_ptr.SetGateStatus(GateStatus::GATE_SET); } -void Prefix::ConcatChildIsGate(ART &art, NodePtr &parent, NodePtr &node4, const NodePtr child, uint8_t byte) { - if (parent.GetType() != PREFIX) { +void Prefix::ConcatChildIsGate(ART &art, NodePtr &parent_ptr, NodePtr &node4_ptr, const NodePtr child_ptr, + uint8_t byte) { + if (parent_ptr.GetType() != PREFIX) { // Create a new prefix at the former position of the Node4, // and point it to the gate. - auto prefix = NewInternal(art, node4, &byte, 1, 0); - *prefix.child_slot = child; + auto prefix = NewInternal(art, node4_ptr, &byte, 1, 0); + *prefix.child_slot = child_ptr; return; } // The parent is a prefix (chain), so we need to append the byte to its tail. - auto tail = GetTail(art, parent); + auto tail = GetTail(art, parent_ptr); tail = tail.Append(art, byte); - *tail.child_slot = child; + *tail.child_slot = child_ptr; } Prefix Prefix::TransformToDeprecatedAppend(ART &art, FixedSizeAllocator &allocator, uint8_t byte) { diff --git a/src/duckdb/src/execution/index/art/prefix_handle.cpp b/src/duckdb/src/execution/index/art/prefix_handle.cpp index 579e4566b..58ccbb8dc 100644 --- a/src/duckdb/src/execution/index/art/prefix_handle.cpp +++ b/src/duckdb/src/execution/index/art/prefix_handle.cpp @@ -7,12 +7,12 @@ namespace duckdb { -PrefixHandle PrefixHandle::NewInternal(ART &art, NodePtr &node, const_data_ptr_t data, const uint8_t count, +PrefixHandle PrefixHandle::NewInternal(ART &art, NodePtr &node_ptr, const_data_ptr_t data, const uint8_t count, const idx_t offset) { - node = NodePtr::GetAllocator(art, PREFIX).New(); - node.SetMetadata(static_cast(PREFIX)); + node_ptr = NodePtr::GetAllocator(art, PREFIX).New(); + node_ptr.SetMetadata(static_cast(PREFIX)); - PrefixHandle prefix(NodeHandle(art, node)); + PrefixHandle prefix(NodeHandle(art, node_ptr)); prefix.SetCount(art, count); if (data) { D_ASSERT(count); @@ -52,38 +52,38 @@ PrefixHandle PrefixHandle::AppendByte(ART &art, PrefixHandle prefix, const uint8 return NewInternal(art, prefix.Child(art), &byte, 1, 0); } -void PrefixHandle::Append(ART &art, PrefixHandle prefix, NodePtr other) { - D_ASSERT(other.HasMetadata()); +void PrefixHandle::Append(ART &art, PrefixHandle prefix, NodePtr other_ptr) { + D_ASSERT(other_ptr.HasMetadata()); - while (other.GetType() == PREFIX) { - if (other.GetGateStatus() == GateStatus::GATE_SET) { - prefix.Child(art) = other; + while (other_ptr.GetType() == PREFIX) { + if (other_ptr.GetGateStatus() == GateStatus::GATE_SET) { + prefix.Child(art) = other_ptr; return; } - NodePtr next; + NodePtr next_ptr; { - PrefixHandle other_prefix(NodeHandle(art, other)); + PrefixHandle other_prefix(NodeHandle(art, other_ptr)); const auto count = other_prefix.GetCount(art); for (idx_t i = 0; i < count; i++) { prefix = AppendByte(art, std::move(prefix), other_prefix.GetByte(i)); } - next = other_prefix.Child(art); - prefix.Child(art) = next; + next_ptr = other_prefix.Child(art); + prefix.Child(art) = next_ptr; } - NodePtr::FreeNode(art, other); - other = next; + NodePtr::FreeNode(art, other_ptr); + other_ptr = next_ptr; } - prefix.Child(art) = other; + prefix.Child(art) = other_ptr; } -NodePtr PrefixHandle::Split(ART &art, NodePtr &prefix_ptr, NodePtr &branching_node4, const uint8_t pos) { +NodePtr PrefixHandle::Split(ART &art, NodePtr &prefix_ptr, NodePtr &branching_node4_ptr, const uint8_t pos) { D_ASSERT(prefix_ptr.HasMetadata()); D_ASSERT(prefix_ptr.GetType() == PREFIX); - D_ASSERT(branching_node4.HasMetadata()); + D_ASSERT(branching_node4_ptr.HasMetadata()); - NodePtr child; + NodePtr child_ptr; { PrefixHandle prefix(NodeHandle(art, prefix_ptr)); const auto count = prefix.GetCount(art); @@ -100,7 +100,7 @@ NodePtr PrefixHandle::Split(ART &art, NodePtr &prefix_ptr, NodePtr &branching_no // 1. copy the remaining bytes of this prefix. // 2. append remaining prefix nodes. const auto suffix_count = UnsafeNumericCast(count - pos - 1); - auto suffix = NewInternal(art, child, prefix.Data(), suffix_count, pos + 1); + auto suffix = NewInternal(art, child_ptr, prefix.Data(), suffix_count, pos + 1); Append(art, std::move(suffix), prefix.Child(art)); } else { // The split is at the last prefix byte, whether the prefix is full or not. @@ -109,7 +109,7 @@ NodePtr PrefixHandle::Split(ART &art, NodePtr &prefix_ptr, NodePtr &branching_no // [this prefix minus split byte (omitted if pos == 0)] -> // [new node at split byte] --(split byte)--> // [child at split byte: prefix.Child(art)]. - child = prefix.Child(art); + child_ptr = prefix.Child(art); } if (pos != 0) { @@ -117,91 +117,91 @@ NodePtr PrefixHandle::Split(ART &art, NodePtr &prefix_ptr, NodePtr &branching_no // The subsequent node replaces the split byte. // Any gate stays on this prefix. prefix.SetCount(art, pos); - prefix.Child(art) = branching_node4; - return child; + prefix.Child(art) = branching_node4_ptr; + return child_ptr; } - // No bytes left before the split, so branching_node4 inherits the prefix's gate before we free it. - branching_node4.SetGateStatus(prefix_ptr.GetGateStatus()); + // No bytes left before the split, so branching_node4_ptr inherits the prefix's gate before we free it. + branching_node4_ptr.SetGateStatus(prefix_ptr.GetGateStatus()); } // Release the prefix handle before freeing its node, which may destroy the allocator buffer. NodePtr::FreeNode(art, prefix_ptr); - prefix_ptr = branching_node4; - return child; + prefix_ptr = branching_node4_ptr; + return child_ptr; } -NodeHandle PrefixHandle::NewDeprecated(FixedSizeAllocator &allocator, NodePtr &node) { - node = allocator.New(); - node.SetMetadata(static_cast(PREFIX)); +NodeHandle PrefixHandle::NewDeprecated(FixedSizeAllocator &allocator, NodePtr &node_ptr) { + node_ptr = allocator.New(); + node_ptr.SetMetadata(static_cast(PREFIX)); - NodeHandle handle(allocator, node, PREFIX); + NodeHandle handle(allocator, node_ptr, PREFIX); auto data = handle.GetPtr(); data[DEPRECATED_COUNT] = 0; return handle; } -OptionalNodePtr PrefixHandle::TransformToDeprecated(ART &art, NodePtr &node, TransformToDeprecatedState &state) { +OptionalNodePtr PrefixHandle::TransformToDeprecated(ART &art, NodePtr &node_ptr, TransformToDeprecatedState &state) { // Early-out, if we do not need any transformations. if (!state.HasAllocator()) { - NodePtr current = node; + NodePtr current_ptr = node_ptr; auto &allocator = NodePtr::GetAllocator(art, PREFIX); - while (current.GetType() == PREFIX && current.GetGateStatus() == GateStatus::GATE_NOT_SET) { - if (!allocator.LoadedFromStorage(current)) { + while (current_ptr.GetType() == PREFIX && current_ptr.GetGateStatus() == GateStatus::GATE_NOT_SET) { + if (!allocator.LoadedFromStorage(current_ptr)) { return OptionalNodePtr(); } - NodeHandle handle(art, current); - auto &child = ChildRef(art, handle); - current = child; + NodeHandle handle(art, current_ptr); + auto &child_ptr = ChildRef(art, handle); + current_ptr = child_ptr; // Handle gated endpoints while the parent of the prefix chain is still pinned. - if (current.HasMetadata() && current.GetGateStatus() == GateStatus::GATE_SET) { - Leaf::TransformToDeprecated(art, child); + if (current_ptr.HasMetadata() && current_ptr.GetGateStatus() == GateStatus::GATE_SET) { + Leaf::TransformToDeprecated(art, child_ptr); return OptionalNodePtr(); } } - return current; + return current_ptr; } // We need to create a new prefix (chain) in the deprecated format. auto &deprecated_allocator = state.GetAllocator(); - NodePtr rebuilt_prefix; - auto tail_handle = NewDeprecated(deprecated_allocator, rebuilt_prefix); + NodePtr rebuilt_prefix_ptr; + auto tail_handle = NewDeprecated(deprecated_allocator, rebuilt_prefix_ptr); auto &allocator = NodePtr::GetAllocator(art, PREFIX); - NodePtr source_prefix = node; - while (source_prefix.GetType() == PREFIX && source_prefix.GetGateStatus() == GateStatus::GATE_NOT_SET) { - if (!allocator.LoadedFromStorage(source_prefix)) { + NodePtr source_prefix_ptr = node_ptr; + while (source_prefix_ptr.GetType() == PREFIX && source_prefix_ptr.GetGateStatus() == GateStatus::GATE_NOT_SET) { + if (!allocator.LoadedFromStorage(source_prefix_ptr)) { return OptionalNodePtr(); } { // Decrease the readers on source_handle after moving all data over. - NodeHandle source_handle(art, source_prefix); + NodeHandle source_handle(art, source_prefix_ptr); auto source_data = source_handle.GetPtr(); - auto &source_child = ChildRef(art, source_handle); + auto &source_child_ptr = ChildRef(art, source_handle); for (idx_t i = 0; i < source_data[art.PrefixCount()]; i++) { tail_handle = TransformToDeprecatedAppend(std::move(tail_handle), art, deprecated_allocator, source_data[i]); } - auto &tail_child = ChildRefWithCount(tail_handle, DEPRECATED_COUNT); - tail_child = source_child; + auto &tail_child_ptr = ChildRefWithCount(tail_handle, DEPRECATED_COUNT); + tail_child_ptr = source_child_ptr; } // Freeing the node here can trigger a buffer removal (last segment on the buffer). // In that case, there cannot be any readers left on the buffer. - NodePtr::FreeNode(art, source_prefix); - auto &tail_child = ChildRefWithCount(tail_handle, DEPRECATED_COUNT); - source_prefix = tail_child; + NodePtr::FreeNode(art, source_prefix_ptr); + auto &tail_child_ptr = ChildRefWithCount(tail_handle, DEPRECATED_COUNT); + source_prefix_ptr = tail_child_ptr; } - node = rebuilt_prefix; - auto &tail_child = ChildRefWithCount(tail_handle, DEPRECATED_COUNT); + node_ptr = rebuilt_prefix_ptr; + auto &tail_child_ptr = ChildRefWithCount(tail_handle, DEPRECATED_COUNT); // Handle gated endpoints while the new prefix is still pinned. - NodePtr endpoint = tail_child; - if (endpoint.HasMetadata() && endpoint.GetGateStatus() == GateStatus::GATE_SET) { - Leaf::TransformToDeprecated(art, tail_child); + NodePtr endpoint_ptr = tail_child_ptr; + if (endpoint_ptr.HasMetadata() && endpoint_ptr.GetGateStatus() == GateStatus::GATE_SET) { + Leaf::TransformToDeprecated(art, tail_child_ptr); return OptionalNodePtr(); } - return endpoint; + return endpoint_ptr; } NodeHandle PrefixHandle::TransformToDeprecatedAppend(NodeHandle tail_handle, ART &art, FixedSizeAllocator &allocator, @@ -213,8 +213,8 @@ NodeHandle PrefixHandle::TransformToDeprecatedAppend(NodeHandle tail_handle, ART return tail_handle; } - auto &tail_child = ChildRefWithCount(tail_data, DEPRECATED_COUNT); - auto new_tail_handle = NewDeprecated(allocator, tail_child); + auto &tail_child_ptr = ChildRefWithCount(tail_data, DEPRECATED_COUNT); + auto new_tail_handle = NewDeprecated(allocator, tail_child_ptr); return TransformToDeprecatedAppend(std::move(new_tail_handle), art, allocator, byte); } diff --git a/src/duckdb/src/function/table/version/pragma_version.cpp b/src/duckdb/src/function/table/version/pragma_version.cpp index f5427f07b..506e2df72 100644 --- a/src/duckdb/src/function/table/version/pragma_version.cpp +++ b/src/duckdb/src/function/table/version/pragma_version.cpp @@ -1,5 +1,5 @@ #ifndef DUCKDB_PATCH_VERSION -#define DUCKDB_PATCH_VERSION "0-alpha43354" +#define DUCKDB_PATCH_VERSION "0-alpha43482" #endif #ifndef DUCKDB_MINOR_VERSION #define DUCKDB_MINOR_VERSION 1 @@ -8,10 +8,10 @@ #define DUCKDB_MAJOR_VERSION 2 #endif #ifndef DUCKDB_VERSION -#define DUCKDB_VERSION "v2.1.0-alpha43354" +#define DUCKDB_VERSION "v2.1.0-alpha43482" #endif #ifndef DUCKDB_SOURCE_ID -#define DUCKDB_SOURCE_ID "7bcaeeb2da" +#define DUCKDB_SOURCE_ID "cf0b14db3e" #endif #include "duckdb/function/table/system_functions.hpp" #include "duckdb/main/database.hpp" diff --git a/src/duckdb/src/function/window/window_value_function.cpp b/src/duckdb/src/function/window/window_value_function.cpp index 6d1d6b694..46b9cf04e 100644 --- a/src/duckdb/src/function/window/window_value_function.cpp +++ b/src/duckdb/src/function/window/window_value_function.cpp @@ -1312,7 +1312,10 @@ struct TryExtrapolateOperator { template static bool Operation(const T &lo, const double d, const T &hi, T &result) { if (lo > hi) { - return Operation(hi, -d, lo, result); + // Swap the endpoints to keep the offset positive. + // The slope in the exchanged frame is (1 - d), not (-d): + // lo + d*(hi - lo) == hi + (1 - d)*(lo - hi) + return Operation(hi, 1 - d, lo, result); } const auto delta = LossyNumericCast(hi) - LossyNumericCast(lo); T offset; diff --git a/src/duckdb/src/include/duckdb/execution/index/art/art.hpp b/src/duckdb/src/include/duckdb/execution/index/art/art.hpp index bf971c104..053b52b6b 100644 --- a/src/duckdb/src/include/duckdb/execution/index/art/art.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/art/art.hpp @@ -67,7 +67,7 @@ class ART : public BoundIndex { static IndexType GetARTIndexType(); //! Root of the tree. - NodePtr tree = NodePtr(); + NodePtr root_ptr = NodePtr(); //! Fixed-size allocators holding the ART nodes. shared_ptr, ALLOCATOR_COUNT>> allocators; //! True, if the ART owns its data. @@ -196,15 +196,15 @@ class ART : public BoundIndex { string GenerateErrorKeyName(DataChunk &input, idx_t row) const; string GenerateConstraintErrorMessage(VerifyExistenceType verify_type, const string &key_name) const; - void VerifyLeaf(const NodePtr &leaf, const ARTKey &key, DeleteIndexInfo delete_index_info, ConflictManager &manager, - optional_idx &conflict_idx, idx_t i) const; + void VerifyLeaf(const NodePtr &leaf_ptr, const ARTKey &key, DeleteIndexInfo delete_index_info, + ConflictManager &manager, optional_idx &conflict_idx, idx_t i) const; void VerifyConstraint(DataChunk &chunk, IndexAppendInfo &info, ConflictManager &manager) override DUCKDB_EXCLUDES(lock); string GetConstraintViolationMessage(VerifyExistenceType verify_type, idx_t failed_index, DataChunk &input) const override DUCKDB_EXCLUDES(lock); void InitializeMergeUpperBounds(unsafe_vector &upper_bounds); - void InitializeMerge(NodePtr &other_tree, unsafe_vector &upper_bounds); + void InitializeMerge(NodePtr &other_root_ptr, unsafe_vector &upper_bounds); void InitializeVacuum(unordered_set &indexes); void FinalizeVacuum(const unordered_set &indexes); diff --git a/src/duckdb/src/include/duckdb/execution/index/art/art_builder.hpp b/src/duckdb/src/include/duckdb/execution/index/art/art_builder.hpp index a7423a592..21e00d1c8 100644 --- a/src/duckdb/src/include/duckdb/execution/index/art/art_builder.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/art/art_builder.hpp @@ -22,8 +22,8 @@ class ARTBuilder { public: //! Initialize the ART builder by passing a reference to the root node. - void Init(NodePtr &node, const idx_t end) { - s.emplace(node, 0, end, 0); + void Init(NodePtr &node_ptr, const idx_t end) { + s.emplace(node_ptr, 0, end, 0); } //! Build the ART starting at the first entry in the stack. ARTConflictType Build(); @@ -31,10 +31,10 @@ class ARTBuilder { private: struct NodeEntry { NodeEntry() = delete; - NodeEntry(NodePtr &node, const idx_t start, const idx_t end, const idx_t depth) - : node(node), start(start), end(end), depth(depth) {}; + NodeEntry(NodePtr &node_ptr, const idx_t start, const idx_t end, const idx_t depth) + : node_ptr(node_ptr), start(start), end(end), depth(depth) {}; - NodePtr &node; + NodePtr &node_ptr; idx_t start; idx_t end; idx_t depth; diff --git a/src/duckdb/src/include/duckdb/execution/index/art/art_merger.hpp b/src/duckdb/src/include/duckdb/execution/index/art/art_merger.hpp index 4e5d78d18..e30b3cdd3 100644 --- a/src/duckdb/src/include/duckdb/execution/index/art/art_merger.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/art/art_merger.hpp @@ -26,7 +26,7 @@ class ARTMerger { public: //! Init the merge by setting the initial nodes. - void Init(NodePtr &left, NodePtr &right); + void Init(NodePtr &left_ptr, NodePtr &right_ptr); //! Merge until (1) triggering constraint violation or (2) all nodes have been processed. ARTConflictType Merge(); @@ -37,11 +37,11 @@ class ARTMerger { //! The depth resets when entering a gate. struct NodeEntry { NodeEntry() = delete; - NodeEntry(NodePtr &left, NodePtr &right, const GateStatus status, const idx_t depth) - : left(left), right(right), status(status), depth(depth) {}; + NodeEntry(NodePtr &left_ptr, NodePtr &right_ptr, const GateStatus status, const idx_t depth) + : left_ptr(left_ptr), right_ptr(right_ptr), status(status), depth(depth) {}; - NodePtr &left; - NodePtr &right; + NodePtr &left_ptr; + NodePtr &right_ptr; GateStatus status; idx_t depth; }; @@ -57,23 +57,24 @@ class ARTMerger { // When pushing anything on the stack, we ensure that: // - if left is LEAF_INLINED, then right is also LEAF_INLINED. // - if left is PREFIX, then right is also PREFIX (except for PREFIX + LEAF_INLINED). - void Emplace(NodePtr &left, NodePtr &right, const GateStatus parent_status, const idx_t depth); + void Emplace(NodePtr &left_ptr, NodePtr &right_ptr, const GateStatus parent_status, const idx_t depth); ARTConflictType MergeNodeAndInlined(NodeEntry &entry); - array_ptr GetBytes(NodePtr &leaf); + array_ptr GetBytes(NodePtr &leaf_ptr); void MergeLeaves(NodeEntry &entry); - NodeChildren ExtractChildren(NodePtr &node); + NodeChildren ExtractChildren(NodePtr &node_ptr); void MergeNodes(NodeEntry &entry); //! Merges a node and a prefix. //! pos determines up to which position we need to reduce the prefix. //! If we call into this function via MergePrefixes (case: one prefix contains the other), //! then pos is the length of the shorter prefix. - void MergeNodeAndPrefix(NodePtr &node, NodePtr &prefix, const GateStatus parent_status, const idx_t parent_depth, - const uint8_t pos); - void MergeNodeAndPrefix(NodePtr &node, NodePtr &prefix, const GateStatus parent_status, const idx_t parent_depth); + void MergeNodeAndPrefix(NodePtr &node_ptr, NodePtr &prefix_ptr, const GateStatus parent_status, + const idx_t parent_depth, const uint8_t pos); + void MergeNodeAndPrefix(NodePtr &node_ptr, NodePtr &prefix_ptr, const GateStatus parent_status, + const idx_t parent_depth); void MergePrefixes(NodeEntry &entry); }; diff --git a/src/duckdb/src/include/duckdb/execution/index/art/art_operator.hpp b/src/duckdb/src/include/duckdb/execution/index/art/art_operator.hpp index 336475c6e..112164245 100644 --- a/src/duckdb/src/include/duckdb/execution/index/art/art_operator.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/art/art_operator.hpp @@ -23,36 +23,36 @@ namespace duckdb { class ARTOperator { public: //! Lookup returns the leaf matching the key, or an empty OptionalNodePtr if no such leaf exists. - static OptionalNodePtr Lookup(const ART &art, const NodePtr &node, const ARTKey &key, idx_t depth) { - NodePtr current(node); + static OptionalNodePtr Lookup(const ART &art, const NodePtr &node_ptr, const ARTKey &key, idx_t depth) { + NodePtr current_ptr(node_ptr); - while (current.HasMetadata()) { - if (current.IsAnyLeaf() || current.GetGateStatus() == GateStatus::GATE_SET) { - return current; + while (current_ptr.HasMetadata()) { + if (current_ptr.IsAnyLeaf() || current_ptr.GetGateStatus() == GateStatus::GATE_SET) { + return current_ptr; } - if (current.GetType() == NType::PREFIX) { - ConstNodeHandle handle(art, current); + if (current_ptr.GetType() == NType::PREFIX) { + ConstNodeHandle handle(art, current_ptr); auto data = handle.GetPtr(); - NodePtr child = ConstPrefixHandle::ChildRef(art, handle); + NodePtr child_ptr = ConstPrefixHandle::ChildRef(art, handle); for (idx_t i = 0; i < data[art.PrefixCount()]; i++) { if (data[i] != key[depth]) { return OptionalNodePtr(); } depth++; } - current = child; + current_ptr = child_ptr; continue; } D_ASSERT(depth < key.len); - auto child = current.GetChildNode(art, key[depth]); - if (!child) { + auto child_ptr = current_ptr.GetChildNode(art, key[depth]); + if (!child_ptr) { return OptionalNodePtr(); } - current = child.Get(); - D_ASSERT(current.HasMetadata()); + current_ptr = child_ptr.Get(); + D_ASSERT(current_ptr.HasMetadata()); depth++; } @@ -62,15 +62,15 @@ class ARTOperator { //! LookupInLeaf returns true if the rowid is in the leaf: //! 1) If the leaf is an inlined leaf, check if the rowid matches. //! 2) If the leaf is a gate node, perform a search in the nested ART for the rowid. - static bool LookupInLeaf(const ART &art, const NodePtr &node, const ARTKey &rowid) { - NodePtr current(node); + static bool LookupInLeaf(const ART &art, const NodePtr &node_ptr, const ARTKey &rowid) { + NodePtr current_ptr(node_ptr); idx_t depth = 0; - while (current.HasMetadata()) { - const auto type = current.GetType(); + while (current_ptr.HasMetadata()) { + const auto type = current_ptr.GetType(); switch (type) { case NType::LEAF_INLINED: { - return current.GetRowId() == rowid.GetRowId(); + return current_ptr.GetRowId() == rowid.GetRowId(); } case NType::LEAF: { throw InternalException("Invalid node type (LEAF) for ARTOperator::NestedLookup."); @@ -80,25 +80,25 @@ class ARTOperator { case NType::NODE_256_LEAF: { D_ASSERT(depth + 1 == Prefix::ROW_ID_SIZE); const auto byte = rowid[Prefix::ROW_ID_COUNT]; - return current.HasByte(art, byte); + return current_ptr.HasByte(art, byte); } case NType::NODE_4: case NType::NODE_16: case NType::NODE_48: case NType::NODE_256: { D_ASSERT(depth < Prefix::ROW_ID_SIZE); - auto child = current.GetChildNode(art, rowid[depth]); - if (child) { + auto child_ptr = current_ptr.GetChildNode(art, rowid[depth]); + if (child_ptr) { // Continue in the child. - current = child.Get(); + current_ptr = child_ptr.Get(); depth++; - D_ASSERT(current.HasMetadata()); + D_ASSERT(current_ptr.HasMetadata()); continue; } return false; } case NType::PREFIX: { - Prefix prefix(art, current); + Prefix prefix(art, current_ptr); for (idx_t i = 0; i < prefix.data[art.PrefixCount()]; i++) { if (prefix.data[i] != rowid[depth]) { // The key and the prefix don't match. @@ -106,7 +106,7 @@ class ARTOperator { } depth++; } - current = *prefix.child_slot; + current_ptr = *prefix.child_slot; } } } @@ -116,32 +116,32 @@ class ARTOperator { //! Insert a key and its row ID into the node. //! Starts at depth (in the key). //! status indicates if the insert happens inside a gate or not. - static ARTConflictType Insert(ArenaAllocator &arena, ART &art, NodePtr &node, const ARTKey &key, idx_t depth, + static ARTConflictType Insert(ArenaAllocator &arena, ART &art, NodePtr &node_ptr, const ARTKey &key, idx_t depth, const ARTKey &row_id, GateStatus status, DeleteIndexInfo delete_index_info, const IndexAppendMode append_mode) { - reference active_node_ref(node); + reference active_node_ptr_ref(node_ptr); reference active_key_ref(key); // Early-out, if the node is empty. - if (!node.HasMetadata()) { + if (!node_ptr.HasMetadata()) { D_ASSERT(depth == 0); if (status == GateStatus::GATE_SET) { - Leaf::New(node, row_id.GetRowId()); + Leaf::New(node_ptr, row_id.GetRowId()); return ARTConflictType::NO_CONFLICT; } - Prefix::New(art, active_node_ref, active_key_ref.get(), depth, active_key_ref.get().len); - Leaf::New(active_node_ref, row_id.GetRowId()); + Prefix::New(art, active_node_ptr_ref, active_key_ref.get(), depth, active_key_ref.get().len); + Leaf::New(active_node_ptr_ref, row_id.GetRowId()); return ARTConflictType::NO_CONFLICT; } - while (active_node_ref.get().HasMetadata()) { - auto &active_node = active_node_ref.get(); + while (active_node_ptr_ref.get().HasMetadata()) { + auto &active_node_ptr = active_node_ptr_ref.get(); auto &active_key = active_key_ref.get(); // status is GATE_SET, if we've passed a gate in the previous iteration. // In that case, we have not adjusted the reference. - if (status == GateStatus::GATE_NOT_SET && active_node.GetGateStatus() == GateStatus::GATE_SET) { + if (status == GateStatus::GATE_NOT_SET && active_node_ptr.GetGateStatus() == GateStatus::GATE_SET) { if (!art.IsUnique()) { // Enter a gate. active_key_ref = row_id; @@ -163,14 +163,14 @@ class ARTOperator { art.name); } - const auto type = active_node.GetType(); + const auto type = active_node_ptr.GetType(); switch (type) { case NType::LEAF_INLINED: { - return InsertIntoInlined(arena, art, active_node, key, row_id, depth, status, delete_index_info, + return InsertIntoInlined(arena, art, active_node_ptr, key, row_id, depth, status, delete_index_info, append_mode); } case NType::LEAF: { - Leaf::TransformToNested(art, active_node); + Leaf::TransformToNested(art, active_node_ptr); continue; } case NType::NODE_7_LEAF: @@ -178,7 +178,7 @@ class ARTOperator { case NType::NODE_256_LEAF: { // Row IDs are unique; there are never any duplicate byte conflicts. auto byte = active_key[Prefix::ROW_ID_COUNT]; - NodePtr::InsertChild(art, active_node, byte); + NodePtr::InsertChild(art, active_node_ptr, byte); return ARTConflictType::NO_CONFLICT; } case NType::NODE_4: @@ -186,29 +186,29 @@ class ARTOperator { case NType::NODE_48: case NType::NODE_256: { D_ASSERT(depth < active_key.len); - auto child = active_node.GetChildMutable(art, active_key[depth]); - if (child) { + auto child_ptr_ref = active_node_ptr.GetChildMutable(art, active_key[depth]); + if (child_ptr_ref) { // Continue in the child. - active_node_ref = *child; + active_node_ptr_ref = *child_ptr_ref; depth++; - D_ASSERT(active_node_ref.get().HasMetadata()); + D_ASSERT(active_node_ptr_ref.get().HasMetadata()); continue; } - InsertIntoNode(art, active_node, key, row_id, depth, status); + InsertIntoNode(art, active_node_ptr, key, row_id, depth, status); return ARTConflictType::NO_CONFLICT; } case NType::PREFIX: { - Prefix prefix(art, active_node, true); + Prefix prefix(art, active_node_ptr, true); for (idx_t i = 0; i < prefix.data[art.PrefixCount()]; i++) { if (prefix.data[i] != active_key[depth]) { // The active key and the prefix don't match. - InsertIntoPrefix(art, active_node_ref, active_key, row_id, i, depth, status); + InsertIntoPrefix(art, active_node_ptr_ref, active_key, row_id, i, depth, status); return ARTConflictType::NO_CONFLICT; } depth++; } - active_node_ref = *prefix.child_slot; - D_ASSERT(active_node_ref.get().HasMetadata()); + active_node_ptr_ref = *prefix.child_slot; + D_ASSERT(active_node_ptr_ref.get().HasMetadata()); continue; } default: @@ -220,14 +220,14 @@ class ARTOperator { //! Delete a key and its row ID. //! Assumes that deletion starts at the root of the tree. - static bool Delete(ART &art, NodePtr &node, const ARTKey &key, const ARTKey &row_id) { + static bool Delete(ART &art, NodePtr &node_ptr, const ARTKey &key, const ARTKey &row_id) { // If we need to compress a Node4 into a one-way node, // then we need the previous prefix before the Node4. - NodePtr empty; - reference great_grandparent_ref(empty); - reference grandparent_ref(empty); - reference parent_ref(node); - reference current_ref(node); + NodePtr empty_ptr; + reference great_grandparent_ptr_ref(empty_ptr); + reference grandparent_ptr_ref(empty_ptr); + reference parent_ptr_ref(node_ptr); + reference current_ptr_ref(node_ptr); reference current_key_ref(key); idx_t grandparent_depth = 0; @@ -236,62 +236,62 @@ class ARTOperator { auto status = GateStatus::GATE_NOT_SET; auto passed_internal_node = false; - while (current_ref.get().HasMetadata()) { + while (current_ptr_ref.get().HasMetadata()) { // Enter gate. - if (status == GateStatus::GATE_NOT_SET && current_ref.get().GetGateStatus() == GateStatus::GATE_SET) { + if (status == GateStatus::GATE_NOT_SET && current_ptr_ref.get().GetGateStatus() == GateStatus::GATE_SET) { status = GateStatus::GATE_SET; current_key_ref = row_id; depth = 0; continue; } - const auto type = current_ref.get().GetType(); + const auto type = current_ptr_ref.get().GetType(); switch (type) { case NType::LEAF_INLINED: { - if (current_ref.get().GetRowId() != row_id.GetRowId()) { + if (current_ptr_ref.get().GetRowId() != row_id.GetRowId()) { return false; } - if (!passed_internal_node && parent_ref.get().GetType() == NType::PREFIX) { + if (!passed_internal_node && parent_ptr_ref.get().GetType() == NType::PREFIX) { // The tree contains exactly one element with a prefix. - NodePtr::FreeTree(art, parent_ref); + NodePtr::FreeTree(art, parent_ptr_ref); return true; } - if (parent_ref.get().GetType() == NType::PREFIX) { + if (parent_ptr_ref.get().GetType() == NType::PREFIX) { // We might have to compress: // PREFIX (greatgrandparent) - Node4 (grandparent) - PREFIX - INLINED_LEAF. // The parent does not have to be passed in, as it is a child of the possibly being compressed N4. // Then, when we delete that child, we also free it. - NodePtr::DeleteChild(art, grandparent_ref, great_grandparent_ref, + NodePtr::DeleteChild(art, grandparent_ptr_ref, great_grandparent_ptr_ref, current_key_ref.get()[grandparent_depth], status, row_id); return true; } - NodePtr::DeleteChild(art, parent_ref, grandparent_ref, current_key_ref.get()[parent_depth], status, - row_id); + NodePtr::DeleteChild(art, parent_ptr_ref, grandparent_ptr_ref, current_key_ref.get()[parent_depth], + status, row_id); return true; } case NType::LEAF: { D_ASSERT(status == GateStatus::GATE_NOT_SET); - Leaf::TransformToNested(art, current_ref); + Leaf::TransformToNested(art, current_ptr_ref); break; } case NType::PREFIX: { - great_grandparent_ref = grandparent_ref; - grandparent_ref = parent_ref; - parent_ref = current_ref; + great_grandparent_ptr_ref = grandparent_ptr_ref; + grandparent_ptr_ref = parent_ptr_ref; + parent_ptr_ref = current_ptr_ref; grandparent_depth = parent_depth; parent_depth = depth; // Traverse a prefix chain until the next non-prefix node or gate. - while (current_ref.get().GetType() == NType::PREFIX) { - Prefix prefix(art, current_ref, true); + while (current_ptr_ref.get().GetType() == NType::PREFIX) { + Prefix prefix(art, current_ptr_ref, true); for (idx_t i = 0; i < prefix.data[art.PrefixCount()]; i++) { if (prefix.data[i] != current_key_ref.get()[depth]) { return false; } depth++; } - current_ref = *prefix.child_slot; - if (current_ref.get().GetGateStatus() == GateStatus::GATE_SET) { + current_ptr_ref = *prefix.child_slot; + if (current_ptr_ref.get().GetGateStatus() == GateStatus::GATE_SET) { break; } } @@ -302,19 +302,19 @@ class ARTOperator { case NType::NODE_48: case NType::NODE_256: { passed_internal_node = true; - great_grandparent_ref = grandparent_ref; - grandparent_ref = parent_ref; - parent_ref = current_ref; + great_grandparent_ptr_ref = grandparent_ptr_ref; + grandparent_ptr_ref = parent_ptr_ref; + parent_ptr_ref = current_ptr_ref; grandparent_depth = parent_depth; parent_depth = depth; - auto child = current_ref.get().GetChildMutable(art, current_key_ref.get()[depth]); - if (!child) { + auto child_ptr_ref = current_ptr_ref.get().GetChildMutable(art, current_key_ref.get()[depth]); + if (!child_ptr_ref) { // No child at the byte: nothing to erase. return false; } - current_ref = *child; + current_ptr_ref = *child_ptr_ref; depth++; break; } @@ -322,8 +322,8 @@ class ARTOperator { case NType::NODE_15_LEAF: case NType::NODE_256_LEAF: { const auto byte = current_key_ref.get()[depth]; - if (current_ref.get().HasByte(art, byte)) { - NodePtr::DeleteChild(art, current_ref, parent_ref, byte, status, row_id); + if (current_ptr_ref.get().HasByte(art, byte)) { + NodePtr::DeleteChild(art, current_ptr_ref, parent_ptr_ref, byte, status, row_id); return true; } return false; @@ -334,14 +334,14 @@ class ARTOperator { } private: - static ARTConflictType InsertIntoInlined(ArenaAllocator &arena, ART &art, NodePtr &node, const ARTKey &key, + static ARTConflictType InsertIntoInlined(ArenaAllocator &arena, ART &art, NodePtr &node_ptr, const ARTKey &key, const ARTKey &row_id, const idx_t depth, const GateStatus status, DeleteIndexInfo delete_index_info, const IndexAppendMode append_mode) { - NodePtr row_id_node; - Leaf::New(row_id_node, row_id.GetRowId()); + NodePtr row_id_node_ptr; + Leaf::New(row_id_node_ptr, row_id.GetRowId()); if (!art.IsUnique() || append_mode == IndexAppendMode::INSERT_DUPLICATES) { - Leaf::MergeInlined(arena, art, node, row_id_node, status, depth); + Leaf::MergeInlined(arena, art, node_ptr, row_id_node_ptr, status, depth); return ARTConflictType::NO_CONFLICT; } @@ -349,22 +349,22 @@ class ARTOperator { // Lookup in the delete_art. for (auto &delete_index : *delete_index_info.delete_indexes) { auto &delete_art = delete_index.get().Cast(); - auto delete_leaf = Lookup(delete_art, delete_art.tree, key, 0); - if (!delete_leaf) { + auto delete_leaf_ptr = Lookup(delete_art, delete_art.root_ptr, key, 0); + if (!delete_leaf_ptr) { continue; } // The row ID has changed. // Thus, the local index has a newer (local) row ID, and this is a constraint violation. - D_ASSERT(delete_leaf.Get().GetType() == NType::LEAF_INLINED); - auto deleted_row_id = delete_leaf.Get().GetRowId(); - auto this_row_id = node.GetRowId(); + D_ASSERT(delete_leaf_ptr.Get().GetType() == NType::LEAF_INLINED); + auto deleted_row_id = delete_leaf_ptr.Get().GetRowId(); + auto this_row_id = node_ptr.GetRowId(); if (deleted_row_id != this_row_id) { continue; } // The deleted key and its row ID match the current key and its row ID. - Leaf::MergeInlined(arena, art, node, row_id_node, status, depth); + Leaf::MergeInlined(arena, art, node_ptr, row_id_node_ptr, status, depth); return ARTConflictType::NO_CONFLICT; } } @@ -374,42 +374,42 @@ class ARTOperator { return ARTConflictType::CONSTRAINT; } - static void InsertIntoNode(ART &art, NodePtr &node, const ARTKey &key, const ARTKey &row_id, const idx_t depth, + static void InsertIntoNode(ART &art, NodePtr &node_ptr, const ARTKey &key, const ARTKey &row_id, const idx_t depth, const GateStatus status) { if (status == GateStatus::GATE_SET) { // Inside gates, we compress prefixes that only have an inlined // row ID as their child. - NodePtr row_id_node; - Leaf::New(row_id_node, row_id.GetRowId()); - NodePtr::InsertChild(art, node, row_id[depth], row_id_node); + NodePtr row_id_node_ptr; + Leaf::New(row_id_node_ptr, row_id.GetRowId()); + NodePtr::InsertChild(art, node_ptr, row_id[depth], row_id_node_ptr); return; } - NodePtr leaf; + NodePtr leaf_ptr; if (depth + 1 < key.len) { // Outside of gates, we create a prefix for the inlined leaf. auto count = key.len - depth - 1; auto chain = PrefixHandle::New(art, key, depth + 1, count); Leaf::New(chain.tail.Child(art), row_id.GetRowId()); - leaf = chain.root; + leaf_ptr = chain.root_ptr; } else { - Leaf::New(leaf, row_id.GetRowId()); + Leaf::New(leaf_ptr, row_id.GetRowId()); } - NodePtr::InsertChild(art, node, key[depth], leaf); + NodePtr::InsertChild(art, node_ptr, key[depth], leaf_ptr); } - static void InsertIntoPrefix(ART &art, reference &node_ref, const ARTKey &key, const ARTKey &row_id, + static void InsertIntoPrefix(ART &art, reference &node_ptr_ref, const ARTKey &key, const ARTKey &row_id, const idx_t pos, const idx_t depth, const GateStatus status) { const auto cast_pos = UnsafeNumericCast(pos); - const auto byte = Prefix::GetByte(art, node_ref, cast_pos); + const auto byte = Prefix::GetByte(art, node_ptr_ref, cast_pos); - NodePtr branching_node4; - Node4::New(art, branching_node4); - auto child = PrefixHandle::Split(art, node_ref, branching_node4, cast_pos); + NodePtr branching_node4_ptr; + Node4::New(art, branching_node4_ptr); + auto child_ptr = PrefixHandle::Split(art, node_ptr_ref, branching_node4_ptr, cast_pos); - Node4::InsertChild(art, branching_node4, byte, child); - InsertIntoNode(art, branching_node4, key, row_id, depth, status); + Node4::InsertChild(art, branching_node4_ptr, byte, child_ptr); + InsertIntoNode(art, branching_node4_ptr, key, row_id, depth, status); } }; diff --git a/src/duckdb/src/include/duckdb/execution/index/art/art_scanner.hpp b/src/duckdb/src/include/duckdb/execution/index/art/art_scanner.hpp index 480b33691..e3e9b10b9 100644 --- a/src/duckdb/src/include/duckdb/execution/index/art/art_scanner.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/art/art_scanner.hpp @@ -23,21 +23,21 @@ enum class ARTScanNodeResult : uint8_t { SCAN_CHILDREN, SKIP }; //! child_handler runs under the pin, can update the slot in place, //! and returns the NodePtr value to push, or an empty OptionalNodePtr. template -void ARTScanChildrenInternal(ART_TYPE &art, const NodePtr node, CHILD_HANDLER &&child_handler, PUSH &&push) { - NODE_HANDLE handle(art, node); +void ARTScanChildrenInternal(ART_TYPE &art, const NodePtr node_ptr, CHILD_HANDLER &&child_handler, PUSH &&push) { + NODE_HANDLE handle(art, node_ptr); auto &n = handle.template Get(); - NODE::Iterator(n, [&](auto &child) { - auto next = child_handler(child); - if (next) { - push(next.Get()); + NODE::Iterator(n, [&](auto &child_ptr) { + auto next_ptr = child_handler(child_ptr); + if (next_ptr) { + push(next_ptr.Get()); } }); } //! Dispatches on the node type and scans the children of current (see ARTScanChildrenInternal). template -void ARTScanChildren(ART_TYPE &art, const NodePtr current, CHILD_HANDLER &&child_handler, PUSH &&push) { - switch (current.GetType()) { +void ARTScanChildren(ART_TYPE &art, const NodePtr current_ptr, CHILD_HANDLER &&child_handler, PUSH &&push) { + switch (current_ptr.GetType()) { case NType::LEAF_INLINED: case NType::LEAF: case NType::NODE_7_LEAF: @@ -45,28 +45,28 @@ void ARTScanChildren(ART_TYPE &art, const NodePtr current, CHILD_HANDLER &&child case NType::NODE_256_LEAF: break; case NType::PREFIX: { - NODE_HANDLE handle(art, current); - auto &child = PREFIX::ChildRef(art, handle); - auto next = child_handler(child); - if (next) { - push(next.Get()); + NODE_HANDLE handle(art, current_ptr); + auto &child_ptr = PREFIX::ChildRef(art, handle); + auto next_ptr = child_handler(child_ptr); + if (next_ptr) { + push(next_ptr.Get()); } break; } case NType::NODE_4: - ARTScanChildrenInternal(art, current, child_handler, push); + ARTScanChildrenInternal(art, current_ptr, child_handler, push); break; case NType::NODE_16: - ARTScanChildrenInternal(art, current, child_handler, push); + ARTScanChildrenInternal(art, current_ptr, child_handler, push); break; case NType::NODE_48: - ARTScanChildrenInternal(art, current, child_handler, push); + ARTScanChildrenInternal(art, current_ptr, child_handler, push); break; case NType::NODE_256: - ARTScanChildrenInternal(art, current, child_handler, push); + ARTScanChildrenInternal(art, current_ptr, child_handler, push); break; default: - throw InternalException("invalid node type for ARTScanChildren: %d", current.GetType()); + throw InternalException("invalid node type for ARTScanChildren: %d", current_ptr.GetType()); } } @@ -75,27 +75,27 @@ void ARTScanChildren(ART_TYPE &art, const NodePtr current, CHILD_HANDLER &&child //===--------------------------------------------------------------------===// template -void ARTScanPreorderInternal(ART_TYPE &art, NODE_REF &root, CHILD_HANDLER &&child_handler, ON_POP &&on_pop) { +void ARTScanPreorderInternal(ART_TYPE &art, NODE_REF &root_ptr, CHILD_HANDLER &&child_handler, ON_POP &&on_pop) { vector stack; - auto push = [&stack](const NodePtr node) { - stack.push_back(node); + auto push = [&stack](const NodePtr node_ptr) { + stack.push_back(node_ptr); }; // The caller must keep the root slot valid while child_handler runs. This is implicit for the // top-level ART root used by current callers; a subtree root requires its containing parent to remain pinned. - auto next = child_handler(root); - if (next) { - push(next.Get()); + auto next_ptr = child_handler(root_ptr); + if (next_ptr) { + push(next_ptr.Get()); } while (!stack.empty()) { - NodePtr current = stack.back(); + NodePtr current_ptr = stack.back(); stack.pop_back(); - if (on_pop(current) == ARTScanNodeResult::SKIP) { + if (on_pop(current_ptr) == ARTScanNodeResult::SKIP) { continue; } - ARTScanChildren(art, current, child_handler, push); + ARTScanChildren(art, current_ptr, child_handler, push); } } @@ -106,14 +106,14 @@ void ARTScanPreorderInternal(ART_TYPE &art, NODE_REF &root, CHILD_HANDLER &&chil //! on_pop runs on each popped node with no scanner-owned handles held and decides whether to scan its children. //! The caller may still hold a pin protecting the root slot. template -void ARTScanPreorder(ART &art, NodePtr &root, CHILD_HANDLER &&child_handler, ON_POP &&on_pop) { - ARTScanPreorderInternal(art, root, child_handler, on_pop); +void ARTScanPreorder(ART &art, NodePtr &root_ptr, CHILD_HANDLER &&child_handler, ON_POP &&on_pop) { + ARTScanPreorderInternal(art, root_ptr, child_handler, on_pop); } //! Pre-order scanner over an immutable ART (see ARTScanPreorder). template -void ARTConstScanPreorder(const ART &art, const NodePtr &root, CHILD_HANDLER &&child_handler, ON_POP &&on_pop) { - ARTScanPreorderInternal(art, root, child_handler, on_pop); +void ARTConstScanPreorder(const ART &art, const NodePtr &root_ptr, CHILD_HANDLER &&child_handler, ON_POP &&on_pop) { + ARTScanPreorderInternal(art, root_ptr, child_handler, on_pop); } //===--------------------------------------------------------------------===// @@ -121,11 +121,11 @@ void ARTConstScanPreorder(const ART &art, const NodePtr &root, CHILD_HANDLER &&c //===--------------------------------------------------------------------===// struct ARTPostOrderScanEntry { - ARTPostOrderScanEntry(NodePtr node_p, bool children_visited_p) - : node(node_p), children_visited(children_visited_p) { + ARTPostOrderScanEntry(NodePtr node_ptr, bool children_visited_p) + : node_ptr(node_ptr), children_visited(children_visited_p) { } - NodePtr node; + NodePtr node_ptr; bool children_visited; }; @@ -135,26 +135,26 @@ struct ARTPostOrderScanEntry { //! On the second visit, after all descendants have been processed, post_handler runs with no scanner-owned handles //! held. The caller may still hold a pin protecting the root slot. template -void ARTScanPostorder(ART &art, NodePtr &root, CHILD_HANDLER &&child_handler, POST_HANDLER &&post_handler) { +void ARTScanPostorder(ART &art, NodePtr &root_ptr, CHILD_HANDLER &&child_handler, POST_HANDLER &&post_handler) { vector stack; - auto push = [&stack](const NodePtr node) { - stack.push_back(ARTPostOrderScanEntry {node, false}); + auto push = [&stack](const NodePtr node_ptr) { + stack.push_back(ARTPostOrderScanEntry {node_ptr, false}); }; - D_ASSERT(root.HasMetadata()); - stack.push_back(ARTPostOrderScanEntry {root, false}); + D_ASSERT(root_ptr.HasMetadata()); + stack.push_back(ARTPostOrderScanEntry {root_ptr, false}); while (!stack.empty()) { if (stack.back().children_visited) { - auto current = stack.back().node; - post_handler(current); + auto current_ptr = stack.back().node_ptr; + post_handler(current_ptr); stack.pop_back(); continue; } - auto current = stack.back().node; + auto current_ptr = stack.back().node_ptr; stack.back().children_visited = true; - ARTScanChildren(art, current, child_handler, push); + ARTScanChildren(art, current_ptr, child_handler, push); } } diff --git a/src/duckdb/src/include/duckdb/execution/index/art/base_leaf.hpp b/src/duckdb/src/include/duckdb/execution/index/art/base_leaf.hpp index 41be93d3e..3cb0e5dd8 100644 --- a/src/duckdb/src/include/duckdb/execution/index/art/base_leaf.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/art/base_leaf.hpp @@ -33,11 +33,11 @@ class BaseLeaf { public: //! Get a new BaseLeaf and initialize it. - static NodeHandle New(ART &art, NodePtr &node) { - node = NodePtr::GetAllocator(art, TYPE).New(); - node.SetMetadata(static_cast(TYPE)); + static NodeHandle New(ART &art, NodePtr &node_ptr) { + node_ptr = NodePtr::GetAllocator(art, TYPE).New(); + node_ptr.SetMetadata(static_cast(TYPE)); - NodeHandle handle(art, node); + NodeHandle handle(art, node_ptr); auto &n = handle.Get(); n.count = 0; @@ -74,7 +74,7 @@ class BaseLeaf { private: static void InsertByteInternal(BaseLeaf &n, const uint8_t byte); - static NodeHandle DeleteByteInternal(ART &art, NodePtr &node, const uint8_t byte); + static NodeHandle DeleteByteInternal(ART &art, NodePtr &node_ptr, const uint8_t byte); }; //! Node7Leaf holds up to seven sorted bytes. @@ -88,12 +88,12 @@ class Node7Leaf : public BaseLeaf<7, NType::NODE_7_LEAF> { public: //! Insert a byte. - static void InsertByte(ART &art, NodePtr &node, const uint8_t byte); + static void InsertByte(ART &art, NodePtr &node_ptr, const uint8_t byte); //! Delete a byte. - static void DeleteByte(ART &art, NodePtr &node, NodePtr &prefix, const uint8_t byte, const ARTKey &row_id); + static void DeleteByte(ART &art, NodePtr &node_ptr, NodePtr &parent_ptr, const uint8_t byte, const ARTKey &row_id); private: - static void ShrinkNode15Leaf(ART &art, NodePtr &node7_leaf, NodePtr &node15_leaf); + static void ShrinkNode15Leaf(ART &art, NodePtr &node7_leaf_ptr, NodePtr &node15_leaf_ptr); }; //! Node15Leaf holds up to 15 sorted bytes. @@ -107,14 +107,14 @@ class Node15Leaf : public BaseLeaf<15, NType::NODE_15_LEAF> { public: //! Insert a byte. - static void InsertByte(ART &art, NodePtr &node, const uint8_t byte); + static void InsertByte(ART &art, NodePtr &node_ptr, const uint8_t byte); //! Delete a byte. - static void DeleteByte(ART &art, NodePtr &node, const uint8_t byte); + static void DeleteByte(ART &art, NodePtr &node_ptr, const uint8_t byte); private: - static void GrowNode7Leaf(ART &art, NodePtr &node15_leaf, NodePtr &node7_leaf); + static void GrowNode7Leaf(ART &art, NodePtr &node15_leaf_ptr, NodePtr &node7_leaf_ptr); //! We shrink at <= Node48::SHRINK_THRESHOLD. - static void ShrinkNode256Leaf(ART &art, NodePtr &node15_leaf, NodePtr &node256_leaf); + static void ShrinkNode256Leaf(ART &art, NodePtr &node15_leaf_ptr, NodePtr &node256_leaf_ptr); }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/execution/index/art/base_node.hpp b/src/duckdb/src/include/duckdb/execution/index/art/base_node.hpp index dd0e4b746..85a632c01 100644 --- a/src/duckdb/src/include/duckdb/execution/index/art/base_node.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/art/base_node.hpp @@ -34,11 +34,11 @@ class BaseNode { public: //! Get a new BaseNode handle and initialize the base node. - static NodeHandle New(ART &art, NodePtr &node) { - node = NodePtr::GetAllocator(art, TYPE).New(); - node.SetMetadata(static_cast(TYPE)); + static NodeHandle New(ART &art, NodePtr &node_ptr) { + node_ptr = NodePtr::GetAllocator(art, TYPE).New(); + node_ptr.SetMetadata(static_cast(TYPE)); - NodeHandle handle(art, node); + NodeHandle handle(art, node_ptr); auto &n = handle.Get(); // Reset the node (count). @@ -53,14 +53,14 @@ class BaseNode { } //! Replace the child at byte. - static void ReplaceChild(BaseNode &n, const uint8_t byte, const NodePtr child) { + static void ReplaceChild(BaseNode &n, const uint8_t byte, const NodePtr child_ptr) { D_ASSERT(n.count != 0); for (uint8_t i = 0; i < n.count; i++) { if (n.key[i] == byte) { auto status = n.children[i].GetGateStatus(); - n.children[i] = child; + n.children[i] = child_ptr; - if (status == GateStatus::GATE_SET && child.HasMetadata()) { + if (status == GateStatus::GATE_SET && child_ptr.HasMetadata()) { n.children[i].SetGateStatus(status); } return; @@ -153,8 +153,8 @@ class BaseNode { } private: - static void InsertChildInternal(BaseNode &n, const uint8_t byte, const NodePtr child); - static NodeHandle DeleteChildInternal(ART &art, NodePtr &node, const uint8_t byte); + static void InsertChildInternal(BaseNode &n, const uint8_t byte, const NodePtr child_ptr); + static NodeHandle DeleteChildInternal(ART &art, NodePtr &node_ptr, const uint8_t byte); }; //! Node4 holds up to four children sorted by their key byte. @@ -167,12 +167,13 @@ class Node4 : public BaseNode<4, NType::NODE_4> { public: //! Insert a child at byte. - static void InsertChild(ART &art, NodePtr &node, const uint8_t byte, const NodePtr child); + static void InsertChild(ART &art, NodePtr &node_ptr, const uint8_t byte, const NodePtr child_ptr); //! Delete the child at byte. - static void DeleteChild(ART &art, NodePtr &node, NodePtr &prefix, const uint8_t byte, const GateStatus status); + static void DeleteChild(ART &art, NodePtr &node_ptr, NodePtr &parent_ptr, const uint8_t byte, + const GateStatus status); private: - static void ShrinkNode16(ART &art, NodePtr &node4, NodePtr &node16); + static void ShrinkNode16(ART &art, NodePtr &node4_ptr, NodePtr &node16_ptr); }; class Node16 : public BaseNode<16, NType::NODE_16> { @@ -185,14 +186,14 @@ class Node16 : public BaseNode<16, NType::NODE_16> { public: //! Insert a child at byte. - static void InsertChild(ART &art, NodePtr &node, const uint8_t byte, const NodePtr child); + static void InsertChild(ART &art, NodePtr &node_ptr, const uint8_t byte, const NodePtr child_ptr); //! Delete the child at byte. - static void DeleteChild(ART &art, NodePtr &node, const uint8_t byte); + static void DeleteChild(ART &art, NodePtr &node_ptr, const uint8_t byte); private: - static void GrowNode4(ART &art, NodePtr &node16, NodePtr &node4); + static void GrowNode4(ART &art, NodePtr &node16_ptr, NodePtr &node4_ptr); //! We shrink at < Node48::SHRINK_THRESHOLD. - static void ShrinkNode48(ART &art, NodePtr &node16, NodePtr &node48); + static void ShrinkNode48(ART &art, NodePtr &node16_ptr, NodePtr &node48_ptr); }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/execution/index/art/const_prefix_handle.hpp b/src/duckdb/src/include/duckdb/execution/index/art/const_prefix_handle.hpp index f88106c06..0d3109f39 100644 --- a/src/duckdb/src/include/duckdb/execution/index/art/const_prefix_handle.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/art/const_prefix_handle.hpp @@ -20,8 +20,8 @@ class ConstPrefixHandle { static constexpr NType PREFIX = NType::PREFIX; public: - explicit ConstPrefixHandle(const ART &art, const NodePtr node) : handle(art, node) { - D_ASSERT(node.GetType() == PREFIX); + explicit ConstPrefixHandle(const ART &art, const NodePtr node_ptr) : handle(art, node_ptr) { + D_ASSERT(node_ptr.GetType() == PREFIX); } ConstPrefixHandle(const ConstPrefixHandle &) = delete; @@ -54,27 +54,27 @@ class ConstPrefixHandle { } //! Traverses and verifies the node and its subtree. - static void Verify(ART &art, const NodePtr &node); + static void Verify(ART &art, const NodePtr &node_ptr); //! Returns the string representation of the node using ToStringOptions. - static string ToString(ART &art, const NodePtr &node, const ToStringOptions &options); + static string ToString(ART &art, const NodePtr &node_ptr, const ToStringOptions &options); private: template - static NodePtr Iterator(ART &art, NodePtr node, const bool exit_gate, F &&lambda) { - while (node.HasMetadata() && node.GetType() == PREFIX) { - ConstNodeHandle handle(art, node); + static NodePtr Iterator(ART &art, NodePtr node_ptr, const bool exit_gate, F &&lambda) { + while (node_ptr.HasMetadata() && node_ptr.GetType() == PREFIX) { + ConstNodeHandle handle(art, node_ptr); auto data = handle.GetPtr(); - NodePtr child = ChildRef(art, handle); + NodePtr child_ptr = ChildRef(art, handle); - lambda(handle, data, child); + lambda(handle, data, child_ptr); - node = child; - if (exit_gate && node.GetGateStatus() == GateStatus::GATE_SET) { + node_ptr = child_ptr; + if (exit_gate && node_ptr.GetGateStatus() == GateStatus::GATE_SET) { break; } } - return node; + return node_ptr; } private: diff --git a/src/duckdb/src/include/duckdb/execution/index/art/iterator.hpp b/src/duckdb/src/include/duckdb/execution/index/art/iterator.hpp index 59815724d..635f3a445 100644 --- a/src/duckdb/src/include/duckdb/execution/index/art/iterator.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/art/iterator.hpp @@ -17,10 +17,10 @@ namespace duckdb { //! Keeps track of the byte leading to the currently active child of the node. struct IteratorEntry { - IteratorEntry(NodePtr node, uint8_t byte) : node(node), byte(byte) { + IteratorEntry(NodePtr node_ptr, uint8_t byte) : node_ptr(node_ptr), byte(byte) { } - NodePtr node; + NodePtr node_ptr; uint8_t byte = 0; }; @@ -164,10 +164,10 @@ class Iterator { ARTScanProgress Scan(const ARTKey &upper_bound, Output &output, bool equal); //! Finds the minimum (leaf) of the current subtree. - void FindMinimum(NodePtr current); + void FindMinimum(NodePtr current_ptr); //! Finds the lower bound of the ART and adds the nodes to the stack. Returns false, if the lower //! bound exceeds the maximum value of the ART. - bool LowerBound(NodePtr current, const ARTKey &key, const bool equal); + bool LowerBound(NodePtr current_ptr, const ARTKey &key, const bool equal); //! Returns the nested depth. uint8_t GetNestedDepth() const { @@ -180,7 +180,7 @@ class Iterator { //! Stack of nodes from the root to the currently active node. stack nodes; //! Last visited leaf node. - NodePtr last_leaf = NodePtr(); + NodePtr last_leaf_ptr = NodePtr(); //! Holds the row ID of nested leaves. uint8_t row_id[ROW_ID_SIZE]; //! True, if we passed a gate. @@ -204,7 +204,7 @@ class Iterator { ResumeScanState resume_state; private: - //! Goes to the next leaf in the ART and sets it as last_leaf, + //! Goes to the next leaf in the ART and sets it as last_leaf_ptr, //! returns false if there is no next leaf. bool Next(); //! Pop the top node from the stack of iterator entries and adjust the current key. diff --git a/src/duckdb/src/include/duckdb/execution/index/art/leaf.hpp b/src/duckdb/src/include/duckdb/execution/index/art/leaf.hpp index fccf100ca..2977e6692 100644 --- a/src/duckdb/src/include/duckdb/execution/index/art/leaf.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/art/leaf.hpp @@ -36,39 +36,41 @@ class Leaf { private: uint8_t count; // Deprecated. row_t row_ids[LEAF_SIZE]; // Deprecated. - NodePtr next_leaf; // Deprecated. + NodePtr next_leaf_ptr; // Deprecated. public: //! Inline a row ID into a node pointer. - static void New(NodePtr &node, const row_t row_id); + static void New(NodePtr &node_ptr, const row_t row_id); //! Merge two inlined leaf nodes. - static void MergeInlined(ArenaAllocator &arena, ART &art, NodePtr &left, NodePtr &right, GateStatus status, + static void MergeInlined(ArenaAllocator &arena, ART &art, NodePtr &left_ptr, NodePtr &right_ptr, GateStatus status, idx_t depth); //! Transforms a deprecated leaf to a nested leaf. - static void TransformToNested(ART &art, NodePtr &node); + static void TransformToNested(ART &art, NodePtr &node_ptr); //! Transforms a nested leaf to a deprecated leaf. - static void TransformToDeprecated(ART &art, NodePtr &node); + static void TransformToDeprecated(ART &art, NodePtr &node_ptr); public: //! Frees the linked list of leaves. - static void DeprecatedFree(ART &art, NodePtr &node); + static void DeprecatedFree(ART &art, NodePtr &node_ptr); //! Fills the row_ids vector with the row IDs of this linked list of leaves. //! Never pushes more than max_count row IDs. - static bool DeprecatedGetRowIds(const ART &art, const NodePtr &node, set &row_ids, const idx_t max_count); + static bool DeprecatedGetRowIds(const ART &art, const NodePtr &node_ptr, set &row_ids, + const idx_t max_count); //! Vacuums the internal links in the deprecated leaf list pointed to by node. //! The caller is responsible for vacuuming the slot that points to the list head. - static void DeprecatedVacuum(ART &art, NodePtr node); + static void DeprecatedVacuum(ART &art, NodePtr node_ptr); //! Traverses and verifies the linked list of leaves. - static void DeprecatedVerify(ART &art, const NodePtr &node); + static void DeprecatedVerify(ART &art, const NodePtr &node_ptr); //! Count the number of leaves. - static void DeprecatedVerifyAllocations(ART &art, const NodePtr &node, unordered_map &node_counts); + static void DeprecatedVerifyAllocations(ART &art, const NodePtr &node_ptr, + unordered_map &node_counts); //! Return string representation of the linked list of leaves. //! If print_deprecated_leaves is false, returns "[deprecated leaves]" with proper indentation. - static string DeprecatedToString(ART &art, const NodePtr &node, const ToStringOptions &options); + static string DeprecatedToString(ART &art, const NodePtr &node_ptr, const ToStringOptions &options); }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/execution/index/art/node.hpp b/src/duckdb/src/include/duckdb/execution/index/art/node.hpp index 31472faab..0a77d42dd 100644 --- a/src/duckdb/src/include/duckdb/execution/index/art/node.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/art/node.hpp @@ -121,11 +121,11 @@ class NodePtr : public IndexPointer { public: //! Get a new pointer to a node and initialize it. - static void New(ART &art, NodePtr &node, const NType type); + static void New(ART &art, NodePtr &node_ptr, const NType type); //! Free the node. - static void FreeNode(ART &art, NodePtr &node); + static void FreeNode(ART &art, NodePtr &node_ptr); //! Free the node and its children. - static void FreeTree(ART &art, NodePtr &node); + static void FreeTree(ART &art, NodePtr &subtree_root_ptr); //! Get a reference to the allocator. static FixedSizeAllocator &GetAllocator(const ART &art, const NType type); @@ -134,18 +134,18 @@ class NodePtr : public IndexPointer { //! Get a reference to a node. template - static inline NODE &Ref(const ART &art, const NodePtr node, const NType type) { - D_ASSERT(node.GetType() != NType::PREFIX); - return *(GetAllocator(art, type).Get(node, !std::is_const::value)); + static inline NODE &Ref(const ART &art, const NodePtr node_ptr, const NType type) { + D_ASSERT(node_ptr.GetType() != NType::PREFIX); + return *(GetAllocator(art, type).Get(node_ptr, !std::is_const::value)); } //! Replace the child at byte. - void ReplaceChild(const ART &art, const uint8_t byte, const NodePtr child = NodePtr()) const; + void ReplaceChild(const ART &art, const uint8_t byte, const NodePtr child_ptr = NodePtr()) const; //! Insert the child at byte. - static void InsertChild(ART &art, NodePtr &node, const uint8_t byte, const NodePtr child = NodePtr()); + static void InsertChild(ART &art, NodePtr &node_ptr, const uint8_t byte, const NodePtr child_ptr = NodePtr()); //! Delete the child at byte. - static void DeleteChild(ART &art, NodePtr &node, NodePtr &prefix, const uint8_t byte, const GateStatus status, - const ARTKey &row_id); + static void DeleteChild(ART &art, NodePtr &node_ptr, NodePtr &parent_ptr, const uint8_t byte, + const GateStatus status, const ARTKey &row_id); //! Get the child node at byte, if it exists. OptionalNodePtr GetChildNode(const ART &art, const uint8_t byte) const; @@ -171,7 +171,7 @@ class NodePtr : public IndexPointer { static NType GetInternalNodeType(const idx_t count); //! Transform the node storage to deprecated storage. - static void TransformToDeprecated(ART &art, NodePtr &node, TransformToDeprecatedState &state); + static void TransformToDeprecated(ART &art, NodePtr &node_ptr, TransformToDeprecatedState &state); //! Returns the string representation of the node at indentation level. //! @@ -244,22 +244,22 @@ struct NodeChildren { class OptionalNodePtr { public: OptionalNodePtr() = default; - OptionalNodePtr(const NodePtr node) : node(node) { // NOLINT: allow implicit conversion from NodePtr + OptionalNodePtr(const NodePtr node_ptr) : node_ptr(node_ptr) { // NOLINT: allow implicit conversion from NodePtr } //! Returns true if the OptionalNodePtr holds a valid NodePtr. explicit operator bool() const { - return node.HasMetadata(); + return node_ptr.HasMetadata(); } //! Returns the copied NodePtr. Must only be called if it is valid. NodePtr Get() const { - D_ASSERT(node.HasMetadata()); - return node; + D_ASSERT(node_ptr.HasMetadata()); + return node_ptr; } private: - NodePtr node; + NodePtr node_ptr; }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/execution/index/art/node256.hpp b/src/duckdb/src/include/duckdb/execution/index/art/node256.hpp index 639ad6726..3bf842d0a 100644 --- a/src/duckdb/src/include/duckdb/execution/index/art/node256.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/art/node256.hpp @@ -35,11 +35,11 @@ class Node256 { public: //! Get a new Node256 handle and initialize the Node256. - static NodeHandle New(ART &art, NodePtr &node) { - node = NodePtr::GetAllocator(art, NODE_256).New(); - node.SetMetadata(static_cast(NODE_256)); + static NodeHandle New(ART &art, NodePtr &node_ptr) { + node_ptr = NodePtr::GetAllocator(art, NODE_256).New(); + node_ptr.SetMetadata(static_cast(NODE_256)); - NodeHandle handle(art, node); + NodeHandle handle(art, node_ptr); auto &n = handle.Get(); // Reset the node (count and children). @@ -52,15 +52,15 @@ class Node256 { } //! Insert a child at byte. - static void InsertChild(ART &art, NodePtr &node, const uint8_t byte, const NodePtr child); + static void InsertChild(ART &art, NodePtr &node_ptr, const uint8_t byte, const NodePtr child_ptr); //! Delete the child at byte. - static void DeleteChild(ART &art, NodePtr &node, const uint8_t byte); + static void DeleteChild(ART &art, NodePtr &node_ptr, const uint8_t byte); //! Replace the child at byte. - void ReplaceChild(const uint8_t byte, const NodePtr child) { + void ReplaceChild(const uint8_t byte, const NodePtr child_ptr) { D_ASSERT(count > SHRINK_THRESHOLD); auto status = children[byte].GetGateStatus(); - children[byte] = child; - if (status == GateStatus::GATE_SET && child.HasMetadata()) { + children[byte] = child_ptr; + if (status == GateStatus::GATE_SET && child_ptr.HasMetadata()) { children[byte].SetGateStatus(status); } } @@ -139,6 +139,6 @@ class Node256 { } private: - static void GrowNode48(ART &art, NodePtr &node256, NodePtr &node48); + static void GrowNode48(ART &art, NodePtr &node256_ptr, NodePtr &node48_ptr); }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/execution/index/art/node256_leaf.hpp b/src/duckdb/src/include/duckdb/execution/index/art/node256_leaf.hpp index 469fc1591..4ac3e3e4f 100644 --- a/src/duckdb/src/include/duckdb/execution/index/art/node256_leaf.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/art/node256_leaf.hpp @@ -35,12 +35,12 @@ class Node256Leaf { public: //! Get a new Node256Leaf handle and initialize the leaf. - static NodeHandle New(ART &art, NodePtr &node); + static NodeHandle New(ART &art, NodePtr &node_ptr); //! Insert a byte. - static void InsertByte(ART &art, NodePtr &node, const uint8_t byte); + static void InsertByte(ART &art, NodePtr &node_ptr, const uint8_t byte); //! Delete a byte. - static void DeleteByte(ART &art, NodePtr &node, const uint8_t byte); + static void DeleteByte(ART &art, NodePtr &node_ptr, const uint8_t byte); //! Returns true, if the byte exists, else false. bool HasByte(const uint8_t byte) const; @@ -54,7 +54,7 @@ class Node256Leaf { bool GetNextByte(uint8_t &byte) const; private: - static void GrowNode15Leaf(ART &art, NodePtr &node256_leaf, NodePtr &node15_leaf); + static void GrowNode15Leaf(ART &art, NodePtr &node256_leaf_ptr, NodePtr &node15_leaf_ptr); }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/execution/index/art/node48.hpp b/src/duckdb/src/include/duckdb/execution/index/art/node48.hpp index 730a7f4e8..e60f5213c 100644 --- a/src/duckdb/src/include/duckdb/execution/index/art/node48.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/art/node48.hpp @@ -40,11 +40,11 @@ class Node48 { public: //! Get a new Node48 handle and initialize the Node48. - static NodeHandle New(ART &art, NodePtr &node) { - node = NodePtr::GetAllocator(art, NODE_48).New(); - node.SetMetadata(static_cast(NODE_48)); + static NodeHandle New(ART &art, NodePtr &node_ptr) { + node_ptr = NodePtr::GetAllocator(art, NODE_48).New(); + node_ptr.SetMetadata(static_cast(NODE_48)); - NodeHandle handle(art, node); + NodeHandle handle(art, node_ptr); auto &n = handle.Get(); // Reset the node (count and child_index). @@ -61,15 +61,15 @@ class Node48 { } //! Insert a child at byte. - static void InsertChild(ART &art, NodePtr &node, const uint8_t byte, const NodePtr child); + static void InsertChild(ART &art, NodePtr &node_ptr, const uint8_t byte, const NodePtr child_ptr); //! Delete the child at byte. - static void DeleteChild(ART &art, NodePtr &node, const uint8_t byte); + static void DeleteChild(ART &art, NodePtr &node_ptr, const uint8_t byte); //! Replace the child at byte. - void ReplaceChild(const uint8_t byte, const NodePtr child) { + void ReplaceChild(const uint8_t byte, const NodePtr child_ptr) { D_ASSERT(count >= SHRINK_THRESHOLD); auto status = children[child_index[byte]].GetGateStatus(); - children[child_index[byte]] = child; - if (status == GateStatus::GATE_SET && child.HasMetadata()) { + children[child_index[byte]] = child_ptr; + if (status == GateStatus::GATE_SET && child_ptr.HasMetadata()) { children[child_index[byte]].SetGateStatus(status); } } @@ -155,8 +155,8 @@ class Node48 { } private: - static void GrowNode16(ART &art, NodePtr &node48, NodePtr &node16); + static void GrowNode16(ART &art, NodePtr &node48_ptr, NodePtr &node16_ptr); //! We shrink at <= Node256::SHRINK_THRESHOLD. - static void ShrinkNode256(ART &art, NodePtr &node48, NodePtr &node256); + static void ShrinkNode256(ART &art, NodePtr &node48_ptr, NodePtr &node256_ptr); }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/execution/index/art/node_handle.hpp b/src/duckdb/src/include/duckdb/execution/index/art/node_handle.hpp index a6417cc97..50cc17942 100644 --- a/src/duckdb/src/include/duckdb/execution/index/art/node_handle.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/art/node_handle.hpp @@ -24,8 +24,8 @@ enum class NType : uint8_t; //! For read-only access, use ConstNodeHandle instead. class NodeHandle { public: - NodeHandle(ART &art, const NodePtr node); - NodeHandle(FixedSizeAllocator &allocator, const NodePtr node, NType type); + NodeHandle(ART &art, const NodePtr node_ptr); + NodeHandle(FixedSizeAllocator &allocator, const NodePtr node_ptr, NType type); NodeHandle(const NodeHandle &) = delete; NodeHandle &operator=(const NodeHandle &) = delete; @@ -57,7 +57,7 @@ class NodeHandle { //! For mutable access, use NodeHandle instead. class ConstNodeHandle { public: - ConstNodeHandle(const ART &art, const NodePtr node); + ConstNodeHandle(const ART &art, const NodePtr node_ptr); ConstNodeHandle(const ConstNodeHandle &) = delete; ConstNodeHandle &operator=(const ConstNodeHandle &) = delete; diff --git a/src/duckdb/src/include/duckdb/execution/index/art/prefix.hpp b/src/duckdb/src/include/duckdb/execution/index/art/prefix.hpp index 04431dc57..4789125b1 100644 --- a/src/duckdb/src/include/duckdb/execution/index/art/prefix.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/art/prefix.hpp @@ -30,52 +30,56 @@ class Prefix { public: Prefix() = delete; - Prefix(const ART &art, const NodePtr node, const bool is_mutable = false, const bool set_in_memory = false); - Prefix(FixedSizeAllocator &allocator, const NodePtr node, const idx_t count); + Prefix(const ART &art, const NodePtr node_ptr, const bool is_mutable = false, const bool set_in_memory = false); + Prefix(FixedSizeAllocator &allocator, const NodePtr node_ptr, const idx_t count); data_ptr_t data; NodePtr *child_slot; bool in_memory; public: - static uint8_t GetByte(const ART &art, const NodePtr &node, const uint8_t pos); + static uint8_t GetByte(const ART &art, const NodePtr &node_ptr, const uint8_t pos); public: //! Get a new list of prefix nodes. The node reference holds the child of the last prefix node. - static void New(ART &art, reference &node_ref, const ARTKey &key, const idx_t depth, idx_t count); + static void New(ART &art, reference &node_ptr_ref, const ARTKey &key, const idx_t depth, idx_t count); //! Concatenates parent -> prev_node4 -> child. - static void Concat(ART &art, NodePtr &parent, NodePtr &node4, const NodePtr child, uint8_t byte, + static void Concat(ART &art, NodePtr &parent_ptr, NodePtr &node4_ptr, const NodePtr child_ptr, uint8_t byte, const GateStatus node4_status, const GateStatus status); //! Removes up to pos bytes from the prefix. //! Shifts all subsequent bytes by pos. Frees empty nodes. - static void Reduce(ART &art, NodePtr &node, const idx_t pos); + static void Reduce(ART &art, NodePtr &node_ptr, const idx_t pos); private: - static Prefix NewInternal(ART &art, NodePtr &node, const data_ptr_t data, const uint8_t count, const idx_t offset); + static Prefix NewInternal(ART &art, NodePtr &node_ptr, const data_ptr_t data, const uint8_t count, + const idx_t offset); - static Prefix GetTail(ART &art, const NodePtr &node); + static Prefix GetTail(ART &art, const NodePtr &node_ptr); - static void ConcatInternal(ART &art, NodePtr &parent, NodePtr &node4, const NodePtr child, uint8_t byte, + static void ConcatInternal(ART &art, NodePtr &parent_ptr, NodePtr &node4_ptr, const NodePtr child_ptr, uint8_t byte, const GateStatus status); - static void ConcatNode4WasGate(ART &art, NodePtr &node4, const NodePtr child, uint8_t byte); - static void ConcatChildIsGate(ART &art, NodePtr &parent, NodePtr &node4, const NodePtr child, uint8_t byte); - static void ConcatOutsideGate(ART &art, NodePtr &parent, NodePtr &node4, const NodePtr child, uint8_t byte); + static void ConcatNode4WasGate(ART &art, NodePtr &node4_ptr, const NodePtr child_ptr, uint8_t byte); + static void ConcatChildIsGate(ART &art, NodePtr &parent_ptr, NodePtr &node4_ptr, const NodePtr child_ptr, + uint8_t byte); + static void ConcatOutsideGate(ART &art, NodePtr &parent_ptr, NodePtr &node4_ptr, const NodePtr child_ptr, + uint8_t byte); Prefix Append(ART &art, const uint8_t byte); - void Append(ART &art, NodePtr other); + void Append(ART &art, NodePtr other_ptr); Prefix TransformToDeprecatedAppend(ART &art, FixedSizeAllocator &allocator, uint8_t byte); private: template - static void Iterator(ART &art, reference &node_ref, const bool exit_gate, const bool is_mutable, F &&lambda) { - while (node_ref.get().HasMetadata() && node_ref.get().GetType() == PREFIX) { - Prefix prefix(art, node_ref, is_mutable); + static void Iterator(ART &art, reference &node_ptr_ref, const bool exit_gate, const bool is_mutable, + F &&lambda) { + while (node_ptr_ref.get().HasMetadata() && node_ptr_ref.get().GetType() == PREFIX) { + Prefix prefix(art, node_ptr_ref, is_mutable); lambda(prefix); - node_ref = *prefix.child_slot; - if (exit_gate && node_ref.get().GetGateStatus() == GateStatus::GATE_SET) { + node_ptr_ref = *prefix.child_slot; + if (exit_gate && node_ptr_ref.get().GetGateStatus() == GateStatus::GATE_SET) { break; } } diff --git a/src/duckdb/src/include/duckdb/execution/index/art/prefix_handle.hpp b/src/duckdb/src/include/duckdb/execution/index/art/prefix_handle.hpp index ce3f810e0..f002ec911 100644 --- a/src/duckdb/src/include/duckdb/execution/index/art/prefix_handle.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/art/prefix_handle.hpp @@ -38,16 +38,16 @@ class PrefixHandle { //! Create a non-empty prefix chain and return its root pointer and pinned final child location. static PrefixChain New(ART &art, const ARTKey &key, const idx_t depth, const idx_t count); - //! Splits the prefix at pos. branching_node4 must identify an already allocated, ungated node. - //! If pos > 0, prefix_ptr retains the bytes before pos and points to branching_node4; its gate status is unchanged. - //! If pos == 0, the prefix is freed and prefix_ptr is set to branching_node4, which inherits the prefix's gate + //! Splits the prefix at pos. branching_node4_ptr must identify an already allocated, ungated node. + //! If pos > 0, prefix_ptr keeps the bytes before pos and points to branching_node4_ptr; its gate is unchanged. + //! If pos == 0, the prefix is freed and prefix_ptr is set to branching_node4_ptr, which inherits the prefix's gate //! status. Returns the child containing the remaining bytes and subtree after the split byte. The caller must save - //! the split byte before calling and attach the returned child to branching_node4 under that byte. Gate status is - //! handled internally; the caller does not need to set it after splitting. - static NodePtr Split(ART &art, NodePtr &prefix_ptr, NodePtr &branching_node4, const uint8_t pos); + //! the split byte before calling and attach the returned child to branching_node4_ptr under that byte. Gate status + //! is handled internally; the caller does not need to set it after splitting. + static NodePtr Split(ART &art, NodePtr &prefix_ptr, NodePtr &branching_node4_ptr, const uint8_t pos); //! Create a new deprecated prefix node and return a handle to it. - static NodeHandle NewDeprecated(FixedSizeAllocator &allocator, NodePtr &node); + static NodeHandle NewDeprecated(FixedSizeAllocator &allocator, NodePtr &node_ptr); public: data_ptr_t Data() { @@ -94,13 +94,13 @@ class PrefixHandle { //! Returns an empty OptionalNodePtr if the prefix was not loaded from storage (early out) or if the endpoint //! was a gated node (handled internally). Otherwise, returns a copy of the child pointer at the tail of //! the prefix chain for further traversal. - static OptionalNodePtr TransformToDeprecated(ART &art, NodePtr &node, TransformToDeprecatedState &state); + static OptionalNodePtr TransformToDeprecated(ART &art, NodePtr &node_ptr, TransformToDeprecatedState &state); private: - static PrefixHandle NewInternal(ART &art, NodePtr &node, const_data_ptr_t data, const uint8_t count, + static PrefixHandle NewInternal(ART &art, NodePtr &node_ptr, const_data_ptr_t data, const uint8_t count, const idx_t offset); static PrefixHandle AppendByte(ART &art, PrefixHandle prefix, const uint8_t byte); - static void Append(ART &art, PrefixHandle prefix, NodePtr other); + static void Append(ART &art, PrefixHandle prefix, NodePtr other_ptr); static NodeHandle TransformToDeprecatedAppend(NodeHandle tail_handle, ART &art, FixedSizeAllocator &allocator, const uint8_t byte); @@ -112,7 +112,7 @@ class PrefixHandle { //! A newly allocated prefix chain with a pinned final child location. struct PrefixChain { //! Pointer value identifying the first prefix. - NodePtr root; + NodePtr root_ptr; //! Pins the final prefix containing the child pointer to fill. PrefixHandle tail; };