Thanks to visit codestin.com
Credit goes to github.com

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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 17 additions & 30 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 4 additions & 3 deletions
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

0 commit comments

Comments
 (0)