Re: Global temporary tables

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: John Naylor <johncnaylorls(at)gmail(dot)com>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Global temporary tables
Date: 2026-07-07 22:37:11
Message-ID: CAEZATCVjaZFa80S-V_+nvnzRK1ZiLUPx8jwdyAtRVHAmPZQQMg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, 7 Jul 2026 at 10:06, John Naylor <johncnaylorls(at)gmail(dot)com> wrote:
>
> Okay, I followed up with various attempts to get the new sub XID
> tracking to do something dire, and couldn't find anything.
>

Unfortunately, it still wasn't working properly. In a fresh session,
doing VACUUM FREEZE on a GTT with ON COMMIT DELETE ROWS would fail
because the VACUUM FREEZE would update a new pg_temp_class tuple,
flushing it to the database, and then the ON COMMIT code would fail to
find it, because there was no intervening CommandCounterIncrement() to
make it visible.

I don't want to go round adding CommandCounterIncrement()'s to fix
things like this -- part of the reason for having the pending inserts
was to make that unnecessary. So instead, in v8, I have made it so
that the pending insert entries are kept up-to-date all the way to the
end of the transaction, even if they're flushed to the database before
that. This turns out to make the code far simpler, and easier to
reason about, as well as hopefully being more robust. So I feel much
better about this formulation of pending inserts.

> I did find something else, however:
>
> set statement_timeout = '3s';
> set debug_discard_caches = 1;
>
> create global temporary table g (a int);
>
> This enters an infinite loop
>

Doh! Fixed in v8.

Regards,
Dean

Attachment Content-Type Size
v8-0001-Save-temporary-table-ON-COMMIT-actions-to-pg_clas.patch text/x-patch 12.8 KB
v8-0002-Basic-support-for-global-temporary-tables.patch text/x-patch 141.8 KB
v8-0003-Support-indexes-on-global-temporary-tables.patch text/x-patch 36.2 KB
v8-0004-Support-global-temporary-sequences.patch text/x-patch 17.6 KB
v8-0005-Support-global-temporary-catalog-tables-and-add-p.patch text/x-patch 91.2 KB
v8-0006-Add-relation-statistics-columns-to-pg_temp_class.patch text/x-patch 53.0 KB
v8-0007-Add-relfrozenxid-and-relminmxid-columns-to-pg_tem.patch text/x-patch 55.8 KB
v8-0008-Add-pg_temp_statistic-global-temporary-catalog-ta.patch text/x-patch 32.7 KB
v8-0009-Add-pg_temp_statistic_ext_data-global-temporary-c.patch text/x-patch 36.7 KB
v8-0010-Add-pg_temp_index-global-temporary-catalog-table.patch text/x-patch 69.1 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jelte Fennema-Nio 2026-07-07 22:46:53 Re: WAL compression setting after PostgreSQL LZ4 default change
Previous Message Tomas Vondra 2026-07-07 22:36:18 Re: allow spread checkpoints when changing checksums online