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 1lhxFp-0003mq-H7 for pgsql-bugs@arkaria.postgresql.org; Sat, 15 May 2021 16:35: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 1lhxFo-0005bK-GW for pgsql-bugs@arkaria.postgresql.org; Sat, 15 May 2021 16:35:04 +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 1lhwsS-0007Cg-2F for pgsql-bugs@lists.postgresql.org; Sat, 15 May 2021 16:10:56 +0000 Received: from forward104o.mail.yandex.net ([37.140.190.179]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lhwsP-00077K-4w for pgsql-bugs@lists.postgresql.org; Sat, 15 May 2021 16:10:55 +0000 Received: from myt6-10de976bd0de.qloud-c.yandex.net (myt6-10de976bd0de.qloud-c.yandex.net [IPv6:2a02:6b8:c12:2493:0:640:10de:976b]) by forward104o.mail.yandex.net (Yandex) with ESMTP id 42502940E40; Sat, 15 May 2021 19:10:50 +0300 (MSK) Received: from myt3-5a0d70690205.qloud-c.yandex.net (myt3-5a0d70690205.qloud-c.yandex.net [2a02:6b8:c12:4f2b:0:640:5a0d:7069]) by myt6-10de976bd0de.qloud-c.yandex.net (mxback/Yandex) with ESMTP id TN8j4aQXTi-AnJuPGIC; Sat, 15 May 2021 19:10:50 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1621095050; bh=1w2T9TntJL1Vnx4gt1kV09iT5UKvggQGjX+EP5OxHKE=; h=In-Reply-To:Subject:CC:To:Message-ID:From:References:Date; b=gS7GdDkyeyvdzBWK3G8YquzzIwEyhYaEOpYCVpErs2PbErA8hdsL+/8r9wIqOctyQ /1WufDFqqVRKL333JjUXE2gA3/0KfcsYrIZATXlSfu9xmtCNb4Fz8MigPUcMvbnuBj kngvBcGJqM+AZyyg45yyaThd+VglWYB7AfI1rCRY= Authentication-Results: myt6-10de976bd0de.qloud-c.yandex.net; dkim=pass header.i=@yandex.ru Received: by myt3-5a0d70690205.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id W4DAaR7HZ8-AmL8Brv3; Sat, 15 May 2021 19:10:48 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) Date: Sat, 15 May 2021 19:10:48 +0300 From: Eugen Konkov Message-ID: <147634374.20210515191048@yandex.ru> To: David Rowley CC: PG Bug reporting form , PostgreSQL mailing lists , pgsql-performance , "ladayaroslav@yandex.ru" Subject: Re: BUG #16968: Planner does not recognize optimization In-Reply-To: References: <16968-9c8a1708c1c04355@postgresql.org> <846547866.20210416222735@yandex.ru> <226821618.20210513163513@yandex.ru> <55211620994674@mail.yandex.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello David, > I really think you're driving yourself down a difficult path by > expecting queries with whole-row vars to be optimised just as well as > using select * or explicitly listing the columns. Yes, I was expect that. I use whole-row because do not want repeat all 10+ columns at select. I do not use (row1).*, (row2).*, because rows could have same columns. eg: row1.name, row2.name both will be named as 'name' and then I can not distinguish them. So I select whole-row and put myself into problems (( It would be nice if (row1).** will be expanded to: row1_id, row1_name etc. But this is other question which I already ask at different thread. Saturday, May 15, 2021, 5:59:41 PM, you wrote: > On Sat, 15 May 2021 at 00:39, KES wrote: >> >> Thank you for detailed explanation. I glad to hear that I can use aliases and this will be recognized and optimization is applied. >> >> >We'd need some sort of ability to assign ressortgroupref to a particular column within a >> whole-row var >> Could it be possible to create hidden alias in same way as I did that manually? >> >> Algorithm seems not complex: >> 1. User refer column from composite type/whole-row: (o).agreement_id >> 2. Create hidden column at select: _o_agreement_id >> 3. Replace other references to (o).agreement_id by _o_agreement_id >> 4. Process query as usual after replacements > Internally Postgresql does use a hidden column for columns that are > required for calculations which are not in the SELECT list. e.g ones > that are in the GROUP BY / ORDER BY, or in your case a window > function's PARTITION BY. We call these "resjunk" columns. The problem > is you can't reference those from the parent query. If you explicitly > had listed that column in the SELECT clause, it won't cost you > anything more since the planner will add it regardless and just hide > it from you. When you add it yourself you'll be able to use it in the > subquery and you'll be able to filter out the partitions that you > don't want. > I really think you're driving yourself down a difficult path by > expecting queries with whole-row vars to be optimised just as well as > using select * or explicitly listing the columns. > David -- Best regards, Eugen Konkov