Skip to content

[Indexes] Buffer Managed Indexes Part 4: Segment Handles for Base Leaf#19303

Merged
Mytherin merged 2 commits intoduckdb:mainfrom
artjomPlaunov:segment-handles-base-leaf
Oct 13, 2025
Merged

[Indexes] Buffer Managed Indexes Part 4: Segment Handles for Base Leaf#19303
Mytherin merged 2 commits intoduckdb:mainfrom
artjomPlaunov:segment-handles-base-leaf

Conversation

@artjomPlaunov
Copy link
Contributor

@Mytherin Mytherin requested a review from taniabogatsch October 8, 2025 14:11
Copy link
Contributor

@taniabogatsch taniabogatsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @artjomPlaunov, thanks for picking up the work on the buffer-managed indexes! The PR looks good, the only thing I've commented on is the scoping of the node handles. If I saw correctly, most of the Insert-and Delete-functions still need that. Then it should be good to go!

Comment on lines 59 to 66
NodeHandle<Node7Leaf> handle(art, node);
auto &n7 = handle.Get();
if (n7.count == CAPACITY) {
auto node7 = node;
Node15Leaf::GrowNode7Leaf(art, node, node7);
Node15Leaf::InsertByte(art, node, byte);
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We likely need to change the logic here slightly, similar to what the BaseNode does (via n7.count != CAPACITY). If we look at BaseNode::InsertChild, the scope of the NodeHandle ends before growing the node. That way, we don't hold on to a node whose memory changes while growing.

{
		NodeHandle<Node4> handle(art, node);
		auto &n = handle.Get();

		if (n.count != CAPACITY) {
			InsertChildInternal(n, byte, child);
			return;
		}
	}
	// The node is full.
	// Grow to Node16.
	auto node4 = node;
	Node16::GrowNode4(art, node, node4);
	Node16::InsertChild(art, node, byte, child);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for catching that, I will add the changes.

Comment on lines +71 to +72
auto n7_handle = DeleteByteInternal(art, node, byte);
auto &n7 = n7_handle.Get();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, we need to scope the NodeHandle here, to avoid holding on to memory that is being compressed as part of the one-way node compression. For reference, see Node4::DeleteChild.

n7.key[i] = n15.key[i];
}

Node::FreeNode(art, node15_leaf);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think freeing will try to grab the same node handle, so we should also add scope here. I.e., we destroy the handle before we destroy the node memory. See Node4::ShrinkNode16.

@artjomPlaunov artjomPlaunov force-pushed the segment-handles-base-leaf branch from faf56e9 to d88a594 Compare October 9, 2025 09:21
@artjomPlaunov artjomPlaunov marked this pull request as draft October 9, 2025 09:30
Copy link
Contributor

@taniabogatsch taniabogatsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now, thanks!!

@artjomPlaunov artjomPlaunov marked this pull request as ready for review October 9, 2025 14:56
@artjomPlaunov artjomPlaunov force-pushed the segment-handles-base-leaf branch from d88a594 to 7d59af0 Compare October 10, 2025 09:11
@artjomPlaunov artjomPlaunov marked this pull request as draft October 10, 2025 09:30
@artjomPlaunov artjomPlaunov marked this pull request as ready for review October 10, 2025 10:37
@artjomPlaunov artjomPlaunov force-pushed the segment-handles-base-leaf branch from 7d59af0 to a44547d Compare October 10, 2025 11:26
@duckdb-draftbot duckdb-draftbot marked this pull request as draft October 10, 2025 11:36
@Mytherin Mytherin marked this pull request as ready for review October 10, 2025 11:37
@Mytherin Mytherin merged commit f7945f6 into duckdb:main Oct 13, 2025
94 of 98 checks passed
@Mytherin
Copy link
Collaborator

Thanks!

krlmlr added a commit to krlmlr/duckdb-r that referenced this pull request Nov 2, 2025
[Indexes] Buffer Managed Indexes Part 4: Segment Handles for Base Leaf (duckdb/duckdb#19303)
Internal duckdb/duckdb#6190: AsOf Threading (duckdb/duckdb#19328)
krlmlr added a commit to krlmlr/duckdb-r that referenced this pull request Nov 2, 2025
[Indexes] Buffer Managed Indexes Part 4: Segment Handles for Base Leaf (duckdb/duckdb#19303)
Internal duckdb/duckdb#6190: AsOf Threading (duckdb/duckdb#19328)
@artjomPlaunov artjomPlaunov deleted the segment-handles-base-leaf branch December 30, 2025 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants