1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Change gist stratnum function to use CompareType

This changes commit 7406ab623f in that the gist strategy number
mapping support function is changed to use the CompareType enum as
input, instead of the "well-known" RT*StrategyNumber strategy numbers.

This is a bit cleaner, since you are not dealing with two sets of
strategy numbers.  Also, this will enable us to subsume this system
into a more general system of using CompareType to define operator
semantics across index methods.

Discussion: https://www.postgresql.org/message-id/flat/E72EAA49-354D-4C2E-8EB9-255197F55330@enterprisedb.com
This commit is contained in:
Peter Eisentraut
2025-01-15 11:28:39 +01:00
parent 6339f6468e
commit 630f9a43ce
19 changed files with 145 additions and 126 deletions

View File

@ -290,8 +290,8 @@ CREATE INDEX ON my_table USING GIST (my_inet_column inet_ops);
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
translate compare types (from
<filename>src/include/nodes/primnodes.h</filename>) into strategy numbers
used by the operator class. This lets the core code look up operators for
temporal constraint indexes.
</para>
@ -1173,8 +1173,8 @@ my_sortsupport(PG_FUNCTION_ARGS)
<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
Given a <literal>CompareType</literal> value from
<filename>src/include/nodes/primnodes.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.
@ -1184,7 +1184,7 @@ my_sortsupport(PG_FUNCTION_ARGS)
This is used for temporal index constraints (i.e., <literal>PRIMARY
KEY</literal> and <literal>UNIQUE</literal>). If the operator class
provides this function and it returns results for
<literal>RTEqualStrategyNumber</literal>, it can be used in the
<literal>COMPARE_EQ</literal>, it can be used in the
non-<literal>WITHOUT OVERLAPS</literal> part(s) of an index constraint.
</para>
@ -1194,7 +1194,7 @@ my_sortsupport(PG_FUNCTION_ARGS)
<programlisting>
CREATE OR REPLACE FUNCTION my_stratnum(integer)
RETURNS integer
RETURNS smallint
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;
</programlisting>
@ -1209,12 +1209,12 @@ PG_FUNCTION_INFO_V1(my_stratnum);
Datum
my_stratnum(PG_FUNCTION_ARGS)
{
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(1);
CompareType cmptype = PG_GETARG_INT32(0);
StrategyNumber ret = InvalidStrategy;
switch (strategy)
switch (cmptype)
{
case RTEqualStrategyNumber:
case COMPARE_EQ:
ret = BTEqualStrategyNumber;
}
@ -1226,9 +1226,9 @@ my_stratnum(PG_FUNCTION_ARGS)
<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>
<literal>gist_stratnum_common</literal> is for operator classes that
use the <literal>RT*StrategyNumber</literal> constants.
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.

View File

@ -592,7 +592,7 @@
</row>
<row>
<entry><function>stratnum</function></entry>
<entry>translate well-known strategy numbers to ones
<entry>translate compare types to strategy numbers
used by the operator class (optional)</entry>
<entry>12</entry>
</row>