aboutsummaryrefslogtreecommitdiff
path: root/doc/src
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2024-09-17 10:19:26 +0200
committerPeter Eisentraut <peter@eisentraut.org>2024-09-17 11:29:29 +0200
commit7406ab623fee1addcb21c881afecbe638a0d56e9 (patch)
tree6c75a0f795ecec184e0cb9dcd05ed74bd324a6c6 /doc/src
parent95d6e9af07d2e5af2fdd272e72b5b552bad3ea0a (diff)
downloadpostgresql-7406ab623fee1addcb21c881afecbe638a0d56e9.tar.gz
postgresql-7406ab623fee1addcb21c881afecbe638a0d56e9.zip
Add stratnum GiST support function
This is support function 12 for the GiST AM and translates "well-known" RT*StrategyNumber values into whatever strategy number is used by the opclass (since no particular numbers are actually required). We will use this to support temporal PRIMARY KEY/UNIQUE/FOREIGN KEY/FOR PORTION OF functionality. This commit adds two implementations, one for internal GiST opclasses (just an identity function) and another for btree_gist opclasses. It updates btree_gist from 1.7 to 1.8, adding the support function for all its opclasses. (previously committed as 6db4598fcb8, reverted by 8aee330af55; this is essentially unchanged from those) Author: Paul A. Jungwirth <pj@illuminatedcomputing.com> Reviewed-by: Peter Eisentraut <peter@eisentraut.org> Reviewed-by: jian he <jian.universality@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/CA+renyUApHgSZF9-nd-a0+OPGharLQLO=mDHcY4_qQ0+noCUVg@mail.gmail.com
Diffstat (limited to 'doc/src')
-rw-r--r--doc/src/sgml/gist.sgml65
-rw-r--r--doc/src/sgml/xindex.sgml8
2 files changed, 71 insertions, 2 deletions
diff --git a/doc/src/sgml/gist.sgml b/doc/src/sgml/gist.sgml
index 39c7bf370d6..f789824c83b 100644
--- a/doc/src/sgml/gist.sgml
+++ b/doc/src/sgml/gist.sgml
@@ -266,7 +266,7 @@ CREATE INDEX ON my_table USING GIST (my_inet_column inet_ops);
<para>
There are five methods that an index operator class for
- <acronym>GiST</acronym> must provide, and six that are optional.
+ <acronym>GiST</acronym> must provide, and seven that are optional.
Correctness of the index is ensured
by proper implementation of the <function>same</function>, <function>consistent</function>
and <function>union</function> methods, while efficiency (size and speed) of the
@@ -289,6 +289,10 @@ CREATE INDEX ON my_table USING GIST (my_inet_column inet_ops);
user-specified parameters.
The optional eleventh method <function>sortsupport</function> is used to
speed up building a <acronym>GiST</acronym> index.
+ The optional twelfth method <function>stratnum</function> is used to
+ translate well-known <literal>RT*StrategyNumber</literal>s (from
+ <filename>src/include/access/stratnum.h</filename>) into strategy numbers
+ used by the operator class.
</para>
<variablelist>
@@ -1163,6 +1167,65 @@ my_sortsupport(PG_FUNCTION_ARGS)
</para>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><function>stratnum</function></term>
+ <listitem>
+ <para>
+ Given an <literal>RT*StrategyNumber</literal> value from
+ <filename>src/include/access/stratnum.h</filename>, returns a strategy
+ number used by this operator class for matching functionality. The
+ function should return <literal>InvalidStrategy</literal> if the
+ operator class has no matching strategy.
+ </para>
+
+ <para>
+ The <acronym>SQL</acronym> declaration of the function must look like
+ this:
+
+<programlisting>
+CREATE OR REPLACE FUNCTION my_stratnum(integer)
+RETURNS integer
+AS 'MODULE_PATHNAME'
+LANGUAGE C STRICT;
+</programlisting>
+ </para>
+
+ <para>
+ The matching code in the C module could then follow this skeleton:
+
+<programlisting>
+PG_FUNCTION_INFO_V1(my_stratnum);
+
+Datum
+my_stratnum(PG_FUNCTION_ARGS)
+{
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(1);
+ StrategyNumber ret = InvalidStrategy;
+
+ switch (strategy)
+ {
+ case RTEqualStrategyNumber:
+ ret = BTEqualStrategyNumber;
+ }
+
+ PG_RETURN_UINT16(ret);
+}
+</programlisting>
+ </para>
+
+ <para>
+ One translation function is provided by
+ <productname>PostgreSQL</productname>:
+ <literal>gist_stratnum_identity</literal> is for operator classes that
+ already use the <literal>RT*StrategyNumber</literal> constants. It
+ returns whatever is passed to it. The <literal>btree_gist</literal>
+ extension defines a second translation function,
+ <literal>gist_stratnum_btree</literal>, for operator classes that use
+ the <literal>BT*StrategyNumber</literal> constants.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
<para>
diff --git a/doc/src/sgml/xindex.sgml b/doc/src/sgml/xindex.sgml
index 22d8ad1aac4..3a19dab15e0 100644
--- a/doc/src/sgml/xindex.sgml
+++ b/doc/src/sgml/xindex.sgml
@@ -508,7 +508,7 @@
</table>
<para>
- GiST indexes have eleven support functions, six of which are optional,
+ GiST indexes have twelve support functions, seven of which are optional,
as shown in <xref linkend="xindex-gist-support-table"/>.
(For more information see <xref linkend="gist"/>.)
</para>
@@ -590,6 +590,12 @@
(optional)</entry>
<entry>11</entry>
</row>
+ <row>
+ <entry><function>stratnum</function></entry>
+ <entry>translate well-known strategy numbers to ones
+ used by the operator class (optional)</entry>
+ <entry>12</entry>
+ </row>
</tbody>
</tgroup>
</table>