Always unlink first segment for AO/AOCO temp relation.#1656
Open
Always unlink first segment for AO/AOCO temp relation.#1656
Conversation
my-ship-it
reviewed
Apr 1, 2026
| */ | ||
| if (RelFileNodeBackendIsTemp(rnode)) | ||
| { | ||
| /* Next unlink the file, unless it was already found to be missing */ |
Contributor
There was a problem hiding this comment.
Thanks for catching this!
Minor comments below:
int ret; is declared at function scope.
Better to be scoped inside the if block, or removed entirely since it's only checked against < 0 immediately.
| (errcode_for_file_access(), | ||
| errmsg("could not remove file \"%s\": %m", path))); | ||
| } | ||
|
|
Contributor
There was a problem hiding this comment.
Should also unlink the segment files beyond segment 0?
How about modifying mdunlink_ao_base_relfile() and mdunlink_ao_perFile() to check RelFileNodeBackendIsTemp(rnode) and unlink immediately (mirroring the heap mdunlinkfork pattern), rather than appending a separate unlink at the end of mdunlink_ao?
Something like
if (!unlinkFiles->isRedo)
{
if (RelFileNodeBackendIsTemp(unlinkFiles->rnode))
{
ret = unlink(baserel);
if (ret < 0 && errno != ENOENT)
ereport(WARNING, ...);
}
else
{
// Existing truncate + deferred unlink logic
...
}
}
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.
Usually relfiles from deleted relation persist until next CHECKPOINT, and unlinked only then. For temporary relation. this is not the case, and this is explicitly handled in
mdunlinkforkhttps://github.com/postgres/postgres/blob/868825a/src/backend/storage/smgr/md.c#L384-L385
With GPDB 6 -> 7 refactorings we ended up using separate unlink functions for relation obsoletion. In gpdb 6 we used to call
mdunlink_aofrommdunlinkforkwhile in gpdb 7 we are not. This leads to orphan files after temporal relation drop like in scenario:Fix this by importing logic from
mdunlinkfork#1644