mirror of
https://github.com/postgres/postgres.git
synced 2026-01-05 23:38:41 +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:
@@ -1,4 +1,4 @@
|
||||
/* $PostgreSQL: pgsql/contrib/hstore/hstore.sql.in,v 1.8 2007/11/13 04:24:28 momjian Exp $ */
|
||||
/* $PostgreSQL: pgsql/contrib/hstore/hstore.sql.in,v 1.9 2008/04/14 17:05:32 tgl Exp $ */
|
||||
|
||||
-- Adjust this setting to control where the objects get created.
|
||||
SET search_path = public;
|
||||
@@ -214,7 +214,7 @@ RETURNS internal
|
||||
AS 'MODULE_PATHNAME'
|
||||
LANGUAGE C IMMUTABLE;
|
||||
|
||||
CREATE OR REPLACE FUNCTION ghstore_consistent(internal,internal,int4)
|
||||
CREATE OR REPLACE FUNCTION ghstore_consistent(internal,internal,int,oid,internal)
|
||||
RETURNS bool
|
||||
AS 'MODULE_PATHNAME'
|
||||
LANGUAGE C IMMUTABLE;
|
||||
@@ -223,12 +223,12 @@ LANGUAGE C IMMUTABLE;
|
||||
CREATE OPERATOR CLASS gist_hstore_ops
|
||||
DEFAULT FOR TYPE hstore USING gist
|
||||
AS
|
||||
OPERATOR 7 @> RECHECK,
|
||||
OPERATOR 9 ?(hstore,text) RECHECK,
|
||||
--OPERATOR 8 <@ RECHECK,
|
||||
OPERATOR 13 @ RECHECK,
|
||||
--OPERATOR 14 ~ RECHECK,
|
||||
FUNCTION 1 ghstore_consistent (internal, internal, int4),
|
||||
OPERATOR 7 @> ,
|
||||
OPERATOR 9 ?(hstore,text) ,
|
||||
--OPERATOR 8 <@ ,
|
||||
OPERATOR 13 @ ,
|
||||
--OPERATOR 14 ~ ,
|
||||
FUNCTION 1 ghstore_consistent (internal, internal, int, oid, internal),
|
||||
FUNCTION 2 ghstore_union (internal, internal),
|
||||
FUNCTION 3 ghstore_compress (internal),
|
||||
FUNCTION 4 ghstore_decompress (internal),
|
||||
@@ -249,18 +249,18 @@ RETURNS internal
|
||||
AS 'MODULE_PATHNAME'
|
||||
LANGUAGE C IMMUTABLE;
|
||||
|
||||
CREATE OR REPLACE FUNCTION gin_consistent_hstore(internal, int2, internal)
|
||||
RETURNS internal
|
||||
CREATE OR REPLACE FUNCTION gin_consistent_hstore(internal, int2, internal, internal)
|
||||
RETURNS bool
|
||||
AS 'MODULE_PATHNAME'
|
||||
LANGUAGE C IMMUTABLE;
|
||||
|
||||
CREATE OPERATOR CLASS gin_hstore_ops
|
||||
DEFAULT FOR TYPE hstore USING gin
|
||||
AS
|
||||
OPERATOR 7 @> RECHECK,
|
||||
OPERATOR 7 @> ,
|
||||
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),
|
||||
FUNCTION 4 gin_consistent_hstore(internal, int2, internal, internal),
|
||||
STORAGE text;
|
||||
|
||||
@@ -113,21 +113,31 @@ Datum gin_consistent_hstore(PG_FUNCTION_ARGS);
|
||||
Datum
|
||||
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);
|
||||
bool res = true;
|
||||
|
||||
if (strategy == HStoreContainsStrategyNumber)
|
||||
{
|
||||
bool *check = (bool *) PG_GETARG_POINTER(0);
|
||||
HStore *query = PG_GETARG_HS(2);
|
||||
int i;
|
||||
|
||||
/*
|
||||
* Index lost information about correspondence of keys
|
||||
* and values, so we need recheck
|
||||
*/
|
||||
*recheck = true;
|
||||
for (i = 0; res && i < 2 * query->size; i++)
|
||||
if (check[i] == false)
|
||||
res = false;
|
||||
}
|
||||
else if (strategy == HStoreExistsStrategyNumber)
|
||||
{
|
||||
/* Existence of key is guaranteed */
|
||||
*recheck = false;
|
||||
res = true;
|
||||
}
|
||||
else
|
||||
elog(ERROR, "Unsupported strategy number: %d", strategy);
|
||||
|
||||
|
||||
@@ -508,9 +508,14 @@ ghstore_consistent(PG_FUNCTION_ARGS)
|
||||
{
|
||||
GISTTYPE *entry = (GISTTYPE *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
|
||||
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
|
||||
/* Oid subtype = PG_GETARG_OID(3); */
|
||||
bool *recheck = (bool *) PG_GETARG_POINTER(4);
|
||||
bool res = true;
|
||||
BITVECP sign;
|
||||
|
||||
/* All cases served by this function are inexact */
|
||||
*recheck = true;
|
||||
|
||||
if (ISALLTRUE(entry))
|
||||
PG_RETURN_BOOL(true);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $PostgreSQL: pgsql/contrib/hstore/uninstall_hstore.sql,v 1.6 2007/11/13 04:24:28 momjian Exp $ */
|
||||
/* $PostgreSQL: pgsql/contrib/hstore/uninstall_hstore.sql,v 1.7 2008/04/14 17:05:32 tgl Exp $ */
|
||||
|
||||
-- Adjust this setting to control where the objects get dropped.
|
||||
SET search_path = public;
|
||||
@@ -37,8 +37,8 @@ DROP FUNCTION ghstore_penalty(internal,internal,internal);
|
||||
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,int4);
|
||||
DROP FUNCTION gin_consistent_hstore(internal, smallint, internal);
|
||||
DROP FUNCTION ghstore_consistent(internal,internal,int,oid,internal);
|
||||
DROP FUNCTION gin_consistent_hstore(internal, int2, internal, internal);
|
||||
DROP FUNCTION gin_extract_hstore(internal, internal);
|
||||
DROP FUNCTION gin_extract_hstore_query(internal, internal, smallint);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user