1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Push index operator lossiness determination down to GIST/GIN opclass

"consistent" functions, and remove pg_amop.opreqcheck, as per recent
discussion.  The main immediate benefit of this is that we no longer need
8.3's ugly hack of requiring @@@ rather than @@ to test weight-using tsquery
searches on GIN indexes.  In future it should be possible to optimize some
other queries better than is done now, by detecting at runtime whether the
index match is exact or not.

Tom Lane, after an idea of Heikki's, and with some help from Teodor.
This commit is contained in:
Tom Lane
2008-04-14 17:05:34 +00:00
parent 10be77c173
commit 9b5c8d45f6
68 changed files with 1023 additions and 785 deletions

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/contrib/pg_trgm/pg_trgm.sql.in,v 1.7 2007/12/09 02:22:46 tgl Exp $ */
/* $PostgreSQL: pgsql/contrib/pg_trgm/pg_trgm.sql.in,v 1.8 2008/04/14 17:05:32 tgl Exp $ */
-- Adjust this setting to control where the objects get created.
SET search_path = public;
@ -55,7 +55,7 @@ CREATE TYPE gtrgm (
);
-- support functions for gist
CREATE OR REPLACE FUNCTION gtrgm_consistent(gtrgm,internal,int4)
CREATE OR REPLACE FUNCTION gtrgm_consistent(internal,text,int,oid,internal)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE;
@ -95,7 +95,7 @@ CREATE OPERATOR CLASS gist_trgm_ops
FOR TYPE text USING gist
AS
OPERATOR 1 % (text, text),
FUNCTION 1 gtrgm_consistent (gtrgm, internal, int4),
FUNCTION 1 gtrgm_consistent (internal, text, int, oid, internal),
FUNCTION 2 gtrgm_union (bytea, internal),
FUNCTION 3 gtrgm_compress (internal),
FUNCTION 4 gtrgm_decompress (internal),
@ -115,7 +115,7 @@ RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE;
CREATE OR REPLACE FUNCTION gin_trgm_consistent(internal, internal, text)
CREATE OR REPLACE FUNCTION gin_trgm_consistent(internal, int2, text, internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE;
@ -124,9 +124,9 @@ LANGUAGE C IMMUTABLE;
CREATE OPERATOR CLASS gin_trgm_ops
FOR TYPE text USING gin
AS
OPERATOR 1 % (text, text) RECHECK,
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, internal, text),
FUNCTION 4 gin_trgm_consistent (internal, int2, text, internal),
STORAGE int4;

View File

@ -53,13 +53,18 @@ Datum
gin_trgm_consistent(PG_FUNCTION_ARGS)
{
bool *check = (bool *) PG_GETARG_POINTER(0);
text *query = (text *) PG_GETARG_TEXT_P(2);
/* StrategyNumber strategy = PG_GETARG_UINT16(1); */
text *query = PG_GETARG_TEXT_P(2);
bool *recheck = (bool *) PG_GETARG_POINTER(3);
bool res = FALSE;
TRGM *trg;
int4 i,
trglen,
ntrue = 0;
/* All cases served by this function are inexact */
*recheck = true;
trg = generate_trgm(VARDATA(query), VARSIZE(query) - VARHDRSZ);
trglen = ARRNELEM(trg);

View File

@ -159,12 +159,19 @@ gtrgm_decompress(PG_FUNCTION_ARGS)
Datum
gtrgm_consistent(PG_FUNCTION_ARGS)
{
text *query = (text *) PG_GETARG_TEXT_P(1);
TRGM *key = (TRGM *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
text *query = PG_GETARG_TEXT_P(1);
/* StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); */
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
TRGM *key = (TRGM *) DatumGetPointer(entry->key);
TRGM *qtrg = generate_trgm(VARDATA(query), VARSIZE(query) - VARHDRSZ);
int res = false;
bool res = false;
if (GIST_LEAF((GISTENTRY *) PG_GETARG_POINTER(0)))
/* All cases served by this function are exact */
*recheck = false;
if (GIST_LEAF(entry))
{ /* all leafs contains orig trgm */
float4 tmpsml = cnt_sml(key, qtrg);

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/contrib/pg_trgm/uninstall_pg_trgm.sql,v 1.5 2007/11/13 04:24:28 momjian Exp $ */
/* $PostgreSQL: pgsql/contrib/pg_trgm/uninstall_pg_trgm.sql,v 1.6 2008/04/14 17:05:32 tgl Exp $ */
-- Adjust this setting to control where the objects get dropped.
SET search_path = public;
@ -17,7 +17,7 @@ DROP FUNCTION gtrgm_decompress(internal);
DROP FUNCTION gtrgm_compress(internal);
DROP FUNCTION gtrgm_consistent(gtrgm,internal,int4);
DROP FUNCTION gtrgm_consistent(internal,text,int,oid,internal);
DROP TYPE gtrgm CASCADE;
@ -27,7 +27,7 @@ DROP FUNCTION gin_extract_trgm(text, internal);
DROP FUNCTION gin_extract_trgm(text, internal, internal);
DROP FUNCTION gin_trgm_consistent(internal, internal, text);
DROP FUNCTION gin_trgm_consistent(internal, int2, text, internal);
DROP OPERATOR % (text, text);