Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iQvtB-0001EB-3F for pgsql-bugs@arkaria.postgresql.org; Sat, 02 Nov 2019 16:04:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iQvt8-00051e-Uc for pgsql-bugs@arkaria.postgresql.org; Sat, 02 Nov 2019 16:04:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iQvt8-0004zz-LE for pgsql-bugs@lists.postgresql.org; Sat, 02 Nov 2019 16:04:30 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iQvt1-0005ys-Ij for pgsql-bugs@lists.postgresql.org; Sat, 02 Nov 2019 16:04:30 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id xA2G4J5c031329; Sat, 2 Nov 2019 12:04:19 -0400 From: Tom Lane To: Manuel Rigger cc: PostgreSQL mailing lists Subject: Re: ALTER TABLE results in "ERROR: could not open relation with OID 43707388" In-reply-to: <28152.1562692038@sss.pgh.pa.us> References: <28152.1562692038@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Tue, 09 Jul 2019 13:07:18 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <31327.1572710659.1@sss.pgh.pa.us> Date: Sat, 02 Nov 2019 12:04:19 -0400 Message-ID: <31328.1572710659@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I wrote: > Manuel Rigger writes: >> CREATE TABLE t0(c0 INT); >> CREATE UNIQUE INDEX i0 ON t0(c0); >> ALTER TABLE t0 ADD PRIMARY KEY USING INDEX i0, ALTER c0 TYPE BIGINT; >> -- unexpected: ERROR: could not open relation with OID 43707388 > The sequence of events here is that: > 1. transformIndexConstraint looks up the index "i0" and saves its OID > in the IndexStmt's indexOid field. > 2. ALTER c0 TYPE BIGINT executes first, because of ALTER TABLE's > pass design. It rebuilds the i0 index --- with a new OID. > 3. ATExecAddIndexConstraint tries to look up i0 using the old OID. > Kaboom. FYI, the patch I posted at https://www.postgresql.org/message-id/24573.1572647175%40sss.pgh.pa.us fixes this (as well as your other similar complaint). I forgot to add a regression test matching this case, but will do so later. regards, tom lane