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 1r7lct-006htG-FN for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Nov 2023 00:06: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 1r7lcr-000NgG-EB for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Nov 2023 00:06:53 +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 1r7lcr-000Ng7-2P for pgsql-hackers@lists.postgresql.org; Tue, 28 Nov 2023 00:06:53 +0000 Received: from mail-lj1-x236.google.com ([2a00:1450:4864:20::236]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r7lco-008sKx-Bs for pgsql-hackers@postgresql.org; Tue, 28 Nov 2023 00:06:52 +0000 Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2c501bd6ff1so65031521fa.3 for ; Mon, 27 Nov 2023 16:06:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701130009; x=1701734809; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=TaFrukwmLlBBmM+L7wdqG1FfCTXxNY+6T9PQlgq8l/I=; b=bwCimD2kZui00hR9kEyH4N5Gt7JlKXi9pw/pIx+Qb/9+KhL+D3FiHLPQD+Lc9YSMKw 76NfTh+hCPAz5vAPmiAbWmjskOwF2XKgP0An2upCwf7CPhaiXb6tnEfwaVLdrY7N+DED 77Jbo0he1UjBVP26kcSDB4OvCt8h+I6Qxni6JkmNcqiycyZTvdDXfmDAeKQkN1fW/3Vu UHaKyzb0gz6iiHu8OZ1R87iYpJRAbqjYvA8iDYq2QrhsrcKlEELdiPTkoyJzpZ76Ruim pvVu77Ww3x6NJDY/jeZBBxoPh4ZtQ+RWmti6MAD7i8t44DixXAmbejpzGcRlYHJbqMM+ 2bcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701130009; x=1701734809; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TaFrukwmLlBBmM+L7wdqG1FfCTXxNY+6T9PQlgq8l/I=; b=Yg2sOZYdIgcR+BBws+3CD1KxweAOQ9nJi/jnFYwv1F9p5kFAZ21RCNtpPSvyZbYOcK O1aDdLbAn4n87SI7L43Ne11mPW5Tfz7UkWbd9F80CyRdGnCqirUtlJnYM/y0/SzoiJhL MSWQowtsURv7P0mnB+jJjVcUrUxZtpHUDsBcp+YMKJToj7u+5+fEjcX4wgt+AUgwwEZ2 hadzNkvuA9EAsnsBRhAJ+ETYAZdL6l8a+OD9hhwFuSGMoPTRZOUL0iOcwCw9JN6T6PCL /ewO/KdRxhkcBShck/X/R3DLfoM9oWkRbIiEc919sxgfjMcbKiyF6/oRS516KqJEBmts 2vRQ== X-Gm-Message-State: AOJu0Yzsq8yd3Cf+QcW2vLzugiIJDnI01tguQ+H0Dil9pbaaIif4yjS8 jCcQn1sJ5b9OAgOyC6Bqr2kmsbY9lezasdlO7/E= X-Google-Smtp-Source: AGHT+IFRTqQPQQkfsM3+WHILK3ulH0xtNV+4yg6TlF58UjQmR0VRElVv3hri0M0Ci5eUJPSgQU/jMx49C59OtKCilxM= X-Received: by 2002:a05:651c:1067:b0:2c9:9a45:a3c5 with SMTP id y7-20020a05651c106700b002c99a45a3c5mr4283750ljm.34.1701130009021; Mon, 27 Nov 2023 16:06:49 -0800 (PST) MIME-Version: 1.0 References: <567ED6CA.2040504@sigaev.ru> <16a7e3aa-24c0-4986-8820-ea2857bd7b6b@postgrespro.ru> <421656a9-5df7-41bb-9d58-1c1edbd5dc3e@postgrespro.ru> <28c727ba-5260-42a8-88b0-4ecdeeca6ef8@postgrespro.ru> <4c1c2c0b-802f-45ae-a7cd-007bfd8957cf@postgrespro.ru> <52f0d302-7963-452f-8c5a-f66d261514eb@postgrespro.ru> <43ad8a48-b980-410d-a83c-5beebf82a4ed@postgrespro.ru> <04ef16eb-46c1-4ce7-9f68-d1c80ef0be81@postgrespro.ru> In-Reply-To: From: Matthias van de Meent Date: Tue, 28 Nov 2023 01:06:35 +0100 Message-ID: Subject: Re: POC, WIP: OR-clause support for indexes To: Peter Geoghegan Cc: Robert Haas , Andrei Lepikhov , Alexander Korotkov , Alena Rybakina , PostgreSQL Hackers , "Finnerty, Jim" , Marcos Pegoraro , Teodor Sigaev , Ranier Vilela , Tomas Vondra , Peter Eisentraut Content-Type: multipart/alternative; boundary="000000000000e79316060b2b3126" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000e79316060b2b3126 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, 27 Nov 2023, 23:16 Peter Geoghegan, wrote: > On Mon, Nov 27, 2023 at 1:04=E2=80=AFPM Robert Haas wrote: > > The use of op_mergejoinable() seems pretty random to me. Why should we > > care about that? If somebody writes a<1 or a<2 or a<3 or a<4, you can > > transform that to a > good idea, but I think it's a legal transformation. > > That kind of transformation is likely to be a very good idea, because > nbtree's _bt_preprocess_array_keys() function knows how to perform > preprocessing that makes the final index qual "a < 1". Obviously that > could be far more efficient. > a < 4, you mean? The example mentioned ANY, not ALL Further suppose you have a machine generated query "a<1 or a<2 or a<3 > or a<4 AND a =3D 2" -- same as before, except that I added "AND a =3D 2" > to the end. Now _bt_preprocess_array_keys() will be able to do the > aforementioned inequality preprocessing, just as before. But this time > _bt_preprocess_keys() (a different function with a similar name) can > see that the quals are contradictory. That makes the entire index scan > end, before it ever really began. > With the given WHERE-clause I would hope it did *not* return before scanning the index, given that any row with a < 3 is valid for that constraint with current rules of operator precedence. - Matthias --000000000000e79316060b2b3126 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Mon, 27 Nov 2023, 23:16 Peter Geoghegan, <pg@bowt.ie> wrote:
On Mon, Nov 27, 2023 at 1:04=E2=80=AFPM Robert Haas <r= obertmhaas@gmail.com> wrote:
> The use of op_mergejoinable() seems pretty random to me. Why should we=
> care about that? If somebody writes a<1 or a<2 or a<3 or a<= ;4, you can
> transform that to a<any(array[1,2,3,4]) if you want. It might not b= e a
> good idea, but I think it's a legal transformation.

That kind of transformation is likely to be a very good idea, because
nbtree's _bt_preprocess_array_keys() function knows how to perform
preprocessing that makes the final index qual "a < 1". Obvious= ly that
could be far more efficient.
=
a < 4, you mean? The example mentioned ANY, = not ALL

Further suppose you have a machin= e generated query=C2=A0 "a<1 or a<2 or a<3
or a<4 AND a =3D 2" -- same as before, except that I added "AN= D a =3D 2"
to the end. Now _bt_preprocess_array_keys() will be able to do the
aforementioned inequality preprocessing, just as before. But this time
_bt_preprocess_keys() (a different function with a similar name) can
see that the quals are contradictory. That makes the entire index scan
end, before it ever really began.

With the given WHERE-clause I would hope i= t did not return before scanning the index, given that any row with = a < 3 is valid for that constraint with current rules of operator preced= ence.

- Matthias
--000000000000e79316060b2b3126--