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 1lYEF3-0004Hq-Di for pgsql-hackers@arkaria.postgresql.org; Sun, 18 Apr 2021 20:42: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 1lYEF0-00078C-IL for pgsql-hackers@arkaria.postgresql.org; Sun, 18 Apr 2021 20:42: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 1lYEF0-000785-Bp for pgsql-hackers@lists.postgresql.org; Sun, 18 Apr 2021 20:42: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 1lYEEv-0005PU-RL for pgsql-hackers@lists.postgresql.org; Sun, 18 Apr 2021 20:42:01 +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 13IKfrVZ141462; Sun, 18 Apr 2021 16:41:53 -0400 From: Tom Lane To: "Joel Jacobson" cc: pgsql-hackers@lists.postgresql.org Subject: Re: Planning time grows exponentially with levels of nested views In-reply-to: <140747.1618776847@sss.pgh.pa.us> References: <797aff54-b49b-4914-9ff9-aa42564a4d7d@www.fastmail.com> <140747.1618776847@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Sun, 18 Apr 2021 16:14:07 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <141460.1618778513.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 18 Apr 2021 16:41:53 -0400 Message-ID: <141461.1618778513@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I wrote: > If multiple references are actually possible then this'd break it. Ther= e > seem to be no such cases in the regression tests though, and I'm having = a > hard time wrapping my brain around what would cause it. "git blame" > traces this text to my own commit f44639e1b, which has the log entry > Don't crash if subquery appears multiple times in jointree. This sh= ould > not happen anyway, but let's try not to get completely confused if i= t does > (due to rewriter bugs or whatever). > so I'm thinking that this was only hypothetical. Ah, found it. That was evidently a reaction to the immediately preceding commit (352871ac9), which fixed a rewriter bug that could lead to exactly the case of multiple jointree references to one RTE. I think this patch doesn't make things any worse for such a case though. If we re-introduced such a bug, the result would be an immediate null pointer crash while trying to process the second reference to a flattenable subquery. That's probably better for debuggability than what happens now, where we just silently process the duplicate reference. Anyway, I've stuck this into the next CF for future consideration. regards, tom lane PS: to save time for anyone else who wants to investigate this, it looks like the report mentioned in 352871ac9 was https://www.postgresql.org/message-id/007401c0860d%24bed809a0%241001a8c0%4= 0archonet.com