Free temporary rowid Datums after index and trigger use#69
Open
GremSnoort wants to merge 1 commit into
Open
Conversation
slot_getsysattr(RowIdAttributeNumber) returns caller-owned palloc'd rowid Datums for ROW_REF_ROWID table AMs. Index insertion/update/delete and after-trigger event queuing copy or consume the rowid before returning, so the temporary caller-owned copy does not need to live until PortalContext reset. Free those temporary rowid Datums after use to avoid accumulating per-row rowid copies during long COPY statements.
pashkinelfe
reviewed
Jun 23, 2026
| #include "utils/snapmgr.h" | ||
|
|
||
| static inline bool | ||
| ExecIndexTupleIdNeedsFree(Relation heapRelation) |
Contributor
There was a problem hiding this comment.
Any reason not to inline one-line function?
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.
Summary
This patch reduces
PortalContextmemory growth forROW_REF_ROWIDtable AMs during long statements such as largeCOPY FROM.For
ROW_REF_ROWIDrelations,slot_getsysattr(RowIdAttributeNumber)returns a caller-ownedpalloccopy of the rowid. The index insertion/update/delete paths and after-trigger event queue either consume the rowid immediately or copy it into their own long-lived storage. The temporary caller-owned copy therefore does not need to live untilPortalContextreset.This patch explicitly frees those temporary rowid Datums after index/trigger use.
Reason
Large TPC-C
COPY FROMloads with OrioleDB accumulated per-row temporary rowid copies inPortalContext. This produced unnecessary private backend memory growth during long COPY statements.After this change,
PortalContextstays small during the same load path.Notes
The change relies on the
ROW_REF_ROWIDownership contract:slot_getsysattr(RowIdAttributeNumber)must return a caller-ownedpallocDatum. This is documented near the helper that decides whether the tuple id should be freed.Testing
Validated with Stroppy TPC-C load on OrioleDB:
scale_factor=1000load_workers=16PortalContextstayed smallAfterTriggerEventsdid not accumulate during COPY