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 1p6EEh-0007gU-SD for pgsql-bugs@arkaria.postgresql.org; Fri, 16 Dec 2022 17:11:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p6EEg-0002sV-R5 for pgsql-bugs@arkaria.postgresql.org; Fri, 16 Dec 2022 17:11:02 +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 1p6EEg-0002oa-J7 for pgsql-bugs@lists.postgresql.org; Fri, 16 Dec 2022 17:11:02 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p6EEe-0003JJ-9m for pgsql-bugs@lists.postgresql.org; Fri, 16 Dec 2022 17:11:02 +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 2BGHAuRL3697955; Fri, 16 Dec 2022 12:10:56 -0500 From: Tom Lane To: vik@postgresfriends.org cc: pgsql-bugs@lists.postgresql.org, Peter Eisentraut Subject: Re: BUG #17723: cache lookup failed for type 0 In-reply-to: <17723-2c4985ff111e7bba@postgresql.org> References: <17723-2c4985ff111e7bba@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Fri, 16 Dec 2022 15:38:04 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3697953.1671210656.1@sss.pgh.pa.us> Date: Fri, 16 Dec 2022 12:10:56 -0500 Message-ID: <3697954.1671210656@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: > This query: > WITH RECURSIVE > run(x, y) AS ( > SELECT 0, 0 > UNION ALL > SELECT x, y FROM run AS r WHERE r.is_cycle > ) > CYCLE x, y SET is_cycle USING path > TABLE run > ; > in which I mistakenly tried to access the is_cycle column from inside the > wle, provokes the following error: > ERROR: XX000: cache lookup failed for type 0 > LOCATION: typeOrDomainTypeRelid, parse_type.c:699 Yeah. We are calling addRangeTableEntryForCTE inside parse analysis of the CTE's query, and it's generating a ParseNamespaceItem with p_vartype = 0 because analyzeCTE hasn't yet identified the cycle_mark_type. That eventually results in a Var with vartype 0, confusing later parse analysis. It looks to me like we can just move that part of the code up to before we recurse to parse_sub_analyze, though. AFAICS, identification of the cycle column type needn't (and had better not) depend on any characteristics of the CTE's query. regards, tom lane