From 9a09248eddf12339677169064c88e4df11e5077f Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 24 Jun 2005 00:18:52 +0000 Subject: Fix rtree and contrib/rtree_gist search behavior for the 1-D box and polygon operators (<<, &<, >>, &>). Per ideas originally put forward by andrew@supernews and later rediscovered by moi. This patch just fixes the existing opclasses, and does not add any new behavior as I proposed earlier; that can be sorted out later. In principle this could be back-patched, since it changes only search behavior and not system catalog entries nor rtree index contents. I'm not currently planning to do that, though, since I think it could use more testing. --- contrib/rtree_gist/rtree_gist.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'contrib/rtree_gist/rtree_gist.c') diff --git a/contrib/rtree_gist/rtree_gist.c b/contrib/rtree_gist/rtree_gist.c index 55a480915fb..f4ce58460fb 100644 --- a/contrib/rtree_gist/rtree_gist.c +++ b/contrib/rtree_gist/rtree_gist.c @@ -2,12 +2,12 @@ * * rtree_gist.c * pg_amproc entries for GiSTs over 2-D boxes. - * This gives R-tree behavior, with Guttman's poly-time split algorithm. * + * This gives R-tree behavior, with Guttman's poly-time split algorithm. * * * IDENTIFICATION - * $PostgreSQL: pgsql/contrib/rtree_gist/rtree_gist.c,v 1.12 2005/05/25 21:40:40 momjian Exp $ + * $PostgreSQL: pgsql/contrib/rtree_gist/rtree_gist.c,v 1.13 2005/06/24 00:18:52 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -78,7 +78,7 @@ gbox_consistent(PG_FUNCTION_ARGS) StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); /* - * * if entry is not leaf, use gbox_internal_consistent, * else use + * if entry is not leaf, use rtree_internal_consistent, else use * gbox_leaf_consistent */ if (!(DatumGetPointer(entry->key) != NULL && query)) @@ -509,8 +509,9 @@ gpoly_consistent(PG_FUNCTION_ARGS) bool result; /* - * * if entry is not leaf, use gbox_internal_consistent, * else use - * gbox_leaf_consistent + * Since the operators are marked lossy anyway, we can just use + * rtree_internal_consistent even at leaf nodes. (This works + * in part because the index entries are bounding Boxes not polygons.) */ if (!(DatumGetPointer(entry->key) != NULL && query)) PG_RETURN_BOOL(FALSE); @@ -536,15 +537,19 @@ rtree_internal_consistent(BOX *key, switch (strategy) { case RTLeftStrategyNumber: + retval = !DatumGetBool(DirectFunctionCall2(box_overright, PointerGetDatum(key), PointerGetDatum(query))); + break; case RTOverLeftStrategyNumber: - retval = DatumGetBool(DirectFunctionCall2(box_overleft, PointerGetDatum(key), PointerGetDatum(query))); + retval = !DatumGetBool(DirectFunctionCall2(box_right, PointerGetDatum(key), PointerGetDatum(query))); break; case RTOverlapStrategyNumber: retval = DatumGetBool(DirectFunctionCall2(box_overlap, PointerGetDatum(key), PointerGetDatum(query))); break; case RTOverRightStrategyNumber: + retval = !DatumGetBool(DirectFunctionCall2(box_left, PointerGetDatum(key), PointerGetDatum(query))); + break; case RTRightStrategyNumber: - retval = DatumGetBool(DirectFunctionCall2(box_right, PointerGetDatum(key), PointerGetDatum(query))); + retval = !DatumGetBool(DirectFunctionCall2(box_overleft, PointerGetDatum(key), PointerGetDatum(query))); break; case RTSameStrategyNumber: case RTContainsStrategyNumber: -- cgit v1.2.3