1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +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

@ -554,10 +554,15 @@ _ltree_consistent(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
char *query = (char *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1)));
ltree_gist *key = (ltree_gist *) DatumGetPointer(entry->key);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
ltree_gist *key = (ltree_gist *) DatumGetPointer(entry->key);
bool res = false;
/* All cases served by this function are inexact */
*recheck = true;
switch (strategy)
{
case 10:

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/contrib/ltree/ltree.sql.in,v 1.16 2007/11/13 04:24:28 momjian Exp $ */
/* $PostgreSQL: pgsql/contrib/ltree/ltree.sql.in,v 1.17 2008/04/14 17:05:32 tgl Exp $ */
-- Adjust this setting to control where the objects get created.
SET search_path = public;
@ -496,7 +496,7 @@ CREATE TYPE ltree_gist (
);
CREATE OR REPLACE FUNCTION ltree_consistent(internal,internal,int2)
CREATE OR REPLACE FUNCTION ltree_consistent(internal,internal,int2,oid,internal)
RETURNS bool as 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE;
CREATE OR REPLACE FUNCTION ltree_compress(internal)
@ -532,7 +532,7 @@ CREATE OPERATOR CLASS gist_ltree_ops
OPERATOR 15 @ (ltxtquery, ltree) ,
OPERATOR 16 ? (ltree, _lquery) ,
OPERATOR 17 ? (_lquery, ltree) ,
FUNCTION 1 ltree_consistent (internal, internal, int2),
FUNCTION 1 ltree_consistent (internal, internal, int2, oid, internal),
FUNCTION 2 ltree_union (internal, internal),
FUNCTION 3 ltree_compress (internal),
FUNCTION 4 ltree_decompress (internal),
@ -822,7 +822,7 @@ CREATE OPERATOR ?@ (
);
--GiST support for ltree[]
CREATE OR REPLACE FUNCTION _ltree_consistent(internal,internal,int2)
CREATE OR REPLACE FUNCTION _ltree_consistent(internal,internal,int2,oid,internal)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE;
@ -854,15 +854,15 @@ LANGUAGE C IMMUTABLE;
CREATE OPERATOR CLASS gist__ltree_ops
DEFAULT FOR TYPE _ltree USING gist AS
OPERATOR 10 <@ (_ltree, ltree) RECHECK ,
OPERATOR 11 @> (ltree, _ltree) RECHECK ,
OPERATOR 12 ~ (_ltree, lquery) RECHECK ,
OPERATOR 13 ~ (lquery, _ltree) RECHECK ,
OPERATOR 14 @ (_ltree, ltxtquery) RECHECK ,
OPERATOR 15 @ (ltxtquery, _ltree) RECHECK ,
OPERATOR 16 ? (_ltree, _lquery) RECHECK ,
OPERATOR 17 ? (_lquery, _ltree) RECHECK ,
FUNCTION 1 _ltree_consistent (internal, internal, int2),
OPERATOR 10 <@ (_ltree, ltree),
OPERATOR 11 @> (ltree, _ltree),
OPERATOR 12 ~ (_ltree, lquery),
OPERATOR 13 ~ (lquery, _ltree),
OPERATOR 14 @ (_ltree, ltxtquery),
OPERATOR 15 @ (ltxtquery, _ltree),
OPERATOR 16 ? (_ltree, _lquery),
OPERATOR 17 ? (_lquery, _ltree),
FUNCTION 1 _ltree_consistent (internal, internal, int2, oid, internal),
FUNCTION 2 _ltree_union (internal, internal),
FUNCTION 3 _ltree_compress (internal),
FUNCTION 4 ltree_decompress (internal),

View File

@ -1,7 +1,7 @@
/*
* GiST support for ltree
* Teodor Sigaev <teodor@stack.net>
* $PostgreSQL: pgsql/contrib/ltree/ltree_gist.c,v 1.22 2007/11/16 01:12:24 momjian Exp $
* $PostgreSQL: pgsql/contrib/ltree/ltree_gist.c,v 1.23 2008/04/14 17:05:32 tgl Exp $
*/
#include "ltree.h"
@ -624,11 +624,16 @@ Datum
ltree_consistent(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
void *query = NULL;
ltree_gist *key = (ltree_gist *) DatumGetPointer(entry->key);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
ltree_gist *key = (ltree_gist *) DatumGetPointer(entry->key);
void *query = NULL;
bool res = false;
/* All cases served by this function are exact */
*recheck = false;
switch (strategy)
{
case BTLessStrategyNumber:

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/contrib/ltree/uninstall_ltree.sql,v 1.5 2007/11/13 04:24:28 momjian Exp $ */
/* $PostgreSQL: pgsql/contrib/ltree/uninstall_ltree.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;
@ -15,7 +15,7 @@ DROP FUNCTION _ltree_penalty(internal,internal,internal);
DROP FUNCTION _ltree_compress(internal);
DROP FUNCTION _ltree_consistent(internal,internal,int2);
DROP FUNCTION _ltree_consistent(internal,internal,int2,oid,internal);
DROP OPERATOR ?@ (_ltree, ltxtquery);
@ -107,7 +107,7 @@ DROP FUNCTION ltree_decompress(internal);
DROP FUNCTION ltree_compress(internal);
DROP FUNCTION ltree_consistent(internal,internal,int2);
DROP FUNCTION ltree_consistent(internal,internal,int2,oid,internal);
DROP TYPE ltree_gist CASCADE;