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 1nvccy-0006KM-Dj for pgsql-bugs@arkaria.postgresql.org; Mon, 30 May 2022 10:28:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nvccw-0001Oe-AG for pgsql-bugs@arkaria.postgresql.org; Mon, 30 May 2022 10:27:58 +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 1nvccw-0001OP-20 for pgsql-bugs@lists.postgresql.org; Mon, 30 May 2022 10:27:58 +0000 Received: from carbon.misis.ru ([85.143.104.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nvccu-0003rk-6X for pgsql-bugs@lists.postgresql.org; Mon, 30 May 2022 10:27:57 +0000 Received: from mail.tzirechnoy.ru (unknown [10.1.250.11]) by carbon.misis.ru (Postfix) with ESMTP id 5441E2102D for ; Mon, 30 May 2022 13:27:54 +0300 (MSK) Received: by mail.tzirechnoy.ru (Postfix, from userid 1000) id E5141A42B1; Mon, 30 May 2022 13:27:53 +0300 (MSK) Date: Mon, 30 May 2022 13:27:53 +0300 From: Ilya Anfimov To: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17502: View based on window functions returns wrong results when queried Message-ID: <20220530102753.GA2725032@azor.tzirechnoy.ru> Mail-Followup-To: Ilya Anfimov , pgsql-bugs@lists.postgresql.org References: <17502-281a7aaacfaa872a@postgresql.org> <3722616.1653877139@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3722616.1653877139@sss.pgh.pa.us> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spamd-Result: default: False [0.00 / 15.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_NO_TLS_LAST(0.10)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2] X-Rspamd-Queue-Id: 5441E2102D X-Rspamd-Server: carbon List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, May 29, 2022 at 10:18:59PM -0400, Tom Lane wrote: > 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. I would like to note, that some SRFs may return only one row in specific cases, like dblink() with the specific query. It may used much more often, than real multirow SRFs in PARTITION BY. While converting it to a LATERAL JOIN is not a lot of work -- breaking it in previous versions may affect a lot of people.