diff --git a/src/backend/access/gist/gistproc.c b/src/backend/access/gist/gistproc.c index 1795a71..0ebec52 100644 --- a/src/backend/access/gist/gistproc.c +++ b/src/backend/access/gist/gistproc.c @@ -165,7 +165,8 @@ gist_box_compress(PG_FUNCTION_ARGS) } /* - * GiST DeCompress method for boxes (also used for polygons and circles) + * GiST DeCompress method for boxes (also used for points, polygons + * and circles) * * do not do anything --- we just use the stored box as is. */ @@ -176,7 +177,7 @@ gist_box_decompress(PG_FUNCTION_ARGS) } /* - * The GiST Penalty method for boxes + * The GiST Penalty method for boxes (also used for points) * * As in the R-tree paper, we use change in area as our penalty metric */ @@ -341,6 +342,8 @@ fallbackSplit(GistEntryVector *entryvec, GIST_SPLITVEC *v) * * New linear algorithm, see 'New Linear Node Splitting Algorithm for R-tree', * C.H.Ang and T.C.Tan + * + * This is used for both boxes and points. */ Datum gist_box_picksplit(PG_FUNCTION_ARGS) @@ -533,6 +536,8 @@ gist_box_picksplit(PG_FUNCTION_ARGS) /* * Equality method + * + * This is used for both boxes and points. */ Datum gist_box_same(PG_FUNCTION_ARGS) @@ -873,25 +878,25 @@ gist_circle_consistent(PG_FUNCTION_ARGS) PG_RETURN_BOOL(result); } - - -/* - * Point - */ +/************************************************** + * Point ops + **************************************************/ Datum -gist_point_compress(PG_FUNCTION_ARGS) { +gist_point_compress(PG_FUNCTION_ARGS) +{ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); - if ( entry->leafkey ) { /* Point, actually */ - BOX *box = palloc(sizeof(BOX)); - Point *point = DatumGetPointP(entry->key); - GISTENTRY *retval = palloc(sizeof(GISTENTRY)); + if (entry->leafkey) /* Point, actually */ + { + BOX *box = palloc(sizeof(BOX)); + Point *point = DatumGetPointP(entry->key); + GISTENTRY *retval = palloc(sizeof(GISTENTRY)); box->high = box->low = *point; gistentryinit(*retval, BoxPGetDatum(box), - entry->rel, entry->page, entry->offset, FALSE); + entry->rel, entry->page, entry->offset, FALSE); PG_RETURN_POINTER(retval); } @@ -900,11 +905,12 @@ gist_point_compress(PG_FUNCTION_ARGS) { } static bool -gist_point_consistent_internal(StrategyNumber strategy, bool isLeaf, BOX *key, Point *query) +gist_point_consistent_internal(StrategyNumber strategy, + bool isLeaf, BOX *key, Point *query) { bool result = false; - switch( strategy ) + switch (strategy) { case RTLeftStrategyNumber: result = FPlt(key->low.x, query->x); @@ -921,7 +927,8 @@ gist_point_consistent_internal(StrategyNumber strategy, bool isLeaf, BOX *key, P case RTSameStrategyNumber: if (isLeaf) { - result = FPeq(key->low.x, query->x) && FPeq(key->low.y, query->y); + result = FPeq(key->low.x, query->x) + && FPeq(key->low.y, query->y); } else { @@ -936,97 +943,100 @@ gist_point_consistent_internal(StrategyNumber strategy, bool isLeaf, BOX *key, P return result; } -#define StrategyNumberOffsetRange 20 +#define GeoStrategyNumberOffset 20 #define PointStrategyNumberGroup 0 #define BoxStrategyNumberGroup 1 #define PolygonStrategyNumberGroup 2 #define CircleStrategyNumberGroup 3 Datum -gist_point_consistent(PG_FUNCTION_ARGS) { +gist_point_consistent(PG_FUNCTION_ARGS) +{ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); - StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); + StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); bool result; bool *recheck = (bool *) PG_GETARG_POINTER(4); - StrategyNumber strategyGroup = strategy / StrategyNumberOffsetRange; + StrategyNumber strategyGroup = strategy / GeoStrategyNumberOffset; - switch(strategyGroup) + switch (strategyGroup) { - case PointStrategyNumberGroup: - result = gist_point_consistent_internal(strategy % StrategyNumberOffsetRange, + case PointStrategyNumberGroup: + result = gist_point_consistent_internal(strategy % GeoStrategyNumberOffset, GIST_LEAF(entry), DatumGetBoxP(entry->key), PG_GETARG_POINT_P(1)); *recheck = false; break; - case BoxStrategyNumberGroup: - result = DatumGetBool( DirectFunctionCall5( + case BoxStrategyNumberGroup: + result = DatumGetBool(DirectFunctionCall5( gist_box_consistent, PointerGetDatum(entry), PG_GETARG_DATUM(1), Int16GetDatum(RTOverlapStrategyNumber), 0, PointerGetDatum(recheck))); break; - case PolygonStrategyNumberGroup: - do { + case PolygonStrategyNumberGroup: + { POLYGON *query = PG_GETARG_POLYGON_P(1); - result = DatumGetBool( DirectFunctionCall5( + result = DatumGetBool(DirectFunctionCall5( gist_poly_consistent, PointerGetDatum(entry), PolygonPGetDatum(query), Int16GetDatum(RTOverlapStrategyNumber), 0, PointerGetDatum(recheck))); - if ( GIST_LEAF(entry) && result ) { + if (GIST_LEAF(entry) && result) + { /* * We are on leaf page and quick check shows overlapping * of polygon's bounding box and point */ BOX *box = DatumGetBoxP(entry->key); - Assert( box->high.x == box->low.x && box->high.y == box->low.y ); - - result = DatumGetBool( DirectFunctionCall2( + Assert(box->high.x == box->low.x + && box->high.y == box->low.y); + result = DatumGetBool(DirectFunctionCall2( poly_contain_pt, PolygonPGetDatum(query), PointPGetDatum(&box->high))); *recheck = false; } - } while (0); + } break; - case CircleStrategyNumberGroup: - do { + case CircleStrategyNumberGroup: + { CIRCLE *query = PG_GETARG_CIRCLE_P(1); - result = DatumGetBool( DirectFunctionCall5( + result = DatumGetBool(DirectFunctionCall5( gist_circle_consistent, PointerGetDatum(entry), CirclePGetDatum(query), Int16GetDatum(RTOverlapStrategyNumber), 0, PointerGetDatum(recheck))); - if ( GIST_LEAF(entry) && result ) { + if (GIST_LEAF(entry) && result) + { /* * We are on leaf page and quick check shows overlapping * of polygon's bounding box and point */ BOX *box = DatumGetBoxP(entry->key); - Assert( box->high.x == box->low.x && box->high.y == box->low.y ); - - result = DatumGetBool( DirectFunctionCall2( + Assert(box->high.x == box->low.x + && box->high.y == box->low.y); + result = DatumGetBool(DirectFunctionCall2( circle_contain_pt, CirclePGetDatum(query), PointPGetDatum(&box->high))); *recheck = false; } - } while(0); + } break; default: + result = false; /* silence compiler warning */ elog(ERROR, "unknown strategy number: %d", strategy); } PG_RETURN_BOOL(result); } -