Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7406ab6

Browse files
committed
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 isused by the opclass (since no particular numbers are actuallyrequired). We will use this to support temporal PRIMARYKEY/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. Itupdates btree_gist from 1.7 to 1.8, adding the support function forall its opclasses.(previously committed as6db4598, reverted by8aee330; this isessentially 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
1 parent95d6e9a commit7406ab6

File tree

17 files changed

+273
-8
lines changed

17 files changed

+273
-8
lines changed

‎contrib/btree_gist/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ EXTENSION = btree_gist
3333
DATA = btree_gist--1.0--1.1.sql\
3434
btree_gist--1.1--1.2.sql btree_gist--1.2.sql btree_gist--1.2--1.3.sql\
3535
btree_gist--1.3--1.4.sql btree_gist--1.4--1.5.sql\
36-
btree_gist--1.5--1.6.sql btree_gist--1.6--1.7.sql
36+
btree_gist--1.5--1.6.sql btree_gist--1.6--1.7.sql\
37+
btree_gist--1.7--1.8.sql
3738
PGFILEDESC = "btree_gist - B-tree equivalent GiST operator classes"
3839

3940
REGRESS = init int2 int4 int8 float4 float8 cash oid timestamp timestamptz\
4041
time timetz date interval macaddr macaddr8 inet cidr text varchar char\
41-
bytea bit varbit numeric uuid not_equal enum bool partitions
42+
bytea bit varbit numeric uuid not_equal enum bool partitions\
43+
stratnum
4244

4345
SHLIB_LINK +=$(filter -lm,$(LIBS))
4446

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/* contrib/btree_gist/btree_gist--1.7--1.8.sql*/
2+
3+
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
4+
\echo Use"ALTER EXTENSION btree_gist UPDATE TO '1.8'" to load this file. \quit
5+
6+
CREATEFUNCTIONgist_stratnum_btree(smallint)
7+
RETURNSsmallint
8+
AS'MODULE_PATHNAME'
9+
LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT;
10+
11+
ALTEROPERATOR FAMILY gist_oid_ops USING gist ADD
12+
FUNCTION12 (oid,oid) gist_stratnum_btree (int2) ;
13+
14+
ALTEROPERATOR FAMILY gist_int2_ops USING gist ADD
15+
FUNCTION12 (int2, int2) gist_stratnum_btree (int2) ;
16+
17+
ALTEROPERATOR FAMILY gist_int4_ops USING gist ADD
18+
FUNCTION12 (int4, int4) gist_stratnum_btree (int2) ;
19+
20+
ALTEROPERATOR FAMILY gist_int8_ops USING gist ADD
21+
FUNCTION12 (int8, int8) gist_stratnum_btree (int2) ;
22+
23+
ALTEROPERATOR FAMILY gist_float4_ops USING gist ADD
24+
FUNCTION12 (float4, float4) gist_stratnum_btree (int2) ;
25+
26+
ALTEROPERATOR FAMILY gist_float8_ops USING gist ADD
27+
FUNCTION12 (float8, float8) gist_stratnum_btree (int2) ;
28+
29+
ALTEROPERATOR FAMILY gist_timestamp_ops USING gist ADD
30+
FUNCTION12 (timestamp,timestamp) gist_stratnum_btree (int2) ;
31+
32+
ALTEROPERATOR FAMILY gist_timestamptz_ops USING gist ADD
33+
FUNCTION12 (timestamptz,timestamptz) gist_stratnum_btree (int2) ;
34+
35+
ALTEROPERATOR FAMILY gist_time_ops USING gist ADD
36+
FUNCTION12 (time,time) gist_stratnum_btree (int2) ;
37+
38+
ALTEROPERATOR FAMILY gist_date_ops USING gist ADD
39+
FUNCTION12 (date,date) gist_stratnum_btree (int2) ;
40+
41+
ALTEROPERATOR FAMILY gist_interval_ops USING gist ADD
42+
FUNCTION12 (interval, interval) gist_stratnum_btree (int2) ;
43+
44+
ALTEROPERATOR FAMILY gist_cash_ops USING gist ADD
45+
FUNCTION12 (money,money) gist_stratnum_btree (int2) ;
46+
47+
ALTEROPERATOR FAMILY gist_macaddr_ops USING gist ADD
48+
FUNCTION12 (macaddr,macaddr) gist_stratnum_btree (int2) ;
49+
50+
ALTEROPERATOR FAMILY gist_text_ops USING gist ADD
51+
FUNCTION12 (text,text) gist_stratnum_btree (int2) ;
52+
53+
ALTEROPERATOR FAMILY gist_bpchar_ops USING gist ADD
54+
FUNCTION12 (bpchar, bpchar) gist_stratnum_btree (int2) ;
55+
56+
ALTEROPERATOR FAMILY gist_bytea_ops USING gist ADD
57+
FUNCTION12 (bytea,bytea) gist_stratnum_btree (int2) ;
58+
59+
ALTEROPERATOR FAMILY gist_numeric_ops USING gist ADD
60+
FUNCTION12 (numeric,numeric) gist_stratnum_btree (int2) ;
61+
62+
ALTEROPERATOR FAMILY gist_bit_ops USING gist ADD
63+
FUNCTION12 (bit,bit) gist_stratnum_btree (int2) ;
64+
65+
ALTEROPERATOR FAMILY gist_vbit_ops USING gist ADD
66+
FUNCTION12 (varbit, varbit) gist_stratnum_btree (int2) ;
67+
68+
ALTEROPERATOR FAMILY gist_inet_ops USING gist ADD
69+
FUNCTION12 (inet,inet) gist_stratnum_btree (int2) ;
70+
71+
ALTEROPERATOR FAMILY gist_cidr_ops USING gist ADD
72+
FUNCTION12 (cidr,cidr) gist_stratnum_btree (int2) ;
73+
74+
ALTEROPERATOR FAMILY gist_timetz_ops USING gist ADD
75+
FUNCTION12 (timetz, timetz) gist_stratnum_btree (int2) ;
76+
77+
ALTEROPERATOR FAMILY gist_uuid_ops USING gist ADD
78+
FUNCTION12 (uuid, uuid) gist_stratnum_btree (int2) ;
79+
80+
ALTEROPERATOR FAMILY gist_macaddr8_ops USING gist ADD
81+
FUNCTION12 (macaddr8, macaddr8) gist_stratnum_btree (int2) ;
82+
83+
ALTEROPERATOR FAMILY gist_enum_ops USING gist ADD
84+
FUNCTION12 (anyenum, anyenum) gist_stratnum_btree (int2) ;
85+
86+
ALTEROPERATOR FAMILY gist_bool_ops USING gist ADD
87+
FUNCTION12 (bool, bool) gist_stratnum_btree (int2) ;

‎contrib/btree_gist/btree_gist.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
*/
44
#include"postgres.h"
55

6+
#include"access/stratnum.h"
67
#include"utils/builtins.h"
78

89
PG_MODULE_MAGIC;
910

1011
PG_FUNCTION_INFO_V1(gbt_decompress);
1112
PG_FUNCTION_INFO_V1(gbtreekey_in);
1213
PG_FUNCTION_INFO_V1(gbtreekey_out);
14+
PG_FUNCTION_INFO_V1(gist_stratnum_btree);
1315

1416
/**************************************************
1517
* In/Out for keys
@@ -51,3 +53,28 @@ gbt_decompress(PG_FUNCTION_ARGS)
5153
{
5254
PG_RETURN_POINTER(PG_GETARG_POINTER(0));
5355
}
56+
57+
/*
58+
* Returns the btree number for supported operators, otherwise invalid.
59+
*/
60+
Datum
61+
gist_stratnum_btree(PG_FUNCTION_ARGS)
62+
{
63+
StrategyNumberstrat=PG_GETARG_UINT16(0);
64+
65+
switch (strat)
66+
{
67+
caseRTEqualStrategyNumber:
68+
PG_RETURN_UINT16(BTEqualStrategyNumber);
69+
caseRTLessStrategyNumber:
70+
PG_RETURN_UINT16(BTLessStrategyNumber);
71+
caseRTLessEqualStrategyNumber:
72+
PG_RETURN_UINT16(BTLessEqualStrategyNumber);
73+
caseRTGreaterStrategyNumber:
74+
PG_RETURN_UINT16(BTGreaterStrategyNumber);
75+
caseRTGreaterEqualStrategyNumber:
76+
PG_RETURN_UINT16(BTGreaterEqualStrategyNumber);
77+
default:
78+
PG_RETURN_UINT16(InvalidStrategy);
79+
}
80+
}

‎contrib/btree_gist/btree_gist.control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# btree_gist extension
22
comment = 'support for indexing common datatypes in GiST'
3-
default_version = '1.7'
3+
default_version = '1.8'
44
module_pathname = '$libdir/btree_gist'
55
relocatable = true
66
trusted = true
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- test stratnum support func
2+
SELECT gist_stratnum_btree(3::smallint);
3+
gist_stratnum_btree
4+
---------------------
5+
0
6+
(1 row)
7+
8+
SELECT gist_stratnum_btree(18::smallint);
9+
gist_stratnum_btree
10+
---------------------
11+
3
12+
(1 row)
13+

‎contrib/btree_gist/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ install_data(
5050
'btree_gist--1.4--1.5.sql',
5151
'btree_gist--1.5--1.6.sql',
5252
'btree_gist--1.6--1.7.sql',
53+
'btree_gist--1.7--1.8.sql',
5354
kwargs: contrib_data_args,
5455
)
5556

@@ -89,6 +90,7 @@ tests += {
8990
'enum',
9091
'bool',
9192
'partitions',
93+
'stratnum',
9294
],
9395
},
9496
}

‎contrib/btree_gist/sql/stratnum.sql

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

‎doc/src/sgml/gist.sgml

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ CREATE INDEX ON my_table USING GIST (my_inet_column inet_ops);
266266

267267
<para>
268268
There are five methods that an index operator class for
269-
<acronym>GiST</acronym> must provide, andsix that are optional.
269+
<acronym>GiST</acronym> must provide, andseven that are optional.
270270
Correctness of the index is ensured
271271
by proper implementation of the <function>same</function>, <function>consistent</function>
272272
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);
289289
user-specified parameters.
290290
The optional eleventh method <function>sortsupport</function> is used to
291291
speed up building a <acronym>GiST</acronym> index.
292+
The optional twelfth method <function>stratnum</function> is used to
293+
translate well-known <literal>RT*StrategyNumber</literal>s (from
294+
<filename>src/include/access/stratnum.h</filename>) into strategy numbers
295+
used by the operator class.
292296
</para>
293297

294298
<variablelist>
@@ -1163,6 +1167,65 @@ my_sortsupport(PG_FUNCTION_ARGS)
11631167
</para>
11641168
</listitem>
11651169
</varlistentry>
1170+
1171+
<varlistentry>
1172+
<term><function>stratnum</function></term>
1173+
<listitem>
1174+
<para>
1175+
Given an <literal>RT*StrategyNumber</literal> value from
1176+
<filename>src/include/access/stratnum.h</filename>, returns a strategy
1177+
number used by this operator class for matching functionality. The
1178+
function should return <literal>InvalidStrategy</literal> if the
1179+
operator class has no matching strategy.
1180+
</para>
1181+
1182+
<para>
1183+
The <acronym>SQL</acronym> declaration of the function must look like
1184+
this:
1185+
1186+
<programlisting>
1187+
CREATE OR REPLACE FUNCTION my_stratnum(integer)
1188+
RETURNS integer
1189+
AS 'MODULE_PATHNAME'
1190+
LANGUAGE C STRICT;
1191+
</programlisting>
1192+
</para>
1193+
1194+
<para>
1195+
The matching code in the C module could then follow this skeleton:
1196+
1197+
<programlisting>
1198+
PG_FUNCTION_INFO_V1(my_stratnum);
1199+
1200+
Datum
1201+
my_stratnum(PG_FUNCTION_ARGS)
1202+
{
1203+
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(1);
1204+
StrategyNumber ret = InvalidStrategy;
1205+
1206+
switch (strategy)
1207+
{
1208+
case RTEqualStrategyNumber:
1209+
ret = BTEqualStrategyNumber;
1210+
}
1211+
1212+
PG_RETURN_UINT16(ret);
1213+
}
1214+
</programlisting>
1215+
</para>
1216+
1217+
<para>
1218+
One translation function is provided by
1219+
<productname>PostgreSQL</productname>:
1220+
<literal>gist_stratnum_identity</literal> is for operator classes that
1221+
already use the <literal>RT*StrategyNumber</literal> constants. It
1222+
returns whatever is passed to it. The <literal>btree_gist</literal>
1223+
extension defines a second translation function,
1224+
<literal>gist_stratnum_btree</literal>, for operator classes that use
1225+
the <literal>BT*StrategyNumber</literal> constants.
1226+
</para>
1227+
</listitem>
1228+
</varlistentry>
11661229
</variablelist>
11671230

11681231
<para>

‎doc/src/sgml/xindex.sgml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@
508508
</table>
509509

510510
<para>
511-
GiST indexes haveeleven support functions,six of which are optional,
511+
GiST indexes havetwelve support functions,seven of which are optional,
512512
as shown in <xref linkend="xindex-gist-support-table"/>.
513513
(For more information see <xref linkend="gist"/>.)
514514
</para>
@@ -590,6 +590,12 @@
590590
(optional)</entry>
591591
<entry>11</entry>
592592
</row>
593+
<row>
594+
<entry><function>stratnum</function></entry>
595+
<entry>translate well-known strategy numbers to ones
596+
used by the operator class (optional)</entry>
597+
<entry>12</entry>
598+
</row>
593599
</tbody>
594600
</tgroup>
595601
</table>

‎src/backend/access/gist/gistutil.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include"common/pg_prng.h"
2222
#include"storage/indexfsm.h"
2323
#include"utils/float.h"
24+
#include"utils/fmgrprotos.h"
2425
#include"utils/lsyscache.h"
2526
#include"utils/rel.h"
2627
#include"utils/snapmgr.h"
@@ -1055,3 +1056,16 @@ gistGetFakeLSN(Relation rel)
10551056
returnGetFakeLSNForUnloggedRel();
10561057
}
10571058
}
1059+
1060+
/*
1061+
* Returns the same number that was received.
1062+
*
1063+
* This is for GiST opclasses that use the RT*StrategyNumber constants.
1064+
*/
1065+
Datum
1066+
gist_stratnum_identity(PG_FUNCTION_ARGS)
1067+
{
1068+
StrategyNumberstrat=PG_GETARG_UINT16(0);
1069+
1070+
PG_RETURN_UINT16(strat);
1071+
}

‎src/backend/access/gist/gistvalidate.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ gistvalidate(Oid opclassoid)
146146
ok=check_amproc_signature(procform->amproc,VOIDOID, true,
147147
1,1,INTERNALOID);
148148
break;
149+
caseGIST_STRATNUM_PROC:
150+
ok=check_amproc_signature(procform->amproc,INT2OID, true,
151+
1,1,INT2OID);
152+
break;
149153
default:
150154
ereport(INFO,
151155
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
@@ -266,7 +270,8 @@ gistvalidate(Oid opclassoid)
266270
continue;/* got it */
267271
if (i==GIST_DISTANCE_PROC||i==GIST_FETCH_PROC||
268272
i==GIST_COMPRESS_PROC||i==GIST_DECOMPRESS_PROC||
269-
i==GIST_OPTIONS_PROC||i==GIST_SORTSUPPORT_PROC)
273+
i==GIST_OPTIONS_PROC||i==GIST_SORTSUPPORT_PROC||
274+
i==GIST_STRATNUM_PROC)
270275
continue;/* optional methods */
271276
ereport(INFO,
272277
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
@@ -338,6 +343,7 @@ gistadjustmembers(Oid opfamilyoid,
338343
caseGIST_FETCH_PROC:
339344
caseGIST_OPTIONS_PROC:
340345
caseGIST_SORTSUPPORT_PROC:
346+
caseGIST_STRATNUM_PROC:
341347
/* Optional, so force it to be a soft family dependency */
342348
op->ref_is_hard= false;
343349
op->ref_is_family= true;

‎src/include/access/gist.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
#defineGIST_FETCH_PROC9
3939
#defineGIST_OPTIONS_PROC10
4040
#defineGIST_SORTSUPPORT_PROC11
41-
#defineGISTNProcs11
41+
#defineGIST_STRATNUM_PROC12
42+
#defineGISTNProcs12
4243

4344
/*
4445
* Page opaque data in a GiST index page.

‎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-
#defineCATALOG_VERSION_NO202409122
60+
#defineCATALOG_VERSION_NO202409171
6161

6262
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp