Skip to content

ScheduledMerges: migrate union level early (as soon as merging tree is completed)#824

Draft
mheinzel wants to merge 6 commits intomheinzel/prototype-empty-levelsfrom
mheinzel/prototype-migrate-union-level-early
Draft

ScheduledMerges: migrate union level early (as soon as merging tree is completed)#824
mheinzel wants to merge 6 commits intomheinzel/prototype-empty-levelsfrom
mheinzel/prototype-migrate-union-level-early

Conversation

@mheinzel
Copy link
Collaborator

@mheinzel mheinzel commented Mar 4, 2026

Builds on top of #823, as the migration relies on being able to create empty levels.

When creating the union of multiple tables, we create a special union level containing a merging tree. Once the tree has been completed, i.e. merged into a single run, we want to get rid of the union level by migrating the run to the regular levels. The main motivation is that we want it to become part of a last level merge, so compaction can occur. Last level merges are especially useful for compaction, since they can drop all delete entries.

This PR demonstrates one of two approaches for migration (#822 being the other one). As soon as the merging tree gets completed through supplyUnionCredits, we migrate it to a new last regular level. Sometimes it would not fit directly after the existing levels, in which case we can insert a few empty levels.

An interesting case to consider it that a union can get completed by an operation on another table that contains a shared reference to the merging tree. Therefore, at the beginning of any operation, a completed but not yet migrated union might be present. To ensure unions can become part of merges as soon as possible, we also check for possible migrations when flushing the write buffer. It might be beneficial to do the same when doing lookups.

I still plan to add some tracing once we decided which approach for migrating the union we want to take.

@jorisdral
Copy link
Collaborator

Over other channels we agreed we would try the migrate-early approach in this PR, rather than the migrate-late approach from #822

@mheinzel mheinzel force-pushed the mheinzel/prototype-empty-levels branch from f90b172 to 2591aff Compare March 23, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants