public inbox for [email protected]  
help / color / mirror / Atom feed
From: Alena Rybakina <[email protected]>
To: jian he <[email protected]>
Cc: Andrei Lepikhov <[email protected]>
Cc: Alexander Korotkov <[email protected]>
Cc: Robert Haas <[email protected]>
Cc: [email protected]
Cc: Peter Geoghegan <[email protected]>
Cc: Finnerty, Jim <[email protected]>
Cc: Marcos Pegoraro <[email protected]>
Cc: [email protected]
Cc: Tomas Vondra <[email protected]>
Cc: Peter Eisentraut <[email protected]>
Cc: Ranier Vilela <[email protected]>
Subject: Re: POC, WIP: OR-clause support for indexes
Date: Mon, 26 Feb 2024 07:10:47 +0300
Message-ID: <[email protected]> (raw)
In-Reply-To: <CACJufxFhQn0awSEcZD7=FHvjx6OLt6PUtuoi0_10pWFVXUEDJw@mail.gmail.com>
References: <[email protected]>
	<[email protected]>
	<CACJufxFS-xcjaWq2Du2OyJUjRAyqCk12Q_zGOPxv61sgrdpw9w@mail.gmail.com>
	<[email protected]>
	<[email protected]>
	<CACJufxFSfSGZpmVt_98SRojdugW2s9H-qYm2sYr0A3o-xPea0g@mail.gmail.com>
	<[email protected]>
	<[email protected]>
	<CACJufxH-zju3VfosSRBu8d3xs99sGENn6+P3AETLuTiAPFY+0g@mail.gmail.com>
	<[email protected]>
	<CACJufxFMFoosvbuFYDiFtpam4sKCSGJeh5jYiZSY8PHjCpEHYA@mail.gmail.com>
	<[email protected]>
	<CAEudQAq4XTcwhw2OmfW1AJNqvMfbReEWjuzqv6YTz6ZjbpmL0g@mail.gmail.com>
	<[email protected]>
	<CAEudQArk002t_C9LGoeJWnw=iGKikt+gSa8Mh==muG00WS=qYA@mail.gmail.com>
	<CACJufxFhQn0awSEcZD7=FHvjx6OLt6PUtuoi0_10pWFVXUEDJw@mail.gmail.com>

On 24.02.2024 14:28, jian he wrote:
> Hi.
> I wrote the first draft patch of the documentation.
> it's under the section: Planner Method Configuration (runtime-config-query.html)
> but this feature's main meat is in src/backend/parser/parse_expr.c
> so it may be slightly inconsistent, as mentioned by others.
>
> You can further furnish it.

Thank you for your work. I found a few spelling mistakes - I fixed this 
and added some information about generating a partial index plan. I 
attached it.

-- 
Regards,
Alena Rybakina
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

From e3a0e01c43a70099f6870a468d0cc3a8bdcb2775 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <[email protected]>
Date: Mon, 26 Feb 2024 06:37:36 +0300
Subject: [PATCH] doc1

---
 doc/src/sgml/config.sgml | 74 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 36a2a5ce431..47f82ca2dc9 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5294,6 +5294,80 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
       </listitem>
      </varlistentry>
 
+     <varlistentry id="guc-enable-or-transformation" xreflabel="enable_or_transformation">
+      <term><varname>enable_or_transformation</varname> (<type>boolean</type>)
+       <indexterm>
+        <primary><varname>enable_or_transformation</varname> configuration parameter</primary>
+       </indexterm>
+      </term>
+      <listitem>
+       <para>
+        Enables or disables in query planner's ability to transform multiple expressions in (<xref linkend="sql-expressions"/>)
+        <xref linkend="sql-where"/> to a ANY expression (<xref linkend="functions-comparisons-any-some"/>).
+        This transformations only apply under the following condition:
+        <itemizedlist>
+          <listitem>
+          <para>
+            Each expression should be formed as: <replaceable>expression</replaceable> <replaceable>operator</replaceable>  (<replaceable>expression</replaceable>).
+            The right-hand side of the operator should be just a plain constant.
+            The left-hand side of these expressions should remain unchanged.
+          </para>
+          </listitem>
+        </itemizedlist>
+        <itemizedlist>
+          <listitem>
+          <para>
+            At the stage of index formation, a check is made on the restructuring of the plan using partial indexes or the formation of expressions combined by the "OR" <replaceable>operator</replaceable>.
+          </para>
+          </listitem>
+        </itemizedlist>
+            <itemizedlist>
+              <listitem>
+                <para>
+                  Each expression form should return Boolean (true/false) result.
+                </para>
+              </listitem>
+            </itemizedlist>
+            <itemizedlist>
+              <listitem>
+                <para>
+                These expressions are logically linked in a OR condition.
+                </para>
+              </listitem>
+            </itemizedlist>
+          The default is <literal>on</literal>.
+          </para>
+        <para>
+          For example, the following query without setting <varname>enable_or_transformation</varname> is usually applied to the three filtering conditions separately,
+          but if we set <varname>enable_or_transformation</varname>, we combine the three expressions into only one expression: <literal>unique1 = ANY ('{1,2,3}'::integer[]) </literal>.
+          <programlisting>
+          EXPLAIN SELECT * FROM tenk1 WHERE unique1 = 1 or unique1 = 2 or unique1 = 3;
+
+                                  QUERY PLAN
+          -------------------------------------------------------------
+          Seq Scan on tenk1  (cost=0.00..482.50 rows=3 width=244)
+            Filter: (unique1 = ANY ('{1,2,3}'::integer[]))
+          </programlisting>
+        </para>
+        <para>
+          Another example is the following query with a given <varname>enable_or_transformation</varname> value, but we have generated a plan with partial indexes.
+          <programlisting>
+          EXPLAIN SELECT unique2, stringu1 FROM onek2 WHERE unique1 = 1 OR unique1 = PI()::integer;
+                              QUERY PLAN                    
+          --------------------------------------------------
+          Bitmap Heap Scan on onek2
+            Recheck Cond: ((unique1 = 3) OR (unique1 = 1))
+            ->  BitmapOr
+                  ->  Bitmap Index Scan on onek2_u1_prtl
+                        Index Cond: (unique1 = 3)
+                  ->  Bitmap Index Scan on onek2_u1_prtl
+                        Index Cond: (unique1 = 1)
+          (7 rows)
+          </programlisting>
+        </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry id="guc-enable-parallel-append" xreflabel="enable_parallel_append">
       <term><varname>enable_parallel_append</varname> (<type>boolean</type>)
       <indexterm>
-- 
2.34.1



Attachments:

  [text/plain] v1-0001-Add-enable_or_transformation-doc-entry.no-cfbot (4.4K, ../[email protected]/2-v1-0001-Add-enable_or_transformation-doc-entry.no-cfbot)
  download | inline diff:
From e3a0e01c43a70099f6870a468d0cc3a8bdcb2775 Mon Sep 17 00:00:00 2001
From: Alena Rybakina <[email protected]>
Date: Mon, 26 Feb 2024 06:37:36 +0300
Subject: [PATCH] doc1

---
 doc/src/sgml/config.sgml | 74 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 36a2a5ce431..47f82ca2dc9 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5294,6 +5294,80 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
       </listitem>
      </varlistentry>
 
+     <varlistentry id="guc-enable-or-transformation" xreflabel="enable_or_transformation">
+      <term><varname>enable_or_transformation</varname> (<type>boolean</type>)
+       <indexterm>
+        <primary><varname>enable_or_transformation</varname> configuration parameter</primary>
+       </indexterm>
+      </term>
+      <listitem>
+       <para>
+        Enables or disables in query planner's ability to transform multiple expressions in (<xref linkend="sql-expressions"/>)
+        <xref linkend="sql-where"/> to a ANY expression (<xref linkend="functions-comparisons-any-some"/>).
+        This transformations only apply under the following condition:
+        <itemizedlist>
+          <listitem>
+          <para>
+            Each expression should be formed as: <replaceable>expression</replaceable> <replaceable>operator</replaceable>  (<replaceable>expression</replaceable>).
+            The right-hand side of the operator should be just a plain constant.
+            The left-hand side of these expressions should remain unchanged.
+          </para>
+          </listitem>
+        </itemizedlist>
+        <itemizedlist>
+          <listitem>
+          <para>
+            At the stage of index formation, a check is made on the restructuring of the plan using partial indexes or the formation of expressions combined by the "OR" <replaceable>operator</replaceable>.
+          </para>
+          </listitem>
+        </itemizedlist>
+            <itemizedlist>
+              <listitem>
+                <para>
+                  Each expression form should return Boolean (true/false) result.
+                </para>
+              </listitem>
+            </itemizedlist>
+            <itemizedlist>
+              <listitem>
+                <para>
+                These expressions are logically linked in a OR condition.
+                </para>
+              </listitem>
+            </itemizedlist>
+          The default is <literal>on</literal>.
+          </para>
+        <para>
+          For example, the following query without setting <varname>enable_or_transformation</varname> is usually applied to the three filtering conditions separately,
+          but if we set <varname>enable_or_transformation</varname>, we combine the three expressions into only one expression: <literal>unique1 = ANY ('{1,2,3}'::integer[]) </literal>.
+          <programlisting>
+          EXPLAIN SELECT * FROM tenk1 WHERE unique1 = 1 or unique1 = 2 or unique1 = 3;
+
+                                  QUERY PLAN
+          -------------------------------------------------------------
+          Seq Scan on tenk1  (cost=0.00..482.50 rows=3 width=244)
+            Filter: (unique1 = ANY ('{1,2,3}'::integer[]))
+          </programlisting>
+        </para>
+        <para>
+          Another example is the following query with a given <varname>enable_or_transformation</varname> value, but we have generated a plan with partial indexes.
+          <programlisting>
+          EXPLAIN SELECT unique2, stringu1 FROM onek2 WHERE unique1 = 1 OR unique1 = PI()::integer;
+                              QUERY PLAN                    
+          --------------------------------------------------
+          Bitmap Heap Scan on onek2
+            Recheck Cond: ((unique1 = 3) OR (unique1 = 1))
+            ->  BitmapOr
+                  ->  Bitmap Index Scan on onek2_u1_prtl
+                        Index Cond: (unique1 = 3)
+                  ->  Bitmap Index Scan on onek2_u1_prtl
+                        Index Cond: (unique1 = 1)
+          (7 rows)
+          </programlisting>
+        </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry id="guc-enable-parallel-append" xreflabel="enable_parallel_append">
       <term><varname>enable_parallel_append</varname> (<type>boolean</type>)
       <indexterm>
-- 
2.34.1



view thread (41+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: POC, WIP: OR-clause support for indexes
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox