Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ls5JT-0008DG-RG for pgsql-hackers@arkaria.postgresql.org; Sat, 12 Jun 2021 15:12:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ls5JS-0003Sp-0B for pgsql-hackers@arkaria.postgresql.org; Sat, 12 Jun 2021 15:12:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ls5JR-0003Ro-K2 for pgsql-hackers@lists.postgresql.org; Sat, 12 Jun 2021 15:12:41 +0000 Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ls5JO-0002f8-C5 for pgsql-hackers@lists.postgresql.org; Sat, 12 Jun 2021 15:12:41 +0000 Received: by mail-io1-xd31.google.com with SMTP id q7so34840051iob.4 for ; Sat, 12 Jun 2021 08:12:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=VSqojgNjPf7BqQNwTJUSs37X3eeINY+DHcfHMbV7rZo=; b=iETR+2GEoAr2/VmarRt14WxT1Fkb51qfb7/+7bX+EqfHXXnG5YhBWwctq2C6kVDS/d X1aPr3fi6zf7qKCn+rGRh4UE4UTisyfo0Oduvo8IrzE8mkt1S7H5EsZVg/UFA5H+7klt mN6HljITxkcHI3QK/nUY/t+LSC7sYmcNAqzj2ZHsXrKzHkSD6ET4vcLuSRnXduSXPpXc jlYR8Qz67RGP1MwSjzZc8K2CLErJunxC/XEqCK15kfFjcTlkpkyCM1EPwgnkwOaJalg7 xbRRYbL/fcQcp65TkpSsuJiAPJCvEE3zprNO6UQi5V/u9Zs2Wcs0FPtHyKL6od86+fiS sckQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=VSqojgNjPf7BqQNwTJUSs37X3eeINY+DHcfHMbV7rZo=; b=dIicvxS6FF4txTlfBUu8XyIyGFn/E/a942vhlAI7KDJc6vF1yHoUdjj0NGpvwF8nnC hxxV+/YuDCWbwGkUel4ow4cVK5gHgu2n/vmODkJw8tya/VOEysMoFDwHdbo3lPmqzUb5 sZM1BRVgyQi+9JLGo6lzEaBWmbUucf6LsU7ZQPzqx8ANsv0/kQrGC3JO0COgXfBK7VgI cPSu1RjtSOSFDOxvXzJTMOA1LIlNeWgGz0IbewP8R4S2QGROF1XhvQG720+gn4VjYEV5 7U8XCMj6FotMinFMgX8EQ/YTKk5LynKnMDjrZtXTbp6f9xkJIPFVFo+TfKvaqmPx7Soz 2zFA== X-Gm-Message-State: AOAM533D4+DPiCdO6Lho9RFlmYRj2Iw6JwOGwVoDr1lqrWPEGgyqcxN+ 8HDaTh3SRTP03ldeWUGWm6Az9pWQmVmTrg== X-Google-Smtp-Source: ABdhPJzh73T9TaQUCiU+/s1fYWDKoIMMfhRk3ooEWRhMgJDhPooIizeM6tYNXsOV9LCBb3mAjNOdJg== X-Received: by 2002:a5d:9059:: with SMTP id v25mr7371477ioq.113.1623510756508; Sat, 12 Jun 2021 08:12:36 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id d6sm4876565ils.88.2021.06.12.08.12.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 12 Jun 2021 08:12:35 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id C55C0800B38; Sat, 12 Jun 2021 10:12:34 -0500 (CDT) Date: Sat, 12 Jun 2021 10:12:34 -0500 From: Justin Pryzby To: Tom Lane Cc: pgsql-hackers@lists.postgresql.org Subject: Re: pg_filenode_relation(0,0) elog Message-ID: <20210612151234.GW16435@telsasoft.com> References: <20210612023324.GT16435@telsasoft.com> <2146777.1623469895@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2146777.1623469895@sss.pgh.pa.us> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Jun 11, 2021 at 11:51:35PM -0400, Tom Lane wrote: > Justin Pryzby writes: > > Per sqlsmith. > > postgres=# SELECT pg_filenode_relation(0,0); > > ERROR: unexpected duplicate for tablespace 0, relfilenode 0 > > Ugh. > > > The usual expectation is that sql callable functions should return null rather > > than hitting elog(). > > Agreed, but you should put the short-circuit into the SQL-callable > function, ie pg_filenode_relation. Lower-level callers ought not be > passing junk data. Right. I spent inadequate time reading output of git grep. > Likely it should check the reltablespace, too. I don't think so. The docs say: https://www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-ADMIN-DBLOCATION |For a relation in the database's default tablespace, the tablespace can be specified as zero. Also, that would breaks expected/alter_table.out for the same reason. diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c index 3c70bb5943..144aca1099 100644 --- a/src/backend/utils/adt/dbsize.c +++ b/src/backend/utils/adt/dbsize.c @@ -905,6 +905,9 @@ pg_filenode_relation(PG_FUNCTION_ARGS) Oid relfilenode = PG_GETARG_OID(1); Oid heaprel = InvalidOid; + if (!OidIsValid(relfilenode)) + PG_RETURN_NULL(); + heaprel = RelidByRelfilenode(reltablespace, relfilenode); if (!OidIsValid(heaprel))