Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 87b8db3

Browse files
committed
Adjust the APIs for GIN opclass support functions to allow the extractQuery()
method to pass extra data to the consistent() and comparePartial() methods. This is the core infrastructure needed to support the soon-to-appear contrib/btree_gin module. The APIs are still upward compatible with the definitions used in 8.3 and before, although *not* with the previous 8.4devel function definitions. catversion bump for changes in pg_proc entries (although these are just cosmetic, since GIN doesn't actually look at the function signature before calling it...) Teodor Sigaev and Oleg Bartunov
1 parent 050a78d commit 87b8db3

File tree

18 files changed

+211
-149
lines changed

18 files changed

+211
-149
lines changed

contrib/hstore/hstore.sql.in

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/contrib/hstore/hstore.sql.in,v 1.9 2008/04/14 17:05:32 tgl Exp $ */
1+
/* $PostgreSQL: pgsql/contrib/hstore/hstore.sql.in,v 1.10 2009/03/25 22:19:01 tgl Exp $ */
22

33
-- Adjust this setting to control where the objects get created.
44
SET search_path = public;
@@ -244,12 +244,12 @@ RETURNS internal
244244
AS 'MODULE_PATHNAME'
245245
LANGUAGE C IMMUTABLE;
246246

247-
CREATE OR REPLACE FUNCTION gin_extract_hstore_query(internal, internal, int2)
247+
CREATE OR REPLACE FUNCTION gin_extract_hstore_query(internal, internal, int2, internal, internal)
248248
RETURNS internal
249249
AS 'MODULE_PATHNAME'
250250
LANGUAGE C IMMUTABLE;
251251

252-
CREATE OR REPLACE FUNCTION gin_consistent_hstore(internal, int2, internal, internal)
252+
CREATE OR REPLACE FUNCTION gin_consistent_hstore(internal, int2, internal, int4, internal, internal)
253253
RETURNS bool
254254
AS 'MODULE_PATHNAME'
255255
LANGUAGE C IMMUTABLE;
@@ -261,6 +261,6 @@ AS
261261
OPERATOR 9 ?(hstore,text),
262262
FUNCTION 1 bttextcmp(text,text),
263263
FUNCTION 2 gin_extract_hstore(internal, internal),
264-
FUNCTION 3 gin_extract_hstore_query(internal, internal, int2),
265-
FUNCTION 4 gin_consistent_hstore(internal, int2, internal, internal),
264+
FUNCTION 3 gin_extract_hstore_query(internal, internal, int2, internal, internal),
265+
FUNCTION 4 gin_consistent_hstore(internal, int2, internal, int4, internal, internal),
266266
STORAGE text;

contrib/hstore/hstore_gin.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/hstore/hstore_gin.c,v 1.4 2008/05/12 00:00:42 alvherre Exp $
2+
* $PostgreSQL: pgsql/contrib/hstore/hstore_gin.c,v 1.5 2009/03/25 22:19:01 tgl Exp $
33
*/
44
#include "postgres.h"
55

@@ -122,7 +122,9 @@ gin_consistent_hstore(PG_FUNCTION_ARGS)
122122
bool *check = (bool *) PG_GETARG_POINTER(0);
123123
StrategyNumber strategy = PG_GETARG_UINT16(1);
124124
HStore *query = PG_GETARG_HS(2);
125-
bool *recheck = (bool *) PG_GETARG_POINTER(3);
125+
/* int32 nkeys = PG_GETARG_INT32(3); */
126+
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
127+
bool *recheck = (bool *) PG_GETARG_POINTER(5);
126128
bool res = true;
127129

128130
if (strategy == HStoreContainsStrategyNumber)

contrib/hstore/uninstall_hstore.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/contrib/hstore/uninstall_hstore.sql,v 1.7 2008/04/14 17:05:32 tgl Exp $ */
1+
/* $PostgreSQL: pgsql/contrib/hstore/uninstall_hstore.sql,v 1.8 2009/03/25 22:19:01 tgl Exp $ */
22

33
-- Adjust this setting to control where the objects get dropped.
44
SET search_path = public;
@@ -38,9 +38,9 @@ DROP FUNCTION ghstore_picksplit(internal, internal);
3838
DROP FUNCTION ghstore_union(internal, internal);
3939
DROP FUNCTION ghstore_same(internal, internal, internal);
4040
DROP FUNCTION ghstore_consistent(internal,internal,int,oid,internal);
41-
DROP FUNCTION gin_consistent_hstore(internal, int2, internal, internal);
41+
DROP FUNCTION gin_consistent_hstore(internal, int2, internal, int4, internal, internal);
4242
DROP FUNCTION gin_extract_hstore(internal, internal);
43-
DROP FUNCTION gin_extract_hstore_query(internal, internal, smallint);
43+
DROP FUNCTION gin_extract_hstore_query(internal, internal, smallint, internal, internal);
4444

4545
DROP TYPE hstore CASCADE;
4646
DROP TYPE ghstore CASCADE;

contrib/intarray/_int.sql.in

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/contrib/intarray/_int.sql.in,v 1.28 2008/04/14 17:05:32 tgl Exp $ */
1+
/* $PostgreSQL: pgsql/contrib/intarray/_int.sql.in,v 1.29 2009/03/25 22:19:01 tgl Exp $ */
22

33
-- Adjust this setting to control where the objects get created.
44
SET search_path = public;
@@ -458,13 +458,13 @@ AS
458458

459459
--GIN
460460

461-
CREATE OR REPLACE FUNCTION ginint4_queryextract(internal, internal, int2)
461+
CREATE OR REPLACE FUNCTION ginint4_queryextract(internal, internal, int2, internal, internal)
462462
RETURNS internal
463463
AS 'MODULE_PATHNAME'
464464
LANGUAGE C IMMUTABLE;
465465

466-
CREATE OR REPLACE FUNCTION ginint4_consistent(internal, int2, internal, internal)
467-
RETURNS internal
466+
CREATE OR REPLACE FUNCTION ginint4_consistent(internal, int2, internal, int4, internal, internal)
467+
RETURNS bool
468468
AS 'MODULE_PATHNAME'
469469
LANGUAGE C IMMUTABLE;
470470

@@ -480,6 +480,6 @@ AS
480480
OPERATOR 20 @@ (_int4, query_int),
481481
FUNCTION 1 btint4cmp (int4, int4),
482482
FUNCTION 2 ginarrayextract (anyarray, internal),
483-
FUNCTION 3 ginint4_queryextract (internal, internal, int2),
484-
FUNCTION 4 ginint4_consistent (internal, int2, internal, internal),
483+
FUNCTION 3 ginint4_queryextract (internal, internal, int2, internal, internal),
484+
FUNCTION 4 ginint4_consistent (internal, int2, internal, int4, internal, internal),
485485
STORAGE int4;

contrib/intarray/_int_gin.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/intarray/_int_gin.c,v 1.8 2008/05/17 01:28:19 adunstan Exp $
2+
* $PostgreSQL: pgsql/contrib/intarray/_int_gin.c,v 1.9 2009/03/25 22:19:01 tgl Exp $
33
*/
44
#include "postgres.h"
55

@@ -90,7 +90,9 @@ ginint4_consistent(PG_FUNCTION_ARGS)
9090
{
9191
bool *check = (bool *) PG_GETARG_POINTER(0);
9292
StrategyNumber strategy = PG_GETARG_UINT16(1);
93-
bool *recheck = (bool *) PG_GETARG_POINTER(3);
93+
/* int32 nkeys = PG_GETARG_INT32(3); */
94+
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
95+
bool *recheck = (bool *) PG_GETARG_POINTER(5);
9496
bool res = FALSE;
9597

9698
/*

contrib/intarray/uninstall__int.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
/* $PostgreSQL: pgsql/contrib/intarray/uninstall__int.sql,v 1.9 2008/04/14 17:05:32 tgl Exp $ */
1+
/* $PostgreSQL: pgsql/contrib/intarray/uninstall__int.sql,v 1.10 2009/03/25 22:19:01 tgl Exp $ */
22

33
-- Adjust this setting to control where the objects get created.
44
SET search_path = public;
55

66
DROP OPERATOR CLASS gin__int_ops USING gin;
77

8-
DROP FUNCTION ginint4_queryextract(internal, internal, int2);
8+
DROP FUNCTION ginint4_queryextract(internal, internal, int2, internal, internal);
99

10-
DROP FUNCTION ginint4_consistent(internal, int2, internal, internal);
10+
DROP FUNCTION ginint4_consistent(internal, int2, internal, int4, internal, internal);
1111

1212
DROP OPERATOR CLASS gist__intbig_ops USING gist;
1313

contrib/pg_trgm/pg_trgm.sql.in

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/contrib/pg_trgm/pg_trgm.sql.in,v 1.8 2008/04/14 17:05:32 tgl Exp $ */
1+
/* $PostgreSQL: pgsql/contrib/pg_trgm/pg_trgm.sql.in,v 1.9 2009/03/25 22:19:01 tgl Exp $ */
22

33
-- Adjust this setting to control where the objects get created.
44
SET search_path = public;
@@ -110,13 +110,13 @@ RETURNS internal
110110
AS 'MODULE_PATHNAME'
111111
LANGUAGE C IMMUTABLE;
112112

113-
CREATE OR REPLACE FUNCTION gin_extract_trgm(text, internal, internal)
113+
CREATE OR REPLACE FUNCTION gin_extract_trgm(text, internal, int2, internal, internal)
114114
RETURNS internal
115115
AS 'MODULE_PATHNAME'
116116
LANGUAGE C IMMUTABLE;
117117

118-
CREATE OR REPLACE FUNCTION gin_trgm_consistent(internal, int2, text, internal)
119-
RETURNS internal
118+
CREATE OR REPLACE FUNCTION gin_trgm_consistent(internal, int2, text, int4, internal, internal)
119+
RETURNS bool
120120
AS 'MODULE_PATHNAME'
121121
LANGUAGE C IMMUTABLE;
122122

@@ -127,6 +127,6 @@ AS
127127
OPERATOR 1 % (text, text),
128128
FUNCTION 1 btint4cmp (int4, int4),
129129
FUNCTION 2 gin_extract_trgm (text, internal),
130-
FUNCTION 3 gin_extract_trgm (text, internal, internal),
131-
FUNCTION 4 gin_trgm_consistent (internal, int2, text, internal),
130+
FUNCTION 3 gin_extract_trgm (text, internal, int2, internal, internal),
131+
FUNCTION 4 gin_trgm_consistent (internal, int2, text, int4, internal, internal),
132132
STORAGE int4;

contrib/pg_trgm/trgm_gin.c

+17-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/pg_trgm/trgm_gin.c,v 1.6 2008/11/12 13:43:54 teodor Exp $
2+
* $PostgreSQL: pgsql/contrib/pg_trgm/trgm_gin.c,v 1.7 2009/03/25 22:19:01 tgl Exp $
33
*/
44
#include "trgm.h"
55

@@ -47,53 +47,40 @@ gin_extract_trgm(PG_FUNCTION_ARGS)
4747

4848
ptr++;
4949
}
50+
if (PG_NARGS() > 4)
51+
{
52+
/*
53+
* Function called from query extracting
54+
*/
55+
Pointer **extra_data = (Pointer **) PG_GETARG_POINTER(4);
56+
57+
*extra_data = (Pointer*) palloc0(sizeof(Pointer)*(*nentries));
58+
59+
*(int32*)(*extra_data) = trglen;
60+
}
5061
}
5162

5263
PG_RETURN_POINTER(entries);
5364
}
5465

55-
/*
56-
* Per call strage for consistent functions to
57-
* cache computed value from query
58-
*/
59-
typedef struct PerCallConsistentStorage {
60-
int trglen;
61-
text data[1]; /* query */
62-
} PerCallConsistentStorage;
63-
#define PCCSHDR_SZ offsetof(PerCallConsistentStorage, data)
64-
6566
Datum
6667
gin_trgm_consistent(PG_FUNCTION_ARGS)
6768
{
6869
bool *check = (bool *) PG_GETARG_POINTER(0);
6970
/* StrategyNumber strategy = PG_GETARG_UINT16(1); */
70-
text *query = PG_GETARG_TEXT_P(2);
71-
bool *recheck = (bool *) PG_GETARG_POINTER(3);
71+
/* text *query = PG_GETARG_TEXT_P(2); */
72+
/* int32 nkeys = PG_GETARG_INT32(3); */
73+
Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4);
74+
bool *recheck = (bool *) PG_GETARG_POINTER(5);
7275
bool res = FALSE;
7376
int4 i,
7477
trglen,
7578
ntrue = 0;
76-
PerCallConsistentStorage *pccs = (PerCallConsistentStorage*) fcinfo->flinfo->fn_extra;
7779

7880
/* All cases served by this function are inexact */
7981
*recheck = true;
8082

81-
if ( pccs == NULL || VARSIZE(pccs->data) != VARSIZE(query) || memcmp( pccs->data, query, VARSIZE(query) ) !=0 )
82-
{
83-
TRGM *trg = generate_trgm(VARDATA(query), VARSIZE(query) - VARHDRSZ);
84-
85-
if ( pccs )
86-
pfree(pccs);
87-
88-
fcinfo->flinfo->fn_extra = MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
89-
VARSIZE(query) + PCCSHDR_SZ);
90-
pccs = (PerCallConsistentStorage*) fcinfo->flinfo->fn_extra;
91-
92-
pccs->trglen = ARRNELEM(trg);
93-
memcpy( pccs->data, query, VARSIZE(query) );
94-
}
95-
96-
trglen = pccs->trglen;
83+
trglen = *(int32*)extra_data;
9784

9885
for (i = 0; i < trglen; i++)
9986
if (check[i])

contrib/pg_trgm/uninstall_pg_trgm.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/contrib/pg_trgm/uninstall_pg_trgm.sql,v 1.6 2008/04/14 17:05:32 tgl Exp $ */
1+
/* $PostgreSQL: pgsql/contrib/pg_trgm/uninstall_pg_trgm.sql,v 1.7 2009/03/25 22:19:01 tgl Exp $ */
22

33
-- Adjust this setting to control where the objects get dropped.
44
SET search_path = public;
@@ -25,9 +25,9 @@ DROP OPERATOR CLASS gin_trgm_ops USING gin;
2525

2626
DROP FUNCTION gin_extract_trgm(text, internal);
2727

28-
DROP FUNCTION gin_extract_trgm(text, internal, internal);
28+
DROP FUNCTION gin_extract_trgm(text, internal, int2, internal, internal);
2929

30-
DROP FUNCTION gin_trgm_consistent(internal, int2, text, internal);
30+
DROP FUNCTION gin_trgm_consistent(internal, int2, text, int4, internal, internal);
3131

3232
DROP OPERATOR % (text, text);
3333

contrib/tsearch2/tsearch2.sql.in

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/contrib/tsearch2/tsearch2.sql.in,v 1.6 2008/05/16 17:26:07 tgl Exp $ */
1+
/* $PostgreSQL: pgsql/contrib/tsearch2/tsearch2.sql.in,v 1.7 2009/03/25 22:19:01 tgl Exp $ */
22

33
-- Adjust this setting to control where the objects get created.
44
SET search_path = public;
@@ -552,8 +552,9 @@ AS
552552
OPERATOR 2 @@@ (tsvector, tsquery),
553553
FUNCTION 1 bttextcmp(text, text),
554554
FUNCTION 2 gin_extract_tsvector(tsvector,internal),
555-
FUNCTION 3 gin_extract_tsquery(tsquery,internal,smallint,internal),
556-
FUNCTION 4 gin_tsquery_consistent(internal,smallint,tsquery,internal),
555+
FUNCTION 3 gin_extract_tsquery(tsquery,internal,smallint,internal,internal),
556+
FUNCTION 4 gin_tsquery_consistent(internal,smallint,tsquery,int,internal,internal),
557+
FUNCTION 5 gin_cmp_prefix(text,text,smallint,internal),
557558
STORAGE text;
558559

559560
CREATE OPERATOR CLASS tsvector_ops

doc/src/sgml/gin.sgml

+34-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/gin.sgml,v 2.17 2009/03/24 20:17:07 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/gin.sgml,v 2.18 2009/03/25 22:19:01 tgl Exp $ -->
22

33
<chapter id="GIN">
44
<title>GIN Indexes</title>
@@ -88,7 +88,7 @@
8888

8989
<varlistentry>
9090
<term>Datum *extractQuery(Datum query, int32 *nkeys,
91-
StrategyNumber n, bool **pmatch)</term>
91+
StrategyNumber n, bool **pmatch, Pointer **extra_data)</term>
9292
<listitem>
9393
<para>
9494
Returns an array of keys given a value to be queried; that is,
@@ -104,7 +104,7 @@
104104
should store 0 or -1 into <literal>*nkeys</>, depending on the
105105
semantics of the operator. 0 means that every
106106
value matches the <literal>query</> and a sequential scan should be
107-
produced. -1 means nothing can match the <literal>query</>.
107+
performed. -1 means nothing can match the <literal>query</>.
108108
<literal>pmatch</> is an output argument for use when partial match
109109
is supported. To use it, <function>extractQuery</> must allocate
110110
an array of <literal>*nkeys</> booleans and store its address at
@@ -114,25 +114,40 @@
114114
is not required. The variable is initialized to NULL before call,
115115
so this argument can simply be ignored by operator classes that do
116116
not support partial match.
117+
<literal>extra_data</> is an output argument that allows
118+
<function>extractQuery</> to pass additional data to the
119+
<function>consistent</> and <function>comparePartial</> methods.
120+
To use it, <function>extractQuery</> must allocate
121+
an array of <literal>*nkeys</> Pointers and store its address at
122+
<literal>*extra_data</>, then store whatever it wants to into the
123+
individual pointers. The variable is initialized to NULL before
124+
call, so this argument can simply be ignored by operator classes that
125+
do not require extra data. If <literal>*extra_data</> is set, the
126+
whole array is passed to the <function>consistent</> method, and
127+
the appropriate element to the <function>comparePartial</> method.
117128
</para>
118129

119130
</listitem>
120131
</varlistentry>
121132

122133
<varlistentry>
123-
<term>bool consistent(bool check[], StrategyNumber n, Datum query, bool *recheck)</term>
134+
<term>bool consistent(bool check[], StrategyNumber n, Datum query,
135+
int32 nkeys, Pointer extra_data[], bool *recheck)</term>
124136
<listitem>
125137
<para>
126138
Returns TRUE if the indexed value satisfies the query operator with
127139
strategy number <literal>n</> (or might satisfy, if the recheck
128-
indication is returned). The <literal>check</> array has
129-
the same length as the number of keys previously returned by
130-
<function>extractQuery</> for this query. Each element of the
140+
indication is returned). The <literal>check</> array has length
141+
<literal>nkeys</>, which is the same as the number of keys previously
142+
returned by <function>extractQuery</> for this <literal>query</> datum.
143+
Each element of the
131144
<literal>check</> array is TRUE if the indexed value contains the
132145
corresponding query key, ie, if (check[i] == TRUE) the i-th key of the
133146
<function>extractQuery</> result array is present in the indexed value.
134147
The original <literal>query</> datum (not the extracted key array!) is
135148
passed in case the <function>consistent</> method needs to consult it.
149+
<literal>extra_data</> is the extra-data array returned by
150+
<function>extractQuery</>, or NULL if none.
136151
On success, <literal>*recheck</> should be set to TRUE if the heap
137152
tuple needs to be rechecked against the query operator, or FALSE if
138153
the index test is exact.
@@ -150,7 +165,8 @@
150165
<variablelist>
151166

152167
<varlistentry>
153-
<term>int comparePartial(Datum partial_key, Datum key, StrategyNumber n)</term>
168+
<term>int comparePartial(Datum partial_key, Datum key, StrategyNumber n,
169+
Pointer extra_data)</term>
154170
<listitem>
155171
<para>
156172
Compare a partial-match query to an index key. Returns an integer
@@ -160,7 +176,9 @@
160176
indicates that the index scan should stop because no more matches
161177
are possible. The strategy number <literal>n</> of the operator
162178
that generated the partial match query is provided, in case its
163-
semantics are needed to determine when to end the scan.
179+
semantics are needed to determine when to end the scan. Also,
180+
<literal>extra_data</> is the corresponding element of the extra-data
181+
array made by <function>extractQuery</>, or NULL if none.
164182
</para>
165183
</listitem>
166184
</varlistentry>
@@ -383,6 +401,13 @@
383401
</para>
384402

385403
<variablelist>
404+
<varlistentry>
405+
<term>btree-gin</term>
406+
<listitem>
407+
<para>B-Tree equivalent functionality for several data types</para>
408+
</listitem>
409+
</varlistentry>
410+
386411
<varlistentry>
387412
<term>hstore</term>
388413
<listitem>

0 commit comments

Comments
 (0)