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 1p6GVZ-00071x-OQ for pgsql-bugs@arkaria.postgresql.org; Fri, 16 Dec 2022 19:36:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p6GVW-0002Up-EM for pgsql-bugs@arkaria.postgresql.org; Fri, 16 Dec 2022 19:36:34 +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 1p6GVW-0002Ug-6c for pgsql-bugs@lists.postgresql.org; Fri, 16 Dec 2022 19:36:34 +0000 Received: from relay11.mail.gandi.net ([217.70.178.231]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p6GVT-0005D8-RD for pgsql-bugs@lists.postgresql.org; Fri, 16 Dec 2022 19:36:33 +0000 Received: (Authenticated sender: vik@postgresfriends.org) by mail.gandi.net (Postfix) with ESMTPSA id C4A69100002; Fri, 16 Dec 2022 19:36:28 +0000 (UTC) Message-ID: Date: Fri, 16 Dec 2022 20:36:27 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: BUG #17723: cache lookup failed for type 0 To: Tom Lane Cc: pgsql-bugs@lists.postgresql.org, Peter Eisentraut References: <17723-2c4985ff111e7bba@postgresql.org> <3697954.1671210656@sss.pgh.pa.us> From: Vik Fearing Content-Language: en-US In-Reply-To: <3697954.1671210656@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 12/16/22 18:10, Tom Lane wrote: > 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. Indeed, it should only depend on the TO and DEFAULT subclauses (not shown here). Thanks for the fix! -- Vik Fearing