Re: BUG #18492: Adding a toasted column to a table with an inherited temp table fails with Assert

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: exclusion(at)gmail(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18492: Adding a toasted column to a table with an inherited temp table fails with Assert
Date: 2024-06-03 17:50:22
Message-ID: 78902.1717437022@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> The following script:
> echo "CREATE TABLE t (a int);" | psql

> echo "
> CREATE TEMP TABLE tt() INHERITS (t);
> select pg_sleep(1);
> " | psql &

> echo "
> select pg_sleep(0.1);
> ALTER TABLE t ADD COLUMN b text;
> " | psql

> triggers an assertion failure with the following stack trace:
> TRAP: failed Assert("isTempOrTempToastNamespace(relnamespace)"), File:
> "relcache.c", Line: 3619, PID: 1339672

I'm inclined to think that we should reject any ALTER TABLE on another
session's temp table. It could theoretically work in cases that don't
require touching the temp table's contents, but it has to fail in all
cases that do require that, and I don't really want that distinction
to be semantically visible. It's too implementation-dependent and
would be likely to act differently in different PG versions.

This example shows that the prohibition would also have to include
failing if an ALTER recurses to a child table that is another
session's temp table; but the same error occurs if you just try to
modify the other temp table directly. I did

Session 1:
regression=# create temp table mytemptable(f1 int);
CREATE TABLE

Session 2:
regression=# \d *.mytemptable
Table "pg_temp_60.mytemptable"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
f1 | integer | | |

regression=# alter table pg_temp_60.mytemptable add column f2 int;
ALTER TABLE
regression=# alter table pg_temp_60.mytemptable add column f3 text;
server closed the connection unexpectedly

Even though the "add column f2 int" step went through, I think it's
too scary to allow that. I think we have, or might have in future,
optimizations that assume that a session's temp tables aren't modified
by other sessions.

(Note that this would have failed anyway if I weren't doing it as
superuser, because I wouldn't have had lookup permission in
pg_temp_60.)

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Alejandro Burne 2024-06-03 18:11:06 Visibility of a local variable
Previous Message Erik Wienhold 2024-06-03 16:45:54 Re: Missing semicolumn in anonymous plpgsql block does not raise syntax error