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.94.2) (envelope-from ) id 1qnvnu-00CSHP-KR for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Oct 2023 06:56:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qnvns-00Coxk-Ko for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Oct 2023 06:56:16 +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.94.2) (envelope-from ) id 1qnvns-00Coxc-6d for pgsql-hackers@lists.postgresql.org; Wed, 04 Oct 2023 06:56:16 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qnvnm-0086cj-LF for pgsql-hackers@lists.postgresql.org; Wed, 04 Oct 2023 06:56:15 +0000 Received: from [192.168.1.34] (cm-171-100-241-42.revip10.asianet.co.th [171.100.241.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: a.lepikhov@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id D0939E20FD2; Wed, 4 Oct 2023 09:56:06 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1696402568; bh=nD+LK+rq28WEr6rbpnFKxc/Qsn3ui1UZdhV6UykdKqw=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=KxpiPvIyHpxcdELX9ItwX56Z9JdzomPj7Hq1LhSPCSoD45HGhNG4sIo9tyG3rJ0np wvAhr4uEifDR9ZIGQXUbQEorIkj24In9MHGo294jzPYPnnVM1Q4H5dlkJDOJ8UE2fz SoIDHdl9hXkNkc7M+u/EKvQSJdUz25v0sctV32iHfNA3D4nGeGOzPUwt0QntLN2mXG 4jaTOwYoelAZQBb33SkNEt10MB0fpMfWTrMBZTXb4ZV9rHJURRcAzMywAGf9KM/GSn Lz6T0ud+xIAuho4Q/3l4fQz9jRn+wudUGuV1TiMUWHzULfN2s2D26dHu0t813w9mdY 352EfpV4Z7Z9w== Message-ID: Date: Wed, 4 Oct 2023 13:55:59 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Removing unneeded self joins To: Alexander Korotkov Cc: "Gregory Stark (as CFM)" , =?UTF-8?Q?Micha=C5=82_K=C5=82eczek?= , PostgreSQL Hackers References: <64486b0b-0404-e39e-322d-0801154901f3@postgrespro.ru> <13021914.uLZWGnKmhe@aivenronan> <2375492.jE0xQCEvom@aivenronan> <0fd15c10-eaa5-51bd-b5c7-e635fe03a94d@postgrespro.ru> <20221206184643.zya44h5auv6f45zp@awork3.anarazel.de> <36579124-f9d9-a51e-38b3-af3511921c7e@postgrespro.ru> <88079CBD-B5BB-4C61-A68B-A8C67599E1C7@kleczek.org> <05469e80-454b-41d7-d04f-421f42bbd4a9@postgrespro.ru> Content-Language: en-US From: Andrei Lepikhov Organization: Postgres Professional In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 4/10/2023 07:12, Alexander Korotkov wrote: > Hi! Thanks for the review! > > I think this is a neat optimization. > > On Tue, Sep 12, 2023 at 4:58 PM Andrey Lepikhov > wrote: >> On 5/7/2023 21:28, Andrey Lepikhov wrote: >>> During the significant code revision in v.41 I lost some replacement >>> operations. Here is the fix and extra tests to check this in the future. >>> Also, Tom added the JoinDomain structure five months ago, and I added >>> code to replace relids for that place too. >>> One more thing, I found out that we didn't replace SJs, defined by >>> baserestrictinfos if no one self-join clause have existed for the join. >>> Now, it is fixed, and the test has been added. >>> To understand changes readily, see the delta file in the attachment. >> Here is new patch in attachment. Rebased on current master and some >> minor gaffes are fixed. > > I went through the thread and I think the patch gets better shape. A > couple of notes from my side. > 1) Why replace_relid() makes a copy of lids only on insert/replace of > a member, but performs deletion in-place? Shortly speaking, it was done according to the 'Paranoid' strategy. The main reason for copying before deletion was the case with the rinfo required_relids and clause_relids. They both point to the same Bitmapset in some cases. And we feared such things for other fields. Right now, it may be redundant because we resolved the issue mentioned above in replace_varno_walker. Relid replacement machinery is the most contradictory code here. We used a utilitarian approach and implemented a simplistic variant. > 2) It would be nice to skip the insertion of IS NOT NULL checks when > they are not necessary. [1] points that infrastructure from [2] might > be useful. The patchset from [2] seems committed mow. However, I > can't see it is directly helpful in this matter. Could we just skip > adding IS NOT NULL clause for the columns, that have > pg_attribute.attnotnull set? Thanks for the links, I will look into that case. > > Links > 1. https://www.postgresql.org/message-id/2375492.jE0xQCEvom%40aivenronan > 2. https://www.postgresql.org/message-id/flat/830269.1656693747%40sss.pgh.pa.us -- regards, Andrey Lepikhov Postgres Professional