summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas2011-10-09 15:55:27 +0000
committerHeikki Linnakangas2011-10-09 15:59:34 +0000
commitd50e1251946a6e59092f0a84fc903532eb599a4f (patch)
tree0f09256b7f506267b801ed874b08077730d57dff
parentcbfa92c23c3924d53889320cdbe26f23ee23e40c (diff)
Clean up a couple of box gist helper functions.
The original idea of this patch was to make box picksplit run faster, by eliminating unnecessary palloc() overhead, but that was obsoleted by the new double-sorting split algorithm that doesn't call these functions so heavily anymore. Nevertheless, the code looks better this way. Original patch by me, reviewed and tidied up after the double-sorting patch by Kevin Grittner.
-rw-r--r--src/backend/access/gist/gistproc.c31
1 files changed, 13 insertions, 18 deletions
diff --git a/src/backend/access/gist/gistproc.c b/src/backend/access/gist/gistproc.c
index f7eb9412f9..2b68e218a4 100644
--- a/src/backend/access/gist/gistproc.c
+++ b/src/backend/access/gist/gistproc.c
@@ -23,7 +23,7 @@
static bool gist_box_leaf_consistent(BOX *key, BOX *query,
StrategyNumber strategy);
-static double size_box(Datum dbox);
+static double size_box(BOX *box);
static bool rtree_internal_consistent(BOX *key, BOX *query,
StrategyNumber strategy);
@@ -35,21 +35,16 @@ static bool rtree_internal_consistent(BOX *key, BOX *query,
* Box ops
**************************************************/
-static Datum
-rt_box_union(PG_FUNCTION_ARGS)
+/*
+ * Calculates union of two boxes, a and b. The result is stored in *n.
+ */
+static void
+rt_box_union(BOX *n, BOX *a, BOX *b)
{
- BOX *a = PG_GETARG_BOX_P(0);
- BOX *b = PG_GETARG_BOX_P(1);
- BOX *n;
-
- n = (BOX *) palloc(sizeof(BOX));
-
n->high.x = Max(a->high.x, b->high.x);
n->high.y = Max(a->high.y, b->high.y);
n->low.x = Min(a->low.x, b->low.x);
n->low.y = Min(a->low.y, b->low.y);
-
- PG_RETURN_BOX_P(n);
}
/*
@@ -166,10 +161,12 @@ gist_box_penalty(PG_FUNCTION_ARGS)
GISTENTRY *origentry = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY *newentry = (GISTENTRY *) PG_GETARG_POINTER(1);
float *result = (float *) PG_GETARG_POINTER(2);
- Datum ud;
+ BOX *origbox = DatumGetBoxP(origentry->key);
+ BOX *newbox = DatumGetBoxP(newentry->key);
+ BOX unionbox;
- ud = DirectFunctionCall2(rt_box_union, origentry->key, newentry->key);
- *result = (float) (size_box(ud) - size_box(origentry->key));
+ rt_box_union(&unionbox, origbox, newbox);
+ *result = (float) (size_box(&unionbox) - size_box(origbox));
PG_RETURN_POINTER(result);
}
@@ -937,11 +934,9 @@ gist_box_leaf_consistent(BOX *key, BOX *query, StrategyNumber strategy)
}
static double
-size_box(Datum dbox)
+size_box(BOX *box)
{
- BOX *box = DatumGetBoxP(dbox);
-
- if (box == NULL || box->high.x <= box->low.x || box->high.y <= box->low.y)
+ if (box->high.x <= box->low.x || box->high.y <= box->low.y)
return 0.0;
return (box->high.x - box->low.x) * (box->high.y - box->low.y);
}