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 1lrtTJ-00015L-D4 for pgsql-hackers@arkaria.postgresql.org; Sat, 12 Jun 2021 02:34:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lrtSm-00031C-Ih for pgsql-hackers@arkaria.postgresql.org; Sat, 12 Jun 2021 02:33:32 +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 1lrtSm-000314-B7 for pgsql-hackers@lists.postgresql.org; Sat, 12 Jun 2021 02:33:32 +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 1lrtSj-0004rf-Jw for pgsql-hackers@lists.postgresql.org; Sat, 12 Jun 2021 02:33:31 +0000 Received: by mail-io1-xd31.google.com with SMTP id l64so11566684ioa.7 for ; Fri, 11 Jun 2021 19:33:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=P0ydI9qWZ4q+qbb09YsjKcRJRbbW9u6xk5spi+U7Mb8=; b=XXbknQZlIFNe1/dVHc9EffCwlLbVhjKNJD2Xvsn03quGOCxX9q1yGwCiynmP3x0I3/ srSA4U6K2MPqPS7Tw8d/6S4ioEsfK+N7Z/Oyje2l2dF1cAVk7h05BXCKRXtssig0gQL4 Ax5wHFahMt+Lp/rCxD2el70Eqs39PgHviZssjmTFLorOpxUHkBOPKFTr3QRfuXuOVGcq QDqrk2m/wKPd94OBzFS5NSxhienZXOdV2R2q0PMOuFfIF+0UTzvpnK5rRQWNCU6VyzGZ e0KoRtbkw/wWGddrBgGhC6YbILIcEpUPLqiqEbpH1+E0E7h8sQYC7N15NuPwKsBMBzaZ nVeA== 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:subject:message-id:mime-version :content-disposition:user-agent; bh=P0ydI9qWZ4q+qbb09YsjKcRJRbbW9u6xk5spi+U7Mb8=; b=cCYXbax3Pc6bHW4zgIWJZQ2jwk3SdU1QXER9X9jhZceROaNxXSoC6O3Ekb0a9poOE1 V2dtrDn5iBcfRPW8YzQ2Zc92W4MOVwuwvTeZA2wiXCs21uSqTByrxM7YNBTYSp97MNHI 4b8TWyAqkwzqYExFOM/8ILgobJNfg3JukH7nCgVaLbWbYwKDtQ2lb6kORXOSzfCOmplT rvRv5rtZl0Ooa9fRBj1sBuq27LBB3y84iPG9KOrG6/cZ7X0cnvEgv8fb1QmqQccxdfRV /zZJmnytN1jzo5WForqO1Stscau69P4ft7Yxpx/4pn5EYxEv4uZsTxq88QjlIbMXfFY8 BzWg== X-Gm-Message-State: AOAM5314rkipSOQkNh6QscuCXN9QRExN/MH3qnV6tAjeyo3ouZ/wdOpX tHBVJc1x28uk39306n0jdO42+G39CddOWg== X-Google-Smtp-Source: ABdhPJwxtbTt6F3iDVpnDjyAaUv1L7M8qeOHcSsBMCItaJYkv6phr099fU/q8Oy+h9pv51uRpjrZ+w== X-Received: by 2002:a05:6638:1919:: with SMTP id p25mr6609148jal.115.1623465206859; Fri, 11 Jun 2021 19:33:26 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id d6sm4068957ils.88.2021.06.11.19.33.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Jun 2021 19:33:26 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 33ECE800BDE; Fri, 11 Jun 2021 21:33:25 -0500 (CDT) Date: Fri, 11 Jun 2021 21:33:25 -0500 From: Justin Pryzby To: pgsql-hackers@lists.postgresql.org Subject: pg_filenode_relation(0,0) elog Message-ID: <20210612023324.GT16435@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 Per sqlsmith. postgres=# SELECT pg_filenode_relation(0,0); ERROR: unexpected duplicate for tablespace 0, relfilenode 0 postgres=# \errverbose ERROR: XX000: unexpected duplicate for tablespace 0, relfilenode 0 LOCATION: RelidByRelfilenode, relfilenodemap.c:220 The usual expectation is that sql callable functions should return null rather than hitting elog(). This also means that sqlsmith has one fewer false-positive error. I think it should return NULL if passed invalid relfilenode, rather than searching pg_class and then writing a pretty scary message about duplicates. diff --git a/src/backend/utils/cache/relfilenodemap.c b/src/backend/utils/cache/relfilenodemap.c index 56d7c73d33..5a5cf853bd 100644 --- a/src/backend/utils/cache/relfilenodemap.c +++ b/src/backend/utils/cache/relfilenodemap.c @@ -146,6 +146,9 @@ RelidByRelfilenode(Oid reltablespace, Oid relfilenode) ScanKeyData skey[2]; Oid relid; + if (!OidIsValid(relfilenode)) + return InvalidOid; + if (RelfilenodeMapHash == NULL) InitializeRelfilenodeMap();