On Tue, 14 Jul 2026 at 20:38, Zsolt Parragi <[email protected]> wrote:
>
> 1. The following crashes the server:
>
> CREATE GLOBAL TEMP SEQUENCE slv;
> -- new session
> BEGIN;
> SELECT nextval('slv');
> ROLLBACK;
> SELECT lastval();

Ah, OK. I'll take a look. This is possibly related to the next point.

> 2. And I also have some other questions above global temp sequences:
>
> CREATE GLOBAL TEMP SEQUENCE s;
> CREATE GLOBAL TEMP TABLE t (a int, b serial);
>
> BEGIN;
> SELECT nextval('s');   -- 1
> SELECT nextval('s');   -- 2
> SELECT nextval('s');   -- 3
> ROLLBACK;
> SELECT nextval('s'); -- 1 again, is this intended?

No, I don't think that's right.

I noticed this myself, when looking at Andrew's patch, which creates
storage for sequences non-transactionally, so that it isn't rolled
back. I think that's probably the right thing to do, for consistency
with regular sequences.

> 3. What should happen with a subscription into a temporary table?
> Currently it silently discard the data.

Good point. I think publications should not allow global temporary
tables (just like unlogged tables).

> 6. I can create a permanent materialized view over a global temporary
> table, is this intended?

Yes, I noticed that was another difference between my patch and Andrew's.

I don't think that there is any issue with allowing a materialized
view over a global temporary table though. I think there are probably
valid use cases where you might use that -- e.g., a nightly cron job
runs a process, collecting summary data in a global temporary table,
then publishes a summary of the results via a materialized view,
before exiting and throwing away the temporary data. I don't think we
should disallow such use cases.

> 11. How should GTTs interact with DISCARD?

I had started looking at that. My plan is to add a "DISCARD GLOBAL
TEMP", so that  it can operate independently of "DISCARD TEMP". I plan
to make it delete all storage and  usage associated with global
temporary relations, so that autovacuum can advance datfrozenxid. One
consequence of that is that it will also reset global temporary
sequences back to their initial values, but I think that should be OK
as long as it's documented.

I'll put the patch back to WoA, until I've had a chance to look at these issues.

Regards,
Dean


Reply via email to