From 7406ab623fee1addcb21c881afecbe638a0d56e9 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 17 Sep 2024 10:19:26 +0200 Subject: 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 is used by the opclass (since no particular numbers are actually required). We will use this to support temporal PRIMARY KEY/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. It updates btree_gist from 1.7 to 1.8, adding the support function for all its opclasses. (previously committed as 6db4598fcb8, reverted by 8aee330af55; this is essentially unchanged from those) Author: Paul A. Jungwirth Reviewed-by: Peter Eisentraut Reviewed-by: jian he Discussion: https://www.postgresql.org/message-id/flat/CA+renyUApHgSZF9-nd-a0+OPGharLQLO=mDHcY4_qQ0+noCUVg@mail.gmail.com --- doc/src/sgml/gist.sgml | 65 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) (limited to 'doc/src/sgml/gist.sgml') diff --git a/doc/src/sgml/gist.sgml b/doc/src/sgml/gist.sgml index 39c7bf370d6..f789824c83b 100644 --- a/doc/src/sgml/gist.sgml +++ b/doc/src/sgml/gist.sgml @@ -266,7 +266,7 @@ CREATE INDEX ON my_table USING GIST (my_inet_column inet_ops); There are five methods that an index operator class for - GiST must provide, and six that are optional. + GiST must provide, and seven that are optional. Correctness of the index is ensured by proper implementation of the same, consistent and union methods, while efficiency (size and speed) of the @@ -289,6 +289,10 @@ CREATE INDEX ON my_table USING GIST (my_inet_column inet_ops); user-specified parameters. The optional eleventh method sortsupport is used to speed up building a GiST index. + The optional twelfth method stratnum is used to + translate well-known RT*StrategyNumbers (from + src/include/access/stratnum.h) into strategy numbers + used by the operator class. @@ -1163,6 +1167,65 @@ my_sortsupport(PG_FUNCTION_ARGS) + + + stratnum + + + Given an RT*StrategyNumber value from + src/include/access/stratnum.h, returns a strategy + number used by this operator class for matching functionality. The + function should return InvalidStrategy if the + operator class has no matching strategy. + + + + The SQL declaration of the function must look like + this: + + +CREATE OR REPLACE FUNCTION my_stratnum(integer) +RETURNS integer +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT; + + + + + The matching code in the C module could then follow this skeleton: + + +PG_FUNCTION_INFO_V1(my_stratnum); + +Datum +my_stratnum(PG_FUNCTION_ARGS) +{ + StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(1); + StrategyNumber ret = InvalidStrategy; + + switch (strategy) + { + case RTEqualStrategyNumber: + ret = BTEqualStrategyNumber; + } + + PG_RETURN_UINT16(ret); +} + + + + + One translation function is provided by + PostgreSQL: + gist_stratnum_identity is for operator classes that + already use the RT*StrategyNumber constants. It + returns whatever is passed to it. The btree_gist + extension defines a second translation function, + gist_stratnum_btree, for operator classes that use + the BT*StrategyNumber constants. + + + -- cgit v1.2.3