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 1ra5qM-0082nl-VM for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Feb 2024 03:21:55 +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 1ra5qJ-003aFI-Jz for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Feb 2024 03:21:51 +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 1ra5qJ-003aDd-6G for pgsql-hackers@lists.postgresql.org; Wed, 14 Feb 2024 03:21:51 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ra5qG-0075UR-BA for pgsql-hackers@postgresql.org; Wed, 14 Feb 2024 03:21:50 +0000 Received: from [172.30.8.38] (unknown [172.30.8.38]) (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 AD7B2E21090; Wed, 14 Feb 2024 06:21:43 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1707880906; bh=KYEfKas3mhaeAqPFMbi8yUnj+O2FE7syTNaySmn/4Xs=; h=Message-ID:Date:User-Agent:Subject:From:To:Cc:References: In-Reply-To:From; b=YqsiLXQRgE2HllpDMu6EOMqP/3lHqbJ3u8PT3rlXdecfaOlSB3kPNpifV+sl0yt0S vnSToKaxaoSBHeJ3xQvvAIyjSJfwepiowPnUbtTihPQRVnbS3NVk1vvpPn29IYbpTD uQ0OY8XI+hwGOEH4xKJ9KYW/SujB9PW6KLiSdWKgjpW/gGAJbrbds4d4lVxB+LUn1n BuZ1lSzVCfJL+KC3dBkSxJ2B2S8OqD3uGsHi78kQoY447hwldWXzBARcZBNpp/fbT4 nP7TZZcP2gMctbBvB8zMMqzSl/A125KCSlXlBmMLM9Kj7hSlXkQcp1j0SKz+yPJkeJ UDzsCWenOYJOw== Message-ID: <1cf6b382-6e27-4268-9f2a-54ada66eb2eb@postgrespro.ru> Date: Wed, 14 Feb 2024 10:21:41 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: POC, WIP: OR-clause support for indexes Content-Language: en-US From: Andrei Lepikhov To: jian he Cc: Alena Rybakina , Alexander Korotkov , Robert Haas , pgsql-hackers@postgresql.org, Peter Geoghegan , "Finnerty, Jim" , Marcos Pegoraro , teodor@sigaev.ru, Ranier Vilela , Tomas Vondra , Peter Eisentraut References: <567ED6CA.2040504@sigaev.ru> <04ef16eb-46c1-4ce7-9f68-d1c80ef0be81@postgrespro.ru> <59e67a40-95a8-4d74-ae4e-027ea0f59084@postgrespro.ru> <59b77a8a-29d6-4727-bf26-4a30a6a9719a@postgrespro.ru> <32d23d97-d07f-4d44-9933-ba3295fb3ed8@postgrespro.ru> <7e11e27b-7ab9-4d59-af0a-a921861a9206@postgrespro.ru> <13ad923a-33df-4b44-9e00-c9323cd4c37d@postgrespro.ru> Organization: Postgres Professional In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 13/2/2024 17:03, Andrei Lepikhov wrote: > On 13/2/2024 07:00, jian he wrote: >> The time is the last result of the 10 iterations. > I'm not sure about the origins of such behavior, but it seems to be an > issue of parallel workers, not this specific optimization. Having written that, I'd got a backburner. And to close that issue, I explored get_restriction_qual_cost(). A close look shows us that "x IN (..)" cheaper than its equivalent "x=N1 OR ...". Just numbers: ANY: startup_cost = 0.0225; total_cost = 0.005 OR: startup_cost==0; total_cost = 0.0225 Expression total_cost is calculated per tuple. In your example, we have many tuples, so the low cost of expression per tuple dominates over the significant startup cost. According to the above, SAOP adds 6250 to the cost of SeqScan; OR - 13541. So, the total cost of the query with SAOP is less than with OR, and the optimizer doesn't choose heavy parallel workers. And it is the answer. So, this example is more about the subtle balance between parallel/sequential execution, which can vary from one platform to another. -- regards, Andrei Lepikhov Postgres Professional