summaryrefslogtreecommitdiff
path: root/contrib/intarray/_int_gin.c
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/_int_gin.c
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/_int_gin.c')
-rw-r--r--contrib/intarray/_int_gin.c44
1 files changed, 35 insertions, 9 deletions
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);