Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sEBpD-0008Sq-NH for pgsql-bugs@arkaria.postgresql.org; Mon, 03 Jun 2024 17:50:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sEBpD-00BuPE-D7 for pgsql-bugs@arkaria.postgresql.org; Mon, 03 Jun 2024 17:50:27 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sEBpD-00BuP6-4J for pgsql-bugs@lists.postgresql.org; Mon, 03 Jun 2024 17:50:27 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sEBpA-003HYp-LJ for pgsql-bugs@lists.postgresql.org; Mon, 03 Jun 2024 17:50:25 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 453HoMsH078903; Mon, 3 Jun 2024 13:50:22 -0400 From: Tom Lane To: exclusion@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18492: Adding a toasted column to a table with an inherited temp table fails with Assert In-reply-to: <18492-c7a2634bf4968763@postgresql.org> References: <18492-c7a2634bf4968763@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Mon, 03 Jun 2024 07:00:01 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <78901.1717437022.1@sss.pgh.pa.us> Date: Mon, 03 Jun 2024 13:50:22 -0400 Message-ID: <78902.1717437022@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form 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