Skip to content

Commit 32edf73

Browse files
committed
Rename gist stratnum support function
Commit 7406ab6 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 630f9a4) 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
1 parent 5231ed8 commit 32edf73

File tree

14 files changed

+92
-81
lines changed

14 files changed

+92
-81
lines changed

contrib/btree_gist/btree_gist--1.7--1.8.sql

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,85 +3,85 @@
33
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
44
\echo Use "ALTER EXTENSION btree_gist UPDATE TO '1.8'" to load this file. \quit
55

6-
CREATE FUNCTION gist_stratnum_btree(int)
6+
CREATE FUNCTION gist_translate_cmptype_btree(int)
77
RETURNS smallint
88
AS 'MODULE_PATHNAME'
99
LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT;
1010

1111
ALTER OPERATOR FAMILY gist_oid_ops USING gist ADD
12-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
12+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
1313

1414
ALTER OPERATOR FAMILY gist_int2_ops USING gist ADD
15-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
15+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
1616

1717
ALTER OPERATOR FAMILY gist_int4_ops USING gist ADD
18-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
18+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
1919

2020
ALTER OPERATOR FAMILY gist_int8_ops USING gist ADD
21-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
21+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
2222

2323
ALTER OPERATOR FAMILY gist_float4_ops USING gist ADD
24-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
24+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
2525

2626
ALTER OPERATOR FAMILY gist_float8_ops USING gist ADD
27-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
27+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
2828

2929
ALTER OPERATOR FAMILY gist_timestamp_ops USING gist ADD
30-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
30+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
3131

3232
ALTER OPERATOR FAMILY gist_timestamptz_ops USING gist ADD
33-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
33+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
3434

3535
ALTER OPERATOR FAMILY gist_time_ops USING gist ADD
36-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
36+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
3737

3838
ALTER OPERATOR FAMILY gist_date_ops USING gist ADD
39-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
39+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
4040

4141
ALTER OPERATOR FAMILY gist_interval_ops USING gist ADD
42-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
42+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
4343

4444
ALTER OPERATOR FAMILY gist_cash_ops USING gist ADD
45-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
45+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
4646

4747
ALTER OPERATOR FAMILY gist_macaddr_ops USING gist ADD
48-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
48+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
4949

5050
ALTER OPERATOR FAMILY gist_text_ops USING gist ADD
51-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
51+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
5252

5353
ALTER OPERATOR FAMILY gist_bpchar_ops USING gist ADD
54-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
54+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
5555

5656
ALTER OPERATOR FAMILY gist_bytea_ops USING gist ADD
57-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
57+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
5858

5959
ALTER OPERATOR FAMILY gist_numeric_ops USING gist ADD
60-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
60+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
6161

6262
ALTER OPERATOR FAMILY gist_bit_ops USING gist ADD
63-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
63+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
6464

6565
ALTER OPERATOR FAMILY gist_vbit_ops USING gist ADD
66-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
66+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
6767

6868
ALTER OPERATOR FAMILY gist_inet_ops USING gist ADD
69-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
69+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
7070

7171
ALTER OPERATOR FAMILY gist_cidr_ops USING gist ADD
72-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
72+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
7373

7474
ALTER OPERATOR FAMILY gist_timetz_ops USING gist ADD
75-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
75+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
7676

7777
ALTER OPERATOR FAMILY gist_uuid_ops USING gist ADD
78-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
78+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
7979

8080
ALTER OPERATOR FAMILY gist_macaddr8_ops USING gist ADD
81-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
81+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
8282

8383
ALTER OPERATOR FAMILY gist_enum_ops USING gist ADD
84-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
84+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;
8585

8686
ALTER OPERATOR FAMILY gist_bool_ops USING gist ADD
87-
FUNCTION 12 ("any", "any") gist_stratnum_btree (int) ;
87+
FUNCTION 12 ("any", "any") gist_translate_cmptype_btree (int) ;

contrib/btree_gist/btree_gist.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ PG_MODULE_MAGIC_EXT(
1515
PG_FUNCTION_INFO_V1(gbt_decompress);
1616
PG_FUNCTION_INFO_V1(gbtreekey_in);
1717
PG_FUNCTION_INFO_V1(gbtreekey_out);
18-
PG_FUNCTION_INFO_V1(gist_stratnum_btree);
18+
PG_FUNCTION_INFO_V1(gist_translate_cmptype_btree);
1919

2020
/**************************************************
2121
* In/Out for keys
@@ -62,7 +62,7 @@ gbt_decompress(PG_FUNCTION_ARGS)
6262
* Returns the btree number for supported operators, otherwise invalid.
6363
*/
6464
Datum
65-
gist_stratnum_btree(PG_FUNCTION_ARGS)
65+
gist_translate_cmptype_btree(PG_FUNCTION_ARGS)
6666
{
6767
CompareType cmptype = PG_GETARG_INT32(0);
6868

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
-- test stratnum support func
2-
SELECT gist_stratnum_btree(7);
3-
gist_stratnum_btree
4-
---------------------
5-
0
1+
-- test stratnum translation support func
2+
SELECT gist_translate_cmptype_btree(7);
3+
gist_translate_cmptype_btree
4+
------------------------------
5+
0
66
(1 row)
77

8-
SELECT gist_stratnum_btree(3);
9-
gist_stratnum_btree
10-
---------------------
11-
3
8+
SELECT gist_translate_cmptype_btree(3);
9+
gist_translate_cmptype_btree
10+
------------------------------
11+
3
1212
(1 row)
1313

contrib/btree_gist/sql/stratnum.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
-- test stratnum support func
2-
SELECT gist_stratnum_btree(7);
3-
SELECT gist_stratnum_btree(3);
1+
-- test stratnum translation support func
2+
SELECT gist_translate_cmptype_btree(7);
3+
SELECT gist_translate_cmptype_btree(3);

doc/src/sgml/gist.sgml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ my_sortsupport(PG_FUNCTION_ARGS)
11701170
</varlistentry>
11711171

11721172
<varlistentry>
1173-
<term><function>stratnum</function></term>
1173+
<term><function>translate_cmptype</function></term>
11741174
<listitem>
11751175
<para>
11761176
Given a <literal>CompareType</literal> value from
@@ -1188,12 +1188,23 @@ my_sortsupport(PG_FUNCTION_ARGS)
11881188
non-<literal>WITHOUT OVERLAPS</literal> part(s) of an index constraint.
11891189
</para>
11901190

1191+
<para>
1192+
This support function corresponds to the index access method callback
1193+
function <structfield>amtranslatecmptype</structfield> (see <xref
1194+
linkend="index-functions"/>). The
1195+
<structfield>amtranslatecmptype</structfield> callback function for
1196+
GiST indexes merely calls down to the
1197+
<function>translate_cmptype</function> support function of the
1198+
respective operator family, since the GiST index access method has no
1199+
fixed strategy numbers itself.
1200+
</para>
1201+
11911202
<para>
11921203
The <acronym>SQL</acronym> declaration of the function must look like
11931204
this:
11941205

11951206
<programlisting>
1196-
CREATE OR REPLACE FUNCTION my_stratnum(integer)
1207+
CREATE OR REPLACE FUNCTION my_translate_cmptype(integer)
11971208
RETURNS smallint
11981209
AS 'MODULE_PATHNAME'
11991210
LANGUAGE C STRICT;
@@ -1202,18 +1213,18 @@ LANGUAGE C STRICT;
12021213
And the operator family registration must look like this:
12031214
<programlisting>
12041215
ALTER OPERATOR FAMILY my_opfamily USING gist ADD
1205-
FUNCTION 12 ("any", "any") my_stratnum(int);
1216+
FUNCTION 12 ("any", "any") my_translate_cmptype(int);
12061217
</programlisting>
12071218
</para>
12081219

12091220
<para>
12101221
The matching code in the C module could then follow this skeleton:
12111222

12121223
<programlisting>
1213-
PG_FUNCTION_INFO_V1(my_stratnum);
1224+
PG_FUNCTION_INFO_V1(my_translate_cmptype);
12141225

12151226
Datum
1216-
my_stratnum(PG_FUNCTION_ARGS)
1227+
my_translate_cmptype(PG_FUNCTION_ARGS)
12171228
{
12181229
CompareType cmptype = PG_GETARG_INT32(0);
12191230
StrategyNumber ret = InvalidStrategy;
@@ -1232,11 +1243,11 @@ my_stratnum(PG_FUNCTION_ARGS)
12321243
<para>
12331244
One translation function is provided by
12341245
<productname>PostgreSQL</productname>:
1235-
<literal>gist_stratnum_common</literal> is for operator classes that
1246+
<literal>gist_translate_cmptype_common</literal> is for operator classes that
12361247
use the <literal>RT*StrategyNumber</literal> constants.
12371248
The <literal>btree_gist</literal>
12381249
extension defines a second translation function,
1239-
<literal>gist_stratnum_btree</literal>, for operator classes that use
1250+
<literal>gist_translate_cmptype_btree</literal>, for operator classes that use
12401251
the <literal>BT*StrategyNumber</literal> constants.
12411252
</para>
12421253
</listitem>

doc/src/sgml/xindex.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@
598598
<entry>11</entry>
599599
</row>
600600
<row>
601-
<entry><function>stratnum</function></entry>
601+
<entry><function>translate_cmptype</function></entry>
602602
<entry>translate compare types to strategy numbers
603603
used by the operator class (optional)</entry>
604604
<entry>12</entry>

src/backend/access/gist/gistutil.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,11 +1058,11 @@ gistGetFakeLSN(Relation rel)
10581058
}
10591059

10601060
/*
1061-
* This is a stratnum support function for GiST opclasses that use the
1062-
* RT*StrategyNumber constants.
1061+
* This is a stratnum translation support function for GiST opclasses that use
1062+
* the RT*StrategyNumber constants.
10631063
*/
10641064
Datum
1065-
gist_stratnum_common(PG_FUNCTION_ARGS)
1065+
gist_translate_cmptype_common(PG_FUNCTION_ARGS)
10661066
{
10671067
CompareType cmptype = PG_GETARG_INT32(0);
10681068

@@ -1090,9 +1090,9 @@ gist_stratnum_common(PG_FUNCTION_ARGS)
10901090
/*
10911091
* Returns the opclass's private stratnum used for the given compare type.
10921092
*
1093-
* Calls the opclass's GIST_STRATNUM_PROC support function, if any,
1094-
* and returns the result.
1095-
* Returns InvalidStrategy if the function is not defined.
1093+
* Calls the opclass's GIST_TRANSLATE_CMPTYPE_PROC support function, if any,
1094+
* and returns the result. Returns InvalidStrategy if the function is not
1095+
* defined.
10961096
*/
10971097
StrategyNumber
10981098
gisttranslatecmptype(CompareType cmptype, Oid opfamily)
@@ -1101,7 +1101,7 @@ gisttranslatecmptype(CompareType cmptype, Oid opfamily)
11011101
Datum result;
11021102

11031103
/* Check whether the function is provided. */
1104-
funcid = get_opfamily_proc(opfamily, ANYOID, ANYOID, GIST_STRATNUM_PROC);
1104+
funcid = get_opfamily_proc(opfamily, ANYOID, ANYOID, GIST_TRANSLATE_CMPTYPE_PROC);
11051105
if (!OidIsValid(funcid))
11061106
return InvalidStrategy;
11071107

src/backend/access/gist/gistvalidate.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ gistvalidate(Oid opclassoid)
138138
ok = check_amproc_signature(procform->amproc, VOIDOID, true,
139139
1, 1, INTERNALOID);
140140
break;
141-
case GIST_STRATNUM_PROC:
141+
case GIST_TRANSLATE_CMPTYPE_PROC:
142142
ok = check_amproc_signature(procform->amproc, INT2OID, true,
143143
1, 1, INT4OID) &&
144144
procform->amproclefttype == ANYOID &&
@@ -265,7 +265,7 @@ gistvalidate(Oid opclassoid)
265265
if (i == GIST_DISTANCE_PROC || i == GIST_FETCH_PROC ||
266266
i == GIST_COMPRESS_PROC || i == GIST_DECOMPRESS_PROC ||
267267
i == GIST_OPTIONS_PROC || i == GIST_SORTSUPPORT_PROC ||
268-
i == GIST_STRATNUM_PROC)
268+
i == GIST_TRANSLATE_CMPTYPE_PROC)
269269
continue; /* optional methods */
270270
ereport(INFO,
271271
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
@@ -336,7 +336,7 @@ gistadjustmembers(Oid opfamilyoid,
336336
case GIST_FETCH_PROC:
337337
case GIST_OPTIONS_PROC:
338338
case GIST_SORTSUPPORT_PROC:
339-
case GIST_STRATNUM_PROC:
339+
case GIST_TRANSLATE_CMPTYPE_PROC:
340340
/* Optional, so force it to be a soft family dependency */
341341
op->ref_is_hard = false;
342342
op->ref_is_family = true;

src/include/access/gist.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#define GIST_FETCH_PROC 9
4141
#define GIST_OPTIONS_PROC 10
4242
#define GIST_SORTSUPPORT_PROC 11
43-
#define GIST_STRATNUM_PROC 12
43+
#define GIST_TRANSLATE_CMPTYPE_PROC 12
4444
#define GISTNProcs 12
4545

4646
/*

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
*/
5858

5959
/* yyyymmddN */
60-
#define CATALOG_VERSION_NO 202505071
60+
#define CATALOG_VERSION_NO 202506021
6161

6262
#endif

0 commit comments

Comments
 (0)