postgresql/src/backend/access/rtree/rtstrat.c
Tom Lane b90f8f20f0 Extend r-tree operator classes to handle Y-direction tests equivalent
to the existing X-direction tests.  An rtree class now includes 4 actual
2-D tests, 4 1-D X-direction tests, and 4 1-D Y-direction tests.
This involved adding four new Y-direction test operators for each of
box and polygon; I followed the PostGIS project's lead as to the names
of these operators.
NON BACKWARDS COMPATIBLE CHANGE: the poly_overleft (&<) and poly_overright
(&>) operators now have semantics comparable to box_overleft and box_overright.
This is necessary to make r-tree indexes work correctly on polygons.
Also, I changed circle_left and circle_right to agree with box_left and
box_right --- formerly they allowed the boundaries to touch.  This isn't
actually essential given the lack of any r-tree opclass for circles, but
it seems best to sync all the definitions while we are at it.
2005-06-24 20:53:34 +00:00

80 lines
2.4 KiB
C

/*-------------------------------------------------------------------------
*
* rtstrat.c
* strategy map data for rtrees.
*
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/rtree/rtstrat.c,v 1.27 2005/06/24 20:53:30 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "access/rtree.h"
/*
* Here's something peculiar to rtrees that doesn't apply to most other
* indexing structures: When we're searching a tree for a given value, we
* can't do the same sorts of comparisons on internal node entries as we
* do at leaves. The reason is that if we're looking for (say) all boxes
* that are the same as (0,0,10,10), then we need to find all leaf pages
* that overlap that region. So internally we search for overlap, and at
* the leaf we search for equality.
*
* This array maps leaf search operators to the internal search operators.
*/
static const StrategyNumber RTOperMap[RTNStrategies] = {
RTOverRightStrategyNumber, /* left */
RTRightStrategyNumber, /* overleft */
RTOverlapStrategyNumber, /* overlap */
RTLeftStrategyNumber, /* overright */
RTOverLeftStrategyNumber, /* right */
RTContainsStrategyNumber, /* same */
RTContainsStrategyNumber, /* contains */
RTOverlapStrategyNumber, /* contained-by */
RTAboveStrategyNumber, /* overbelow */
RTOverAboveStrategyNumber, /* below */
RTOverBelowStrategyNumber, /* above */
RTBelowStrategyNumber /* overabove */
};
/*
* We may need to negate the result of the selected operator. (This could
* be avoided by expanding the set of operators required for an opclass.)
*/
static const bool RTNegateMap[RTNStrategies] = {
true, /* left */
true, /* overleft */
false, /* overlap */
true, /* overright */
true, /* right */
false, /* same */
false, /* contains */
false, /* contained-by */
true, /* overbelow */
true, /* below */
true, /* above */
true /* overabove */
};
StrategyNumber
RTMapToInternalOperator(StrategyNumber strat)
{
Assert(strat > 0 && strat <= RTNStrategies);
return RTOperMap[strat - 1];
}
bool
RTMapToInternalNegate(StrategyNumber strat)
{
Assert(strat > 0 && strat <= RTNStrategies);
return RTNegateMap[strat - 1];
}