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

Commit630f9a4

Browse files
committed
Change gist stratnum function to use CompareType
This changes commit7406ab6 in that the gist strategy numbermapping support function is changed to use the CompareType enum asinput, instead of the "well-known" RT*StrategyNumber strategy numbers.This is a bit cleaner, since you are not dealing with two sets ofstrategy numbers. Also, this will enable us to subsume this systeminto a more general system of using CompareType to define operatorsemantics across index methods.Discussion:https://www.postgresql.org/message-id/flat/E72EAA49-354D-4C2E-8EB9-255197F55330@enterprisedb.com
1 parent6339f64 commit630f9a4

File tree

19 files changed

+145
-126
lines changed

19 files changed

+145
-126
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-
CREATEFUNCTIONgist_stratnum_btree(smallint)
6+
CREATEFUNCTIONgist_stratnum_btree(int)
77
RETURNSsmallint
88
AS'MODULE_PATHNAME'
99
LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT;
1010

1111
ALTEROPERATOR FAMILY gist_oid_ops USING gist ADD
12-
FUNCTION12 (oid,oid) gist_stratnum_btree (int2) ;
12+
FUNCTION12 (oid,oid) gist_stratnum_btree (int) ;
1313

1414
ALTEROPERATOR FAMILY gist_int2_ops USING gist ADD
15-
FUNCTION12 (int2, int2) gist_stratnum_btree (int2) ;
15+
FUNCTION12 (int2, int2) gist_stratnum_btree (int) ;
1616

1717
ALTEROPERATOR FAMILY gist_int4_ops USING gist ADD
18-
FUNCTION12 (int4, int4) gist_stratnum_btree (int2) ;
18+
FUNCTION12 (int4, int4) gist_stratnum_btree (int) ;
1919

2020
ALTEROPERATOR FAMILY gist_int8_ops USING gist ADD
21-
FUNCTION12 (int8, int8) gist_stratnum_btree (int2) ;
21+
FUNCTION12 (int8, int8) gist_stratnum_btree (int) ;
2222

2323
ALTEROPERATOR FAMILY gist_float4_ops USING gist ADD
24-
FUNCTION12 (float4, float4) gist_stratnum_btree (int2) ;
24+
FUNCTION12 (float4, float4) gist_stratnum_btree (int) ;
2525

2626
ALTEROPERATOR FAMILY gist_float8_ops USING gist ADD
27-
FUNCTION12 (float8, float8) gist_stratnum_btree (int2) ;
27+
FUNCTION12 (float8, float8) gist_stratnum_btree (int) ;
2828

2929
ALTEROPERATOR FAMILY gist_timestamp_ops USING gist ADD
30-
FUNCTION12 (timestamp,timestamp) gist_stratnum_btree (int2) ;
30+
FUNCTION12 (timestamp,timestamp) gist_stratnum_btree (int) ;
3131

3232
ALTEROPERATOR FAMILY gist_timestamptz_ops USING gist ADD
33-
FUNCTION12 (timestamptz,timestamptz) gist_stratnum_btree (int2) ;
33+
FUNCTION12 (timestamptz,timestamptz) gist_stratnum_btree (int) ;
3434

3535
ALTEROPERATOR FAMILY gist_time_ops USING gist ADD
36-
FUNCTION12 (time,time) gist_stratnum_btree (int2) ;
36+
FUNCTION12 (time,time) gist_stratnum_btree (int) ;
3737

3838
ALTEROPERATOR FAMILY gist_date_ops USING gist ADD
39-
FUNCTION12 (date,date) gist_stratnum_btree (int2) ;
39+
FUNCTION12 (date,date) gist_stratnum_btree (int) ;
4040

4141
ALTEROPERATOR FAMILY gist_interval_ops USING gist ADD
42-
FUNCTION12 (interval, interval) gist_stratnum_btree (int2) ;
42+
FUNCTION12 (interval, interval) gist_stratnum_btree (int) ;
4343

4444
ALTEROPERATOR FAMILY gist_cash_ops USING gist ADD
45-
FUNCTION12 (money,money) gist_stratnum_btree (int2) ;
45+
FUNCTION12 (money,money) gist_stratnum_btree (int) ;
4646

4747
ALTEROPERATOR FAMILY gist_macaddr_ops USING gist ADD
48-
FUNCTION12 (macaddr,macaddr) gist_stratnum_btree (int2) ;
48+
FUNCTION12 (macaddr,macaddr) gist_stratnum_btree (int) ;
4949

5050
ALTEROPERATOR FAMILY gist_text_ops USING gist ADD
51-
FUNCTION12 (text,text) gist_stratnum_btree (int2) ;
51+
FUNCTION12 (text,text) gist_stratnum_btree (int) ;
5252

5353
ALTEROPERATOR FAMILY gist_bpchar_ops USING gist ADD
54-
FUNCTION12 (bpchar, bpchar) gist_stratnum_btree (int2) ;
54+
FUNCTION12 (bpchar, bpchar) gist_stratnum_btree (int) ;
5555

5656
ALTEROPERATOR FAMILY gist_bytea_ops USING gist ADD
57-
FUNCTION12 (bytea,bytea) gist_stratnum_btree (int2) ;
57+
FUNCTION12 (bytea,bytea) gist_stratnum_btree (int) ;
5858

5959
ALTEROPERATOR FAMILY gist_numeric_ops USING gist ADD
60-
FUNCTION12 (numeric,numeric) gist_stratnum_btree (int2) ;
60+
FUNCTION12 (numeric,numeric) gist_stratnum_btree (int) ;
6161

6262
ALTEROPERATOR FAMILY gist_bit_ops USING gist ADD
63-
FUNCTION12 (bit,bit) gist_stratnum_btree (int2) ;
63+
FUNCTION12 (bit,bit) gist_stratnum_btree (int) ;
6464

6565
ALTEROPERATOR FAMILY gist_vbit_ops USING gist ADD
66-
FUNCTION12 (varbit, varbit) gist_stratnum_btree (int2) ;
66+
FUNCTION12 (varbit, varbit) gist_stratnum_btree (int) ;
6767

6868
ALTEROPERATOR FAMILY gist_inet_ops USING gist ADD
69-
FUNCTION12 (inet,inet) gist_stratnum_btree (int2) ;
69+
FUNCTION12 (inet,inet) gist_stratnum_btree (int) ;
7070

7171
ALTEROPERATOR FAMILY gist_cidr_ops USING gist ADD
72-
FUNCTION12 (cidr,cidr) gist_stratnum_btree (int2) ;
72+
FUNCTION12 (cidr,cidr) gist_stratnum_btree (int) ;
7373

7474
ALTEROPERATOR FAMILY gist_timetz_ops USING gist ADD
75-
FUNCTION12 (timetz, timetz) gist_stratnum_btree (int2) ;
75+
FUNCTION12 (timetz, timetz) gist_stratnum_btree (int) ;
7676

7777
ALTEROPERATOR FAMILY gist_uuid_ops USING gist ADD
78-
FUNCTION12 (uuid, uuid) gist_stratnum_btree (int2) ;
78+
FUNCTION12 (uuid, uuid) gist_stratnum_btree (int) ;
7979

8080
ALTEROPERATOR FAMILY gist_macaddr8_ops USING gist ADD
81-
FUNCTION12 (macaddr8, macaddr8) gist_stratnum_btree (int2) ;
81+
FUNCTION12 (macaddr8, macaddr8) gist_stratnum_btree (int) ;
8282

8383
ALTEROPERATOR FAMILY gist_enum_ops USING gist ADD
84-
FUNCTION12 (anyenum, anyenum) gist_stratnum_btree (int2) ;
84+
FUNCTION12 (anyenum, anyenum) gist_stratnum_btree (int) ;
8585

8686
ALTEROPERATOR FAMILY gist_bool_ops USING gist ADD
87-
FUNCTION12 (bool, bool) gist_stratnum_btree (int2) ;
87+
FUNCTION12 (bool, bool) gist_stratnum_btree (int) ;

‎contrib/btree_gist/btree_gist.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include"postgres.h"
55

66
#include"access/stratnum.h"
7+
#include"nodes/primnodes.h"
78
#include"utils/builtins.h"
89

910
PG_MODULE_MAGIC;
@@ -60,19 +61,19 @@ gbt_decompress(PG_FUNCTION_ARGS)
6061
Datum
6162
gist_stratnum_btree(PG_FUNCTION_ARGS)
6263
{
63-
StrategyNumberstrat=PG_GETARG_UINT16(0);
64+
CompareTypecmptype=PG_GETARG_INT32(0);
6465

65-
switch (strat)
66+
switch (cmptype)
6667
{
67-
caseRTEqualStrategyNumber:
68+
caseCOMPARE_EQ:
6869
PG_RETURN_UINT16(BTEqualStrategyNumber);
69-
caseRTLessStrategyNumber:
70+
caseCOMPARE_LT:
7071
PG_RETURN_UINT16(BTLessStrategyNumber);
71-
caseRTLessEqualStrategyNumber:
72+
caseCOMPARE_LE:
7273
PG_RETURN_UINT16(BTLessEqualStrategyNumber);
73-
caseRTGreaterStrategyNumber:
74+
caseCOMPARE_GT:
7475
PG_RETURN_UINT16(BTGreaterStrategyNumber);
75-
caseRTGreaterEqualStrategyNumber:
76+
caseCOMPARE_GE:
7677
PG_RETURN_UINT16(BTGreaterEqualStrategyNumber);
7778
default:
7879
PG_RETURN_UINT16(InvalidStrategy);

‎contrib/btree_gist/expected/stratnum.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
-- test stratnum support func
2-
SELECT gist_stratnum_btree(3::smallint);
2+
SELECT gist_stratnum_btree(7);
33
gist_stratnum_btree
44
---------------------
55
0
66
(1 row)
77

8-
SELECT gist_stratnum_btree(18::smallint);
8+
SELECT gist_stratnum_btree(3);
99
gist_stratnum_btree
1010
---------------------
1111
3

‎contrib/btree_gist/sql/stratnum.sql

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

‎doc/src/sgml/gist.sgml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ CREATE INDEX ON my_table USING GIST (my_inet_column inet_ops);
290290
The optional eleventh method <function>sortsupport</function> is used to
291291
speed up building a <acronym>GiST</acronym> index.
292292
The optional twelfth method <function>stratnum</function> is used to
293-
translatewell-known <literal>RT*StrategyNumber</literal>s (from
294-
<filename>src/include/access/stratnum.h</filename>) into strategy numbers
293+
translatecompare types (from
294+
<filename>src/include/nodes/primnodes.h</filename>) into strategy numbers
295295
used by the operator class. This lets the core code look up operators for
296296
temporal constraint indexes.
297297
</para>
@@ -1173,8 +1173,8 @@ my_sortsupport(PG_FUNCTION_ARGS)
11731173
<term><function>stratnum</function></term>
11741174
<listitem>
11751175
<para>
1176-
Givenan <literal>RT*StrategyNumber</literal> value from
1177-
<filename>src/include/access/stratnum.h</filename>, returns a strategy
1176+
Givena <literal>CompareType</literal> value from
1177+
<filename>src/include/nodes/primnodes.h</filename>, returns a strategy
11781178
number used by this operator class for matching functionality. The
11791179
function should return <literal>InvalidStrategy</literal> if the
11801180
operator class has no matching strategy.
@@ -1184,7 +1184,7 @@ my_sortsupport(PG_FUNCTION_ARGS)
11841184
This is used for temporal index constraints (i.e., <literal>PRIMARY
11851185
KEY</literal> and <literal>UNIQUE</literal>). If the operator class
11861186
provides this function and it returns results for
1187-
<literal>RTEqualStrategyNumber</literal>, it can be used in the
1187+
<literal>COMPARE_EQ</literal>, it can be used in the
11881188
non-<literal>WITHOUT OVERLAPS</literal> part(s) of an index constraint.
11891189
</para>
11901190

@@ -1194,7 +1194,7 @@ my_sortsupport(PG_FUNCTION_ARGS)
11941194

11951195
<programlisting>
11961196
CREATE OR REPLACE FUNCTION my_stratnum(integer)
1197-
RETURNSinteger
1197+
RETURNSsmallint
11981198
AS 'MODULE_PATHNAME'
11991199
LANGUAGE C STRICT;
12001200
</programlisting>
@@ -1209,12 +1209,12 @@ PG_FUNCTION_INFO_V1(my_stratnum);
12091209
Datum
12101210
my_stratnum(PG_FUNCTION_ARGS)
12111211
{
1212-
StrategyNumber strategy =(StrategyNumber) PG_GETARG_UINT16(1);
1212+
CompareType cmptype =PG_GETARG_INT32(0);
12131213
StrategyNumber ret = InvalidStrategy;
12141214

1215-
switch (strategy)
1215+
switch (cmptype)
12161216
{
1217-
caseRTEqualStrategyNumber:
1217+
caseCOMPARE_EQ:
12181218
ret = BTEqualStrategyNumber;
12191219
}
12201220

@@ -1226,9 +1226,9 @@ my_stratnum(PG_FUNCTION_ARGS)
12261226
<para>
12271227
One translation function is provided by
12281228
<productname>PostgreSQL</productname>:
1229-
<literal>gist_stratnum_identity</literal> is for operator classes that
1230-
alreadyuse the <literal>RT*StrategyNumber</literal> constants. It
1231-
returns whatever is passed to it.The <literal>btree_gist</literal>
1229+
<literal>gist_stratnum_common</literal> is for operator classes that
1230+
use the <literal>RT*StrategyNumber</literal> constants.
1231+
The <literal>btree_gist</literal>
12321232
extension defines a second translation function,
12331233
<literal>gist_stratnum_btree</literal>, for operator classes that use
12341234
the <literal>BT*StrategyNumber</literal> constants.

‎doc/src/sgml/xindex.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@
592592
</row>
593593
<row>
594594
<entry><function>stratnum</function></entry>
595-
<entry>translatewell-known strategy numberstoones
595+
<entry>translatecompare typestostrategy numbers
596596
used by the operator class (optional)</entry>
597597
<entry>12</entry>
598598
</row>

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

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

10601060
/*
1061-
* Returns the same number that was received.
1062-
*
1063-
* This is for GiST opclasses that use the RT*StrategyNumber constants.
1061+
* This is a stratnum support function for GiST opclasses that use the
1062+
* RT*StrategyNumber constants.
10641063
*/
10651064
Datum
1066-
gist_stratnum_identity(PG_FUNCTION_ARGS)
1065+
gist_stratnum_common(PG_FUNCTION_ARGS)
10671066
{
1068-
StrategyNumberstrat=PG_GETARG_UINT16(0);
1067+
CompareTypecmptype=PG_GETARG_INT32(0);
10691068

1070-
PG_RETURN_UINT16(strat);
1069+
switch (cmptype)
1070+
{
1071+
caseCOMPARE_EQ:
1072+
PG_RETURN_UINT16(RTEqualStrategyNumber);
1073+
caseCOMPARE_LT:
1074+
PG_RETURN_UINT16(RTLessStrategyNumber);
1075+
caseCOMPARE_LE:
1076+
PG_RETURN_UINT16(RTLessEqualStrategyNumber);
1077+
caseCOMPARE_GT:
1078+
PG_RETURN_UINT16(RTGreaterStrategyNumber);
1079+
caseCOMPARE_GE:
1080+
PG_RETURN_UINT16(RTGreaterEqualStrategyNumber);
1081+
caseCOMPARE_OVERLAP:
1082+
PG_RETURN_UINT16(RTOverlapStrategyNumber);
1083+
caseCOMPARE_CONTAINED_BY:
1084+
PG_RETURN_UINT16(RTContainedByStrategyNumber);
1085+
default:
1086+
PG_RETURN_UINT16(InvalidStrategy);
1087+
}
10711088
}
10721089

10731090
/*
1074-
* Returns the opclass's private stratnum used for the givenstrategy.
1091+
* Returns the opclass's private stratnum used for the givencompare type.
10751092
*
10761093
* Calls the opclass's GIST_STRATNUM_PROC support function, if any,
10771094
* and returns the result.
10781095
* Returns InvalidStrategy if the function is not defined.
10791096
*/
10801097
StrategyNumber
1081-
GistTranslateStratnum(Oidopclass,StrategyNumberstrat)
1098+
GistTranslateStratnum(Oidopclass,CompareTypecmptype)
10821099
{
10831100
Oidopfamily;
10841101
Oidopcintype;
@@ -1095,6 +1112,6 @@ GistTranslateStratnum(Oid opclass, StrategyNumber strat)
10951112
returnInvalidStrategy;
10961113

10971114
/* Ask the translation function */
1098-
result=OidFunctionCall1Coll(funcid,InvalidOid,UInt16GetDatum(strat));
1115+
result=OidFunctionCall1Coll(funcid,InvalidOid,Int32GetDatum(cmptype));
10991116
returnDatumGetUInt16(result);
11001117
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ gistvalidate(Oid opclassoid)
148148
break;
149149
caseGIST_STRATNUM_PROC:
150150
ok=check_amproc_signature(procform->amproc,INT2OID, true,
151-
1,1,INT2OID);
151+
1,1,INT4OID);
152152
break;
153153
default:
154154
ereport(INFO,

‎src/backend/catalog/pg_constraint.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,22 +1647,22 @@ FindFKPeriodOpers(Oid opclass,
16471647
* of the old value, then we can treat the attribute as if it didn't
16481648
* change, and skip the RI check.
16491649
*/
1650-
strat=RTContainedByStrategyNumber;
1651-
GetOperatorFromWellKnownStrategy(opclass,
1652-
InvalidOid,
1653-
containedbyoperoid,
1654-
&strat);
1650+
GetOperatorFromCompareType(opclass,
1651+
InvalidOid,
1652+
COMPARE_CONTAINED_BY,
1653+
containedbyoperoid,
1654+
&strat);
16551655

16561656
/*
16571657
* Now look up the ContainedBy operator. Its left arg must be the type of
16581658
* the column (or rather of the opclass). Its right arg must match the
16591659
* return type of the support proc.
16601660
*/
1661-
strat=RTContainedByStrategyNumber;
1662-
GetOperatorFromWellKnownStrategy(opclass,
1663-
ANYMULTIRANGEOID,
1664-
aggedcontainedbyoperoid,
1665-
&strat);
1661+
GetOperatorFromCompareType(opclass,
1662+
ANYMULTIRANGEOID,
1663+
COMPARE_CONTAINED_BY,
1664+
aggedcontainedbyoperoid,
1665+
&strat);
16661666
}
16671667

16681668
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp