1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

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
This commit is contained in:
Tom Lane
2009-03-25 22:19:02 +00:00
parent 050a78dd3d
commit 87b8db3774
18 changed files with 210 additions and 148 deletions

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/contrib/hstore/hstore.sql.in,v 1.9 2008/04/14 17:05:32 tgl Exp $ */
/* $PostgreSQL: pgsql/contrib/hstore/hstore.sql.in,v 1.10 2009/03/25 22:19:01 tgl Exp $ */
-- Adjust this setting to control where the objects get created.
SET search_path = public;
@ -244,12 +244,12 @@ RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE;
CREATE OR REPLACE FUNCTION gin_extract_hstore_query(internal, internal, int2)
CREATE OR REPLACE FUNCTION gin_extract_hstore_query(internal, internal, int2, internal, internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE;
CREATE OR REPLACE FUNCTION gin_consistent_hstore(internal, int2, internal, internal)
CREATE OR REPLACE FUNCTION gin_consistent_hstore(internal, int2, internal, int4, internal, internal)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE;
@ -261,6 +261,6 @@ AS
OPERATOR 9 ?(hstore,text),
FUNCTION 1 bttextcmp(text,text),
FUNCTION 2 gin_extract_hstore(internal, internal),
FUNCTION 3 gin_extract_hstore_query(internal, internal, int2),
FUNCTION 4 gin_consistent_hstore(internal, int2, internal, internal),
FUNCTION 3 gin_extract_hstore_query(internal, internal, int2, internal, internal),
FUNCTION 4 gin_consistent_hstore(internal, int2, internal, int4, internal, internal),
STORAGE text;

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/hstore/hstore_gin.c,v 1.4 2008/05/12 00:00:42 alvherre Exp $
* $PostgreSQL: pgsql/contrib/hstore/hstore_gin.c,v 1.5 2009/03/25 22:19:01 tgl Exp $
*/
#include "postgres.h"
@ -122,7 +122,9 @@ gin_consistent_hstore(PG_FUNCTION_ARGS)
bool *check = (bool *) PG_GETARG_POINTER(0);
StrategyNumber strategy = PG_GETARG_UINT16(1);
HStore *query = PG_GETARG_HS(2);
bool *recheck = (bool *) PG_GETARG_POINTER(3);
/* int32 nkeys = PG_GETARG_INT32(3); */
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
bool *recheck = (bool *) PG_GETARG_POINTER(5);
bool res = true;
if (strategy == HStoreContainsStrategyNumber)

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/contrib/hstore/uninstall_hstore.sql,v 1.7 2008/04/14 17:05:32 tgl Exp $ */
/* $PostgreSQL: pgsql/contrib/hstore/uninstall_hstore.sql,v 1.8 2009/03/25 22:19:01 tgl Exp $ */
-- Adjust this setting to control where the objects get dropped.
SET search_path = public;
@ -38,9 +38,9 @@ DROP FUNCTION ghstore_picksplit(internal, internal);
DROP FUNCTION ghstore_union(internal, internal);
DROP FUNCTION ghstore_same(internal, internal, internal);
DROP FUNCTION ghstore_consistent(internal,internal,int,oid,internal);
DROP FUNCTION gin_consistent_hstore(internal, int2, internal, internal);
DROP FUNCTION gin_consistent_hstore(internal, int2, internal, int4, internal, internal);
DROP FUNCTION gin_extract_hstore(internal, internal);
DROP FUNCTION gin_extract_hstore_query(internal, internal, smallint);
DROP FUNCTION gin_extract_hstore_query(internal, internal, smallint, internal, internal);
DROP TYPE hstore CASCADE;
DROP TYPE ghstore CASCADE;

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/contrib/intarray/_int.sql.in,v 1.28 2008/04/14 17:05:32 tgl Exp $ */
/* $PostgreSQL: pgsql/contrib/intarray/_int.sql.in,v 1.29 2009/03/25 22:19:01 tgl Exp $ */
-- Adjust this setting to control where the objects get created.
SET search_path = public;
@ -458,13 +458,13 @@ AS
--GIN
CREATE OR REPLACE FUNCTION ginint4_queryextract(internal, internal, int2)
CREATE OR REPLACE FUNCTION ginint4_queryextract(internal, internal, int2, internal, internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE;
CREATE OR REPLACE FUNCTION ginint4_consistent(internal, int2, internal, internal)
RETURNS internal
CREATE OR REPLACE FUNCTION ginint4_consistent(internal, int2, internal, int4, internal, internal)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE;
@ -480,6 +480,6 @@ AS
OPERATOR 20 @@ (_int4, query_int),
FUNCTION 1 btint4cmp (int4, int4),
FUNCTION 2 ginarrayextract (anyarray, internal),
FUNCTION 3 ginint4_queryextract (internal, internal, int2),
FUNCTION 4 ginint4_consistent (internal, int2, internal, internal),
FUNCTION 3 ginint4_queryextract (internal, internal, int2, internal, internal),
FUNCTION 4 ginint4_consistent (internal, int2, internal, int4, internal, internal),
STORAGE int4;

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/intarray/_int_gin.c,v 1.8 2008/05/17 01:28:19 adunstan Exp $
* $PostgreSQL: pgsql/contrib/intarray/_int_gin.c,v 1.9 2009/03/25 22:19:01 tgl Exp $
*/
#include "postgres.h"
@ -90,7 +90,9 @@ ginint4_consistent(PG_FUNCTION_ARGS)
{
bool *check = (bool *) PG_GETARG_POINTER(0);
StrategyNumber strategy = PG_GETARG_UINT16(1);
bool *recheck = (bool *) PG_GETARG_POINTER(3);
/* int32 nkeys = PG_GETARG_INT32(3); */
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
bool *recheck = (bool *) PG_GETARG_POINTER(5);
bool res = FALSE;
/*

View File

@ -1,13 +1,13 @@
/* $PostgreSQL: pgsql/contrib/intarray/uninstall__int.sql,v 1.9 2008/04/14 17:05:32 tgl Exp $ */
/* $PostgreSQL: pgsql/contrib/intarray/uninstall__int.sql,v 1.10 2009/03/25 22:19:01 tgl Exp $ */
-- Adjust this setting to control where the objects get created.
SET search_path = public;
DROP OPERATOR CLASS gin__int_ops USING gin;
DROP FUNCTION ginint4_queryextract(internal, internal, int2);
DROP FUNCTION ginint4_queryextract(internal, internal, int2, internal, internal);
DROP FUNCTION ginint4_consistent(internal, int2, internal, internal);
DROP FUNCTION ginint4_consistent(internal, int2, internal, int4, internal, internal);
DROP OPERATOR CLASS gist__intbig_ops USING gist;

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/contrib/pg_trgm/pg_trgm.sql.in,v 1.8 2008/04/14 17:05:32 tgl Exp $ */
/* $PostgreSQL: pgsql/contrib/pg_trgm/pg_trgm.sql.in,v 1.9 2009/03/25 22:19:01 tgl Exp $ */
-- Adjust this setting to control where the objects get created.
SET search_path = public;
@ -110,13 +110,13 @@ RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE;
CREATE OR REPLACE FUNCTION gin_extract_trgm(text, internal, internal)
CREATE OR REPLACE FUNCTION gin_extract_trgm(text, internal, int2, internal, internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE;
CREATE OR REPLACE FUNCTION gin_trgm_consistent(internal, int2, text, internal)
RETURNS internal
CREATE OR REPLACE FUNCTION gin_trgm_consistent(internal, int2, text, int4, internal, internal)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE;
@ -127,6 +127,6 @@ AS
OPERATOR 1 % (text, text),
FUNCTION 1 btint4cmp (int4, int4),
FUNCTION 2 gin_extract_trgm (text, internal),
FUNCTION 3 gin_extract_trgm (text, internal, internal),
FUNCTION 4 gin_trgm_consistent (internal, int2, text, internal),
FUNCTION 3 gin_extract_trgm (text, internal, int2, internal, internal),
FUNCTION 4 gin_trgm_consistent (internal, int2, text, int4, internal, internal),
STORAGE int4;

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/pg_trgm/trgm_gin.c,v 1.6 2008/11/12 13:43:54 teodor Exp $
* $PostgreSQL: pgsql/contrib/pg_trgm/trgm_gin.c,v 1.7 2009/03/25 22:19:01 tgl Exp $
*/
#include "trgm.h"
@ -47,53 +47,40 @@ gin_extract_trgm(PG_FUNCTION_ARGS)
ptr++;
}
if (PG_NARGS() > 4)
{
/*
* Function called from query extracting
*/
Pointer **extra_data = (Pointer **) PG_GETARG_POINTER(4);
*extra_data = (Pointer*) palloc0(sizeof(Pointer)*(*nentries));
*(int32*)(*extra_data) = trglen;
}
}
PG_RETURN_POINTER(entries);
}
/*
* Per call strage for consistent functions to
* cache computed value from query
*/
typedef struct PerCallConsistentStorage {
int trglen;
text data[1]; /* query */
} PerCallConsistentStorage;
#define PCCSHDR_SZ offsetof(PerCallConsistentStorage, data)
Datum
gin_trgm_consistent(PG_FUNCTION_ARGS)
{
bool *check = (bool *) PG_GETARG_POINTER(0);
/* StrategyNumber strategy = PG_GETARG_UINT16(1); */
text *query = PG_GETARG_TEXT_P(2);
bool *recheck = (bool *) PG_GETARG_POINTER(3);
/* text *query = PG_GETARG_TEXT_P(2); */
/* int32 nkeys = PG_GETARG_INT32(3); */
Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4);
bool *recheck = (bool *) PG_GETARG_POINTER(5);
bool res = FALSE;
int4 i,
trglen,
ntrue = 0;
PerCallConsistentStorage *pccs = (PerCallConsistentStorage*) fcinfo->flinfo->fn_extra;
/* All cases served by this function are inexact */
*recheck = true;
if ( pccs == NULL || VARSIZE(pccs->data) != VARSIZE(query) || memcmp( pccs->data, query, VARSIZE(query) ) !=0 )
{
TRGM *trg = generate_trgm(VARDATA(query), VARSIZE(query) - VARHDRSZ);
if ( pccs )
pfree(pccs);
fcinfo->flinfo->fn_extra = MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
VARSIZE(query) + PCCSHDR_SZ);
pccs = (PerCallConsistentStorage*) fcinfo->flinfo->fn_extra;
pccs->trglen = ARRNELEM(trg);
memcpy( pccs->data, query, VARSIZE(query) );
}
trglen = pccs->trglen;
trglen = *(int32*)extra_data;
for (i = 0; i < trglen; i++)
if (check[i])

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/contrib/pg_trgm/uninstall_pg_trgm.sql,v 1.6 2008/04/14 17:05:32 tgl Exp $ */
/* $PostgreSQL: pgsql/contrib/pg_trgm/uninstall_pg_trgm.sql,v 1.7 2009/03/25 22:19:01 tgl Exp $ */
-- Adjust this setting to control where the objects get dropped.
SET search_path = public;
@ -25,9 +25,9 @@ DROP OPERATOR CLASS gin_trgm_ops USING gin;
DROP FUNCTION gin_extract_trgm(text, internal);
DROP FUNCTION gin_extract_trgm(text, internal, internal);
DROP FUNCTION gin_extract_trgm(text, internal, int2, internal, internal);
DROP FUNCTION gin_trgm_consistent(internal, int2, text, internal);
DROP FUNCTION gin_trgm_consistent(internal, int2, text, int4, internal, internal);
DROP OPERATOR % (text, text);

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/contrib/tsearch2/tsearch2.sql.in,v 1.6 2008/05/16 17:26:07 tgl Exp $ */
/* $PostgreSQL: pgsql/contrib/tsearch2/tsearch2.sql.in,v 1.7 2009/03/25 22:19:01 tgl Exp $ */
-- Adjust this setting to control where the objects get created.
SET search_path = public;
@ -552,8 +552,9 @@ AS
OPERATOR 2 @@@ (tsvector, tsquery),
FUNCTION 1 bttextcmp(text, text),
FUNCTION 2 gin_extract_tsvector(tsvector,internal),
FUNCTION 3 gin_extract_tsquery(tsquery,internal,smallint,internal),
FUNCTION 4 gin_tsquery_consistent(internal,smallint,tsquery,internal),
FUNCTION 3 gin_extract_tsquery(tsquery,internal,smallint,internal,internal),
FUNCTION 4 gin_tsquery_consistent(internal,smallint,tsquery,int,internal,internal),
FUNCTION 5 gin_cmp_prefix(text,text,smallint,internal),
STORAGE text;
CREATE OPERATOR CLASS tsvector_ops