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 1nvUzw-0005rV-4R for pgsql-bugs@arkaria.postgresql.org; Mon, 30 May 2022 02:19:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nvUzu-00065Y-UP for pgsql-bugs@arkaria.postgresql.org; Mon, 30 May 2022 02:19:10 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nvUzu-00065P-Ly for pgsql-bugs@lists.postgresql.org; Mon, 30 May 2022 02:19:10 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nvUzs-000820-A7 for pgsql-bugs@lists.postgresql.org; Mon, 30 May 2022 02:19:09 +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 24U2IxNF3722617; Sun, 29 May 2022 22:18:59 -0400 From: Tom Lane To: David Rowley cc: =?UTF-8?Q?Daniel_Farka=C5=A1?= , Magnus Hagander , PostgreSQL mailing lists Subject: Re: BUG #17502: View based on window functions returns wrong results when queried In-reply-to: References: <17502-281a7aaacfaa872a@postgresql.org> Comments: In-reply-to David Rowley message dated "Mon, 30 May 2022 10:30:14 +1200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3722615.1653877139.1@sss.pgh.pa.us> Date: Sun, 29 May 2022 22:18:59 -0400 Message-ID: <3722616.1653877139@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk David Rowley writes: > The problem seems to be down to the fact that > remove_unused_subquery_outputs() does not check if the to-be-removed > target entry references WindowClauses which contain set-returning > functions. I was sort of wondering why we allow SRFs in this context in the first place. The results don't seem terribly well-defined to me. In particular, a WindowFunc invocation is not supposed to change the number of rows in the query result, and yet this one is doing so. regards, tom lane