summaryrefslogtreecommitdiff
path: root/contrib/intarray
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-04-14 17:05:34 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-04-14 17:05:34 +0000
commit9b5c8d45f62bd3d243a40cc84deb93893f2f5122 (patch)
tree2d75607f7bdb96cfa1d73a3a36a4b3328118ff08 /contrib/intarray
parent10be77c173211a75718f50fe6061862f6a0cb4a2 (diff)
downloadpostgresql-9b5c8d45f62bd3d243a40cc84deb93893f2f5122.tar.gz
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.
Diffstat (limited to 'contrib/intarray')
-rw-r--r--contrib/intarray/_int.sql.in36
-rw-r--r--contrib/intarray/_int_gin.c44
-rw-r--r--contrib/intarray/_int_gist.c5
-rw-r--r--contrib/intarray/_intbig_gist.c5
-rw-r--r--contrib/intarray/uninstall__int.sql8
5 files changed, 67 insertions, 31 deletions
diff --git a/contrib/intarray/_int.sql.in b/contrib/intarray/_int.sql.in
index 9753f14fbf..c681626dc9 100644
--- a/contrib/intarray/_int.sql.in
+++ b/contrib/intarray/_int.sql.in
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/contrib/intarray/_int.sql.in,v 1.27 2007/11/13 04:24:28 momjian Exp $ */
+/* $PostgreSQL: pgsql/contrib/intarray/_int.sql.in,v 1.28 2008/04/14 17:05:32 tgl Exp $ */
-- Adjust this setting to control where the objects get created.
SET search_path = public;
@@ -323,7 +323,7 @@ CREATE OPERATOR & (
--------------
-- define the GiST support methods
-CREATE OR REPLACE FUNCTION g_int_consistent(internal,_int4,int4)
+CREATE OR REPLACE FUNCTION g_int_consistent(internal,_int4,int,oid,internal)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE;
@@ -364,13 +364,13 @@ LANGUAGE C IMMUTABLE;
CREATE OPERATOR CLASS gist__int_ops
DEFAULT FOR TYPE _int4 USING gist AS
OPERATOR 3 &&,
- OPERATOR 6 = (anyarray, anyarray) RECHECK,
+ OPERATOR 6 = (anyarray, anyarray),
OPERATOR 7 @>,
OPERATOR 8 <@,
OPERATOR 13 @,
OPERATOR 14 ~,
OPERATOR 20 @@ (_int4, query_int),
- FUNCTION 1 g_int_consistent (internal, _int4, int4),
+ FUNCTION 1 g_int_consistent (internal, _int4, int, oid, internal),
FUNCTION 2 g_int_union (internal, internal),
FUNCTION 3 g_int_compress (internal),
FUNCTION 4 g_int_decompress (internal),
@@ -400,7 +400,7 @@ CREATE TYPE intbig_gkey (
OUTPUT = _intbig_out
);
-CREATE OR REPLACE FUNCTION g_intbig_consistent(internal,internal,int4)
+CREATE OR REPLACE FUNCTION g_intbig_consistent(internal,internal,int,oid,internal)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE;
@@ -440,14 +440,14 @@ LANGUAGE C IMMUTABLE;
CREATE OPERATOR CLASS gist__intbig_ops
FOR TYPE _int4 USING gist
AS
- OPERATOR 3 && RECHECK,
- OPERATOR 6 = (anyarray, anyarray) RECHECK,
- OPERATOR 7 @> RECHECK,
- OPERATOR 8 <@ RECHECK,
- OPERATOR 13 @ RECHECK,
- OPERATOR 14 ~ RECHECK,
- OPERATOR 20 @@ (_int4, query_int) RECHECK,
- FUNCTION 1 g_intbig_consistent (internal, internal, int4),
+ OPERATOR 3 &&,
+ OPERATOR 6 = (anyarray, anyarray),
+ OPERATOR 7 @>,
+ OPERATOR 8 <@,
+ OPERATOR 13 @,
+ OPERATOR 14 ~,
+ OPERATOR 20 @@ (_int4, query_int),
+ FUNCTION 1 g_intbig_consistent (internal, internal, int, oid, internal),
FUNCTION 2 g_intbig_union (internal, internal),
FUNCTION 3 g_intbig_compress (internal),
FUNCTION 4 g_intbig_decompress (internal),
@@ -463,7 +463,7 @@ RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE;
-CREATE OR REPLACE FUNCTION ginint4_consistent(internal, int2, internal)
+CREATE OR REPLACE FUNCTION ginint4_consistent(internal, int2, internal, internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE;
@@ -472,14 +472,14 @@ CREATE OPERATOR CLASS gin__int_ops
FOR TYPE _int4 USING gin
AS
OPERATOR 3 &&,
- OPERATOR 6 = (anyarray, anyarray) RECHECK,
+ OPERATOR 6 = (anyarray, anyarray),
OPERATOR 7 @>,
- OPERATOR 8 <@ RECHECK,
+ OPERATOR 8 <@,
OPERATOR 13 @,
- OPERATOR 14 ~ RECHECK,
+ OPERATOR 14 ~,
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),
+ FUNCTION 4 ginint4_consistent (internal, int2, internal, internal),
STORAGE int4;
diff --git a/contrib/intarray/_int_gin.c b/contrib/intarray/_int_gin.c
index 6856a68e03..8b6e99edae 100644
--- a/contrib/intarray/_int_gin.c
+++ b/contrib/intarray/_int_gin.c
@@ -82,50 +82,76 @@ ginint4_consistent(PG_FUNCTION_ARGS)
{
bool *check = (bool *) PG_GETARG_POINTER(0);
StrategyNumber strategy = PG_GETARG_UINT16(1);
- int res = FALSE;
+ bool *recheck = (bool *) PG_GETARG_POINTER(3);
+ bool res = FALSE;
/*
- * we can do not check array carefully, it's done by previous
+ * we need not check array carefully, it's done by previous
* ginarrayextract call
*/
switch (strategy)
{
case RTOverlapStrategyNumber:
+ /* result is not lossy */
+ *recheck = false;
+ /* at least one element in check[] is true, so result = true */
+ res = TRUE;
+ break;
case RTContainedByStrategyNumber:
case RTOldContainedByStrategyNumber:
+ /* we will need recheck */
+ *recheck = true;
/* at least one element in check[] is true, so result = true */
-
res = TRUE;
break;
case RTSameStrategyNumber:
+ {
+ ArrayType *query = PG_GETARG_ARRAYTYPE_P(2);
+ int i,
+ nentries = ARRNELEMS(query);
+
+ /* we will need recheck */
+ *recheck = true;
+ res = TRUE;
+ for (i = 0; i < nentries; i++)
+ if (!check[i])
+ {
+ res = FALSE;
+ break;
+ }
+ }
+ break;
case RTContainsStrategyNumber:
case RTOldContainsStrategyNumber:
- res = TRUE;
- do
{
ArrayType *query = PG_GETARG_ARRAYTYPE_P(2);
int i,
nentries = ARRNELEMS(query);
+ /* result is not lossy */
+ *recheck = false;
+ res = TRUE;
for (i = 0; i < nentries; i++)
if (!check[i])
{
res = FALSE;
break;
}
- } while (0);
+ }
break;
case BooleanSearchStrategy:
- do
{
QUERYTYPE *query = (QUERYTYPE *) PG_DETOAST_DATUM(PG_GETARG_POINTER(2));
+ /* result is not lossy */
+ *recheck = false;
res = ginconsistent(query, check);
- } while (0);
+ }
break;
default:
- elog(ERROR, "ginint4_consistent: unknown strategy number: %d", strategy);
+ elog(ERROR, "ginint4_consistent: unknown strategy number: %d",
+ strategy);
}
PG_RETURN_BOOL(res);
diff --git a/contrib/intarray/_int_gist.c b/contrib/intarray/_int_gist.c
index abd576223e..37c05784b9 100644
--- a/contrib/intarray/_int_gist.c
+++ b/contrib/intarray/_int_gist.c
@@ -34,8 +34,13 @@ g_int_consistent(PG_FUNCTION_ARGS)
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
ArrayType *query = (ArrayType *) PG_DETOAST_DATUM_COPY(PG_GETARG_POINTER(1));
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+ /* Oid subtype = PG_GETARG_OID(3); */
+ bool *recheck = (bool *) PG_GETARG_POINTER(4);
bool retval;
+ /* this is exact except for RTSameStrategyNumber */
+ *recheck = (strategy == RTSameStrategyNumber);
+
if (strategy == BooleanSearchStrategy)
{
retval = execconsistent((QUERYTYPE *) query,
diff --git a/contrib/intarray/_intbig_gist.c b/contrib/intarray/_intbig_gist.c
index 3bfbc84dc7..b96c6d7289 100644
--- a/contrib/intarray/_intbig_gist.c
+++ b/contrib/intarray/_intbig_gist.c
@@ -498,8 +498,13 @@ g_intbig_consistent(PG_FUNCTION_ARGS)
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
ArrayType *query = (ArrayType *) PG_DETOAST_DATUM(PG_GETARG_POINTER(1));
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+ /* Oid subtype = PG_GETARG_OID(3); */
+ bool *recheck = (bool *) PG_GETARG_POINTER(4);
bool retval;
+ /* All cases served by this function are inexact */
+ *recheck = true;
+
if (ISALLTRUE(DatumGetPointer(entry->key)))
PG_RETURN_BOOL(true);
diff --git a/contrib/intarray/uninstall__int.sql b/contrib/intarray/uninstall__int.sql
index 9ef269ec21..59ef2afc0f 100644
--- a/contrib/intarray/uninstall__int.sql
+++ b/contrib/intarray/uninstall__int.sql
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/contrib/intarray/uninstall__int.sql,v 1.8 2007/11/13 04:24:28 momjian Exp $ */
+/* $PostgreSQL: pgsql/contrib/intarray/uninstall__int.sql,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;
@@ -7,7 +7,7 @@ DROP OPERATOR CLASS gin__int_ops USING gin;
DROP FUNCTION ginint4_queryextract(internal, internal, int2);
-DROP FUNCTION ginint4_consistent(internal, int2, internal);
+DROP FUNCTION ginint4_consistent(internal, int2, internal, internal);
DROP OPERATOR CLASS gist__intbig_ops USING gist;
@@ -23,7 +23,7 @@ DROP FUNCTION g_intbig_decompress(internal);
DROP FUNCTION g_intbig_compress(internal);
-DROP FUNCTION g_intbig_consistent(internal,internal,int4);
+DROP FUNCTION g_intbig_consistent(internal,internal,int,oid,internal);
DROP TYPE intbig_gkey CASCADE;
@@ -41,7 +41,7 @@ DROP FUNCTION g_int_decompress(internal);
DROP FUNCTION g_int_compress(internal);
-DROP FUNCTION g_int_consistent(internal,_int4,int4);
+DROP FUNCTION g_int_consistent(internal,_int4,int,oid,internal);
DROP OPERATOR & (_int4, _int4);