Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x09jG-004UgF-1O for pgsql-hackers@arkaria.postgresql.org; Sat, 29 Aug 2026 03:27:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x09jE-00AN3A-1D for pgsql-hackers@arkaria.postgresql.org; Sat, 29 Aug 2026 03:27:36 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x09jE-00AN32-0E for pgsql-hackers@lists.postgresql.org; Sat, 29 Aug 2026 03:27:36 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x09jC-00000002wRl-1Pa2 for pgsql-hackers@lists.postgresql.org; Sat, 29 Aug 2026 03:27:35 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 67T3ROWw1708837; Fri, 28 Aug 2026 23:27:24 -0400 From: Tom Lane To: Tender Wang cc: Richard Guo , Thom Brown , Jacob Brazeal , pgsql-hackers@lists.postgresql.org Subject: Re: remove_useless_joins vs. bug #19560 In-reply-to: References: <1186816.1784573544@sss.pgh.pa.us> <2727652.1784997994@sss.pgh.pa.us> <2746010.1785014587@sss.pgh.pa.us> <2933135.1785032128@sss.pgh.pa.us> <3304318.1785087206@sss.pgh.pa.us> <3304418.1785087314@sss.pgh.pa.us> <3968565.1785170019@sss.pgh.pa.us> <3975112.1785176472@sss.pgh.pa.us> <670538.1786924698@sss.pgh.pa.us> <839346.1787765112@sss.pgh.pa.us> <954541.1787846010@sss.pgh.pa.us> <1147476.1787924590@sss.pgh.pa.us> Comments: In-reply-to Tender Wang message dated "Sat, 29 Aug 2026 11:03:49 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1708835.1787974044.1@sss.pgh.pa.us> Date: Fri, 28 Aug 2026 23:27:24 -0400 Message-ID: <1708836.1787974044@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Tender Wang writes: > After 2ebf25e7d70a8, I hit a crash. Oh, interesting. What we have here is: > SELECT > FROM (SELECT CASE > WHEN NULL > THEN sample_1.a > ELSE NULL > END AS c2 > FROM ... What's apparently happening is that we pull up the sub-select, and eval_const_expressions flattens the CASE to constant-NULL, so we don't see the reference to sample_1.a and conclude that sample_1 can be dropped from the query. But when we do that, we try to mutate the original copy of the sub-select's tlist which still contains sample_1.a, and so we hit the Assert saying we should no longer see any such Vars. Not immediately sure what to do about that ... I don't think that dropping the Asserts would fix it, even if that were a pleasant answer which it's not. If we allowed the Var to become a reference to INVALID_VAR, then when we repeat the eval_const_expressions run later, we're going to have problems. IIRC, there are places where eval_const_expressions looks up Var properties such as null-ness, and that'd fail. regards, tom lane