Skip to content

Fix local temporary tables leaking temp pages on DROP and ROLLBACK - #9382

Open
dyemanov wants to merge 1 commit into
masterfrom
work/ltt-page-cleanup
Open

dyemanov wants to merge 1 commit into
masterfrom
work/ltt-page-cleanup

Conversation

@dyemanov

Copy link
Copy Markdown
Member

Pages allocated by a CREATE LOCAL TEMPORARY TABLE in the attachment's temporary page space are now released when the LTT is finalized — dropped and committed, cancelled out by CREATE + DROP in one transaction, or rolled back. Previously those pages (and the relation object itself) stayed allocated until the connection was closed.

User-visible cases

  • CREATE LOCAL TEMPORARY TABLE + rows + DROP + COMMIT
  • CREATE + DROP in the same transaction
  • CREATE + rows + ROLLBACK
  • CREATE + rows + ALTER + ROLLBACK

Measured effect

Single connection, 50 iterations of create / insert 1000 rows / drop + commit, plus the create+drop and rollback variants, watching the live temp page-space file of that attachment:

  • without the fix: 262144 → 1048576 bytes (grows by 16 Kb per LTT, never shrinks)
  • with the fix: flat at 262144 bytes

Dropping an LTT (committed), creating and dropping it in one transaction,
or rolling back its CREATE left the relation's pages allocated in the
temporary page space for the rest of the connection: the per-instance
pages, the base pages created at CREATE time (pointer page + index root),
the recycled page-set containers and the Cached::Relation object were
never released, so the per-attachment temp file grew monotonically.

Add RelationPermanent::cleanupPages() to tear down a relation's temporary
pages: free the per-instance page sets and release the base index and pages
via DPM_delete_relation_pages(). Route all three finalization paths through
a single file-local cleanupLttInstance() helper in Savepoint.cpp that
calls cleanupPages() and cleans up the Cached::Relation. The dead
dfw_delete_relation deferred work in DropRelationNode::execute is
removed: the commit-time relation-id lookup can never resolve a
just-dropped LTT, so it never ran.
@dyemanov dyemanov self-assigned this Nov 30, 2026
@dyemanov
dyemanov requested a review from asfernandes November 30, 2026 11:15
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.

1 participant