Skip to content

Free temporary rowid Datums after index and trigger use#69

Open
GremSnoort wants to merge 1 commit into
patches17from
fix-rowid-portalcontext-memory-17
Open

Free temporary rowid Datums after index and trigger use#69
GremSnoort wants to merge 1 commit into
patches17from
fix-rowid-portalcontext-memory-17

Conversation

@GremSnoort

Copy link
Copy Markdown
Contributor

Summary

This patch reduces PortalContext memory growth for ROW_REF_ROWID table AMs during long statements such as large COPY FROM.

For ROW_REF_ROWID relations, slot_getsysattr(RowIdAttributeNumber) returns a caller-owned palloc copy 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 until PortalContext reset.

This patch explicitly frees those temporary rowid Datums after index/trigger use.

Reason

Large TPC-C COPY FROM loads with OrioleDB accumulated per-row temporary rowid copies in PortalContext. This produced unnecessary private backend memory growth during long COPY statements.

After this change, PortalContext stays small during the same load path.

Notes

The change relies on the ROW_REF_ROWID ownership contract: slot_getsysattr(RowIdAttributeNumber) must return a caller-owned palloc Datum. 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=1000
  • load_workers=16
  • FK constraints moved after load to isolate COPY memory behavior
  • PortalContext stayed small
  • AfterTriggerEvents did not accumulate during COPY
  • load, add constraints, and population validation completed successfully

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.
#include "utils/snapmgr.h"

static inline bool
ExecIndexTupleIdNeedsFree(Relation heapRelation)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any reason not to inline one-line function?

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