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 1qulqd-001aMP-RI for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Oct 2023 03:43:24 +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 1qulqb-004gUu-KJ for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Oct 2023 03:43:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qulqb-004gUl-6y for pgsql-hackers@lists.postgresql.org; Mon, 23 Oct 2023 03:43:22 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qulqZ-002BDb-2j for pgsql-hackers@lists.postgresql.org; Mon, 23 Oct 2023 03:43:21 +0000 Received: from [10.10.20.95] (node-1ir.pool-118-173.dynamic.totinternet.net [118.173.7.179]) (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 6D8B9E20E70; Mon, 23 Oct 2023 06:43:16 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1698032597; bh=nD6OOi+tGJnKSAgB5TiEY4VhXNR/BDebNFmgGd1kk1o=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=PZ6HyxNb1LOqdcnEVCFvu5yHbh3P0H8cZK3JrvuHUp7bp1mohBilH2IWm48fhXzi+ TfCYJvqjfR1R1WBeoujkNVeSUHP20H4qqtIO7trMf3elkfyDoGPLP0rnh5N1I+baYD nVx0ELlo597anetOmHmo0XJidWt5kNYtpdmt4LUQywr58G003Jh16Aq9Hc91k5wos4 rEFHpcet7xZDbMe+syR/VWXbjJ9dcfz0nHRbmGoltmdP3eZa4eVLp9UWIylma+1La6 DCXfAj64bAufoKycOrBLE2jsCLO98e0yzOs717JrB1Tbk0wUH7I4Ibu6LxCBlWMGHk 6YKH5cPKv8t1w== Content-Type: multipart/mixed; boundary="------------lW6IStaFkEldtZ8k9Wgv4Owu" Message-ID: <922623af-872e-4cdc-9238-129b18bee42d@postgrespro.ru> Date: Mon, 23 Oct 2023 10:43:13 +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> <36579124-f9d9-a51e-38b3-af3511921c7e@postgrespro.ru> <88079CBD-B5BB-4C61-A68B-A8C67599E1C7@kleczek.org> <05469e80-454b-41d7-d04f-421f42bbd4a9@postgrespro.ru> <48c11b23-9c23-440e-9a3c-020e05196449@postgrespro.ru> <8800ccf2-ae82-461c-92a1-d4c0a22f8cf2@postgrespro.ru> <1bd80083-a13e-4e9f-a7ce-73c3faab521c@postgrespro.ru> Content-Language: en-US From: Andrei Lepikhov Organization: Postgres Professional In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------lW6IStaFkEldtZ8k9Wgv4Owu Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 22/10/2023 05:01, Alexander Korotkov wrote: > On Thu, Oct 19, 2023 at 6:16 AM Andrei Lepikhov > wrote: >> On 19/10/2023 01:50, Alexander Korotkov wrote: >>> This query took 3778.432 ms with self-join removal disabled, and >>> 3756.009 ms with self-join removal enabled. So, no measurable >>> overhead. Similar to the higher number of joins. Can you imagine >>> some extreme case when self-join removal could introduce significant >>> overhead in comparison with other optimizer parts? If not, should we >>> remove self_join_search_limit GUC? >> Thanks, >> It was Zhihong Yu who worried about that case [1]. And my purpose was to >> show a method to avoid such a problem if it would be needed. >> I guess the main idea here is that we have a lot of self-joins, but only >> few of them (or no one) can be removed. >> I can't imagine a practical situation when we can be stuck in the >> problems here. So, I vote to remove this GUC. > > I've removed the self_join_search_limit. Anyway there is > enable_self_join_removal if the self join removal algorithm causes any > problems. I also did some grammar corrections for the comments. I > think the patch is getting to the committable shape. I noticed some > failures on commitfest.cputube.org. I'd like to check how this > version will pass it. I have observed the final patch. A couple of minor changes can be made (see attachment). Also, I see room for improvement, but it can be done later. For example, we limit the optimization to only ordinary tables in this patch. It can be extended at least with partitioned and foreign tables soon. -- regards, Andrey Lepikhov Postgres Professional --------------lW6IStaFkEldtZ8k9Wgv4Owu Content-Type: text/plain; charset=UTF-8; name="minor_changes.diff" Content-Disposition: attachment; filename="minor_changes.diff" Content-Transfer-Encoding: base64 ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL29wdGltaXplci9wbGFuL2FuYWx5emVqb2lucy5j IGIvc3JjL2JhY2tlbmQvb3B0aW1pemVyL3BsYW4vYW5hbHl6ZWpvaW5zLmMKaW5kZXggNmI4 NDhhYWRhZC4uYjg0MTk3ZGFkYiAxMDA2NDQKLS0tIGEvc3JjL2JhY2tlbmQvb3B0aW1pemVy L3BsYW4vYW5hbHl6ZWpvaW5zLmMKKysrIGIvc3JjL2JhY2tlbmQvb3B0aW1pemVyL3BsYW4v YW5hbHl6ZWpvaW5zLmMKQEAgLTIzLDcgKzIzLDYgQEAKICNpbmNsdWRlICJwb3N0Z3Jlcy5o IgogCiAjaW5jbHVkZSAiY2F0YWxvZy9wZ19jbGFzcy5oIgotI2luY2x1ZGUgIm5vZGVzL21h a2VmdW5jcy5oIgogI2luY2x1ZGUgIm5vZGVzL25vZGVGdW5jcy5oIgogI2luY2x1ZGUgIm9w dGltaXplci9jbGF1c2VzLmgiCiAjaW5jbHVkZSAib3B0aW1pemVyL2pvaW5pbmZvLmgiCkBA IC01MCw3ICs0OSw3IEBAIHR5cGVkZWYgc3RydWN0IFVuaXF1ZVJlbEluZm8KIH0gVW5pcXVl UmVsSW5mbzsKIAogLyoKLSAqIFRoZSBjb250ZXh0IGZvciByZXBsYWNlX3Zhcm5vX3dhbGtl cigpIGNvbnRhaW5pbmcgc291cmNlIGFuZCB0YXJnZXQgcmVsaWRzMgorICogVGhlIGNvbnRl eHQgZm9yIHJlcGxhY2VfdmFybm9fd2Fsa2VyKCkgY29udGFpbmluZyBzb3VyY2UgYW5kIHRh cmdldCByZWxpZHMuCiAgKi8KIHR5cGVkZWYgc3RydWN0CiB7Cg== --------------lW6IStaFkEldtZ8k9Wgv4Owu--