fix: merge strategy is memory intensive#9054
Merged
Conversation
begelundmuller
approved these changes
Mar 16, 2026
begelundmuller
requested changes
Mar 16, 2026
runtime/drivers/duckdb/crud.go
Outdated
| // Create a temporary table with the new data | ||
| tmp := uuid.New().String() | ||
| _, err := conn.ExecContext(ctx, fmt.Sprintf("CREATE TEMPORARY TABLE %s AS (%s\n)", safeSQLName(tmp), sql)) | ||
| _, err := conn.ExecContext(ctx, fmt.Sprintf("CREATE TABLE %s AS (%s\n)", safeSQLName(tmp), sql)) |
Contributor
There was a problem hiding this comment.
Can you see a way this can be done with a stable random name rather than a new UUID every time?
There are various error cases where we can't rely on automatic clean up (e.g. OOM or SIGKILL). Generally when using non-temporary resources, we try to use stable names and CREATE OR REPLACE to keep things idempotent and ensure eventual cleanup in later retries (or at least bounded growth of temporary data).
runtime/drivers/duckdb/crud.go
Outdated
Comment on lines
+201
to
+202
| tmp := uuid.New().String() | ||
| _, err := conn.ExecContext(ctx, fmt.Sprintf("CREATE TEMPORARY TABLE %s AS (%s\n)", safeSQLName(tmp), sql)) | ||
| _, err := conn.ExecContext(ctx, fmt.Sprintf("CREATE TABLE %s AS (%s\n)", safeSQLName(tmp), sql)) |
begelundmuller
approved these changes
Mar 16, 2026
k-anshul
added a commit
that referenced
this pull request
Mar 16, 2026
* fix: merge strategy is compute intensive * tables need drop now * use gracful ctx * review comments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes https://linear.app/rilldata/issue/PLAT-437/improve-oomes-in-duckdb-when-ingesting-partitions-with-merge-strategy
deleteandinsertstatements executed in merge are probably not intensive. I tried by copying a big table and doing delete followed by insert. Both executed pretty fast, did not generate any tmp files ifpreserve_insertion_orderis false.Checklist: