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 1tds4k-00AEhb-9C for pgsql-hackers@arkaria.postgresql.org; Fri, 31 Jan 2025 14:32: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 1tds3l-000qEY-4r for pgsql-hackers@arkaria.postgresql.org; Fri, 31 Jan 2025 14:31:53 +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 1tds3k-000qCA-5T for pgsql-hackers@lists.postgresql.org; Fri, 31 Jan 2025 14:31:52 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tds3f-002TfH-1N for pgsql-hackers@lists.postgresql.org; Fri, 31 Jan 2025 14:31:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1738333905; bh=K7tqseDqN/ZTjs4aAMDSqWq90a97H/x56h5EQqnmq/U=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=aIrgFGAf6qrofJkRIfQDhF0W1SMxSO1BAgXey8JlAZ6+0ZkwRpukRG0q2NS7zsP5Z zl1BaG0kzvtEX5pH59iFRffI4h2l5lZyOSN165lt9M54DtF2qrXozs/ualAAsecI4O wACIp+vHB1m9s2RV/M2a+lyEXpH2MxWtrhb1S77VtYEH4rL6gsNKLI+sWpQah4Pgod NMr3+00h7iOOuS9Mv/qT446pDRa6th2H80XF16aRqDtRwjw0hfyUD0EjLz7oYhdrMQ 5x+W1C05U3M56c58IMzukR21W5N6KTJwp+b0e7gVj7/gNmFvOXV4Z7JLbvlx11exRh PR+A7K16jm+BQ== Received: from [10.4.12.74] (unknown [93.174.131.141]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: a.rybakina@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id 0701860144; Fri, 31 Jan 2025 17:31:45 +0300 (MSK) Content-Type: multipart/alternative; boundary="------------qitupXfotRrAhbMUIzx0N2NE" Message-ID: Date: Fri, 31 Jan 2025 17:31:44 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: POC, WIP: OR-clause support for indexes To: Alexander Korotkov Cc: Ranier Vilela , Alexander Lakhin , jian he , Robert Haas , Nikolay Shaplov , pgsql-hackers@lists.postgresql.org, pgsql-hackers@postgresql.org, Peter Geoghegan , Marcos Pegoraro , teodor@sigaev.ru, Peter Eisentraut , Andrei Lepikhov References: <567ED6CA.2040504@sigaev.ru> <37bf870a-22e0-4aba-b845-549482118f8d@gmail.com> <8174de69-9e1a-0827-0e81-ef97f56a5939@gmail.com> <3b717020-14d9-425f-8c60-ce336b5a23b3@postgrespro.ru> <43db6a40-5c5f-4909-ad62-3060b297e686@postgrespro.ru> <41ba3d47-2a48-476c-88d4-6ebd889a7af2@gmail.com> Content-Language: en-US From: Alena Rybakina In-Reply-To: X-KSMG-AntiPhishing: NotDetected, bases: 2025/01/31 13:28:00 X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.0.7854, bases: 2025/01/31 13:26:00 #27170191 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 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. --------------qitupXfotRrAhbMUIzx0N2NE Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi! On 25.01.2025 08:04, Alexander Korotkov wrote: > On Wed, Jan 15, 2025 at 10:24 AM Andrei Lepikhov wrote: >> On 1/13/25 10:39, Andrei Lepikhov wrote: >>> On 1/13/25 01:39, Alexander Korotkov wrote: >>> It can be resolved with a single-line change (see attached). But I need >>> some time to ponder over the changing behaviour when a clause may match >>> an index and be in joinorclauses. >> In addition, let me raise a couple of issues: >> 1. As Robert has said before, it may interfere with some short-circuit >> optimisations like below: >> >> EXPLAIN (COSTS OFF) >> SELECT * FROM bitmap_split_or t1 >> WHERE t1.a=2 AND (t1.b=2 OR t1.b = ( >> SELECT sum(c1.reltuples) FROM pg_class c1, pg_class c2 >> WHERE c1.relpages=c2.relpages AND c1.relpages = t1.a)); >> >> Here, a user may avoid evaluating the subplan at all if t1.b=2 all the >> time when t1.a=2. OR->ANY may accidentally shift this behaviour. >> >> 2. The query: >> >> EXPLAIN (ANALYZE, COSTS OFF) >> SELECT * FROM bitmap_split_or t1 >> WHERE t1.a=2 OR t1.a = ( >> SELECT sum(c1.reltuples) FROM pg_class c1, pg_class c2 >> WHERE c1.relpages=c2.relpages AND c1.relpages = t1.a)::integer; >> >> causes SEGFAULT during index keys evaluation. I haven't dived into it >> yet, but it seems quite a typical misstep and is not difficult to fix. > Segfault appears to be caused by a typo. Patch used parent rinfo > instead of child rinfo. Fixed in the attached patch. > > It appears that your first query also changed a plan after fixing > this. Could you, please, provide another example of a regression for > short-circuit optimization, which is related to this patch? > > Also, I've integrated your fix from [1]. > > Links. > 1.https://www.postgresql.org/message-id/41ba3d47-2a48-476c-88d4-6ebd889a7af2%40gmail.com I started reviewing at the patch and saw some output "ERROR" in the output of the test and is it okay here? SELECT * FROM tenk1 t1 WHERE t1.thousand= 42OR t1.thousand= (SELECT t2.tenthousFROM tenk1 t2 WHERE t2.thousand= t1.tenthous); ERROR: more than one row returned by a subquery used as an expression -- Regards, Alena Rybakina Postgres Professional --------------qitupXfotRrAhbMUIzx0N2NE Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

Hi!

On 25.01.2025 08:04, Alexander Korotkov wrote:
On Wed, Jan 15, 2025 at 10:24 AM Andrei Lepikhov <lepihov@gmail.com> wrote:
On 1/13/25 10:39, Andrei Lepikhov wrote:
On 1/13/25 01:39, Alexander Korotkov wrote:
It can be resolved with a single-line change (see attached). But I need
some time to ponder over the changing behaviour when a clause may match
an index and be in joinorclauses.
In addition, let me raise a couple of issues:
1. As Robert has said before, it may interfere with some short-circuit
optimisations like below:

EXPLAIN (COSTS OFF)
SELECT * FROM bitmap_split_or t1
WHERE t1.a=2 AND (t1.b=2 OR t1.b = (
   SELECT sum(c1.reltuples) FROM pg_class c1, pg_class c2
   WHERE c1.relpages=c2.relpages AND c1.relpages = t1.a));

Here, a user may avoid evaluating the subplan at all if t1.b=2 all the
time when t1.a=2. OR->ANY may accidentally shift this behaviour.

2. The query:

EXPLAIN (ANALYZE, COSTS OFF)
SELECT * FROM bitmap_split_or t1
WHERE t1.a=2 OR t1.a = (
   SELECT sum(c1.reltuples) FROM pg_class c1, pg_class c2
   WHERE c1.relpages=c2.relpages AND c1.relpages = t1.a)::integer;

causes SEGFAULT during index keys evaluation. I haven't dived into it
yet, but it seems quite a typical misstep and is not difficult to fix.
Segfault appears to be caused by a typo.  Patch used parent rinfo
instead of child rinfo.  Fixed in the attached patch.

It appears that your first query also changed a plan after fixing
this.  Could you, please, provide another example of a regression for
short-circuit optimization, which is related to this patch?

Also, I've integrated your fix from [1].

Links.
1. https://www.postgresql.org/message-id/41ba3d47-2a48-476c-88d4-6ebd889a7af2%40gmail.com

I started reviewing at the patch and saw some output "ERROR" in the output of the test and is it okay here?

SELECT * FROM tenk1 t1
WHERE t1.thousand = 42 OR t1.thousand = (SELECT t2.tenthous FROM tenk1 t2 WHERE t2.thousand = t1.tenthous);
ERROR: more than one row returned by a subquery used as an expression

-- 
Regards,
Alena Rybakina
Postgres Professional
--------------qitupXfotRrAhbMUIzx0N2NE--