1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-31 22:04:40 +03:00

Rename gist stratnum support function

Commit 7406ab623f added a gist support function that we internally
refer to by the symbol GIST_STRATNUM_PROC.  This translated from
"well-known" strategy numbers to opfamily-specific strategy numbers.
However, we later (commit 630f9a43ce) changed this to fit into
index-AM-level compare type mapping, so this function actually now
maps from compare type to opfamily-specific strategy numbers.  So this
name is no longer fitting.

Moreover, the index AM level also supports the opposite, a function to
map from strategy number to compare type.  This is currently not
supported in gist, but one might wonder what this function is supposed
to be called when it is added.

This patch changes the naming of the gist-level functionality to be
more in line with the index-AM-level functionality.  This makes sense
because these are essentially the same thing on different levels.
This also changes the names of the externally visible functions that
are provided for use as such a support function.

Reviewed-by: Paul A Jungwirth <pj@illuminatedcomputing.com>
Discussion: https://www.postgresql.org/message-id/37ebb1d9-9036-485f-a215-e55435689917%40eisentraut.org
This commit is contained in:
Peter Eisentraut
2025-06-02 08:33:04 +02:00
parent 5231ed8262
commit 32edf732e8
14 changed files with 92 additions and 81 deletions

View File

@ -1170,7 +1170,7 @@ my_sortsupport(PG_FUNCTION_ARGS)
</varlistentry>
<varlistentry>
<term><function>stratnum</function></term>
<term><function>translate_cmptype</function></term>
<listitem>
<para>
Given a <literal>CompareType</literal> value from
@ -1188,12 +1188,23 @@ my_sortsupport(PG_FUNCTION_ARGS)
non-<literal>WITHOUT OVERLAPS</literal> part(s) of an index constraint.
</para>
<para>
This support function corresponds to the index access method callback
function <structfield>amtranslatecmptype</structfield> (see <xref
linkend="index-functions"/>). The
<structfield>amtranslatecmptype</structfield> callback function for
GiST indexes merely calls down to the
<function>translate_cmptype</function> support function of the
respective operator family, since the GiST index access method has no
fixed strategy numbers itself.
</para>
<para>
The <acronym>SQL</acronym> declaration of the function must look like
this:
<programlisting>
CREATE OR REPLACE FUNCTION my_stratnum(integer)
CREATE OR REPLACE FUNCTION my_translate_cmptype(integer)
RETURNS smallint
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;
@ -1202,7 +1213,7 @@ LANGUAGE C STRICT;
And the operator family registration must look like this:
<programlisting>
ALTER OPERATOR FAMILY my_opfamily USING gist ADD
FUNCTION 12 ("any", "any") my_stratnum(int);
FUNCTION 12 ("any", "any") my_translate_cmptype(int);
</programlisting>
</para>
@ -1210,10 +1221,10 @@ ALTER OPERATOR FAMILY my_opfamily USING gist ADD
The matching code in the C module could then follow this skeleton:
<programlisting>
PG_FUNCTION_INFO_V1(my_stratnum);
PG_FUNCTION_INFO_V1(my_translate_cmptype);
Datum
my_stratnum(PG_FUNCTION_ARGS)
my_translate_cmptype(PG_FUNCTION_ARGS)
{
CompareType cmptype = PG_GETARG_INT32(0);
StrategyNumber ret = InvalidStrategy;
@ -1232,11 +1243,11 @@ my_stratnum(PG_FUNCTION_ARGS)
<para>
One translation function is provided by
<productname>PostgreSQL</productname>:
<literal>gist_stratnum_common</literal> is for operator classes that
<literal>gist_translate_cmptype_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
<literal>gist_translate_cmptype_btree</literal>, for operator classes that use
the <literal>BT*StrategyNumber</literal> constants.
</para>
</listitem>

View File

@ -598,7 +598,7 @@
<entry>11</entry>
</row>
<row>
<entry><function>stratnum</function></entry>
<entry><function>translate_cmptype</function></entry>
<entry>translate compare types to strategy numbers
used by the operator class (optional)</entry>
<entry>12</entry>