32 #define LIMIT_RATIO 0.3
116 numranges = entryvec->
n;
119 memcpy((
void *) pageunion, (
void *) cur,
sizeof(
BOX));
121 for (i = 1; i < numranges; i++)
126 *sizep =
sizeof(
BOX);
197 maxoff = entryvec->
n - 1;
295 else if (lower1 > lower2)
312 else if (upper1 > upper2)
335 double rightLower,
int minLeftCount,
336 double leftUpper,
int maxLeftCount)
350 leftCount = minLeftCount;
354 if (maxLeftCount <= context->entriesCount / 2)
355 leftCount = maxLeftCount;
365 ratio = ((
float4)
Min(leftCount, rightCount)) /
370 bool selectthis =
false;
384 overlap = (leftUpper - rightLower) / range;
389 else if (context->
dim == dimNum)
395 if (overlap < context->overlap ||
396 (overlap == context->
overlap && ratio > context->
ratio))
419 (range > context->
range &&
427 context->
first =
false;
428 context->
ratio = ratio;
433 context->
dim = dimNum;
447 union_width =
Max(original->
high.
x, new->high.x) -
448 Min(original->
low.
x, new->low.x);
449 union_height =
Max(original->
high.
y, new->high.y) -
450 Min(original->
low.
y, new->low.y);
451 return union_width * union_height - (original->
high.
x - original->
low.
x) *
466 else if (delta1 > delta2)
518 maxoff = entryvec->
n - 1;
531 if (i == FirstOffsetNumber)
540 context.
first =
true;
541 for (dim = 0; dim < 2; dim++)
568 memcpy(intervalsUpper, intervalsLower,
611 rightLower = intervalsLower[i1].
lower;
612 leftUpper = intervalsUpper[i2].
lower;
618 while (i1 < nentries && rightLower == intervalsLower[i1].
lower)
620 leftUpper =
Max(leftUpper, intervalsLower[i1].
upper);
625 rightLower = intervalsLower[i1].
lower;
631 while (i2 < nentries && intervalsUpper[i2].
upper <= leftUpper)
646 rightLower = intervalsLower[i1].
upper;
647 leftUpper = intervalsUpper[i2].
upper;
653 while (i2 >= 0 && leftUpper == intervalsUpper[i2].
upper)
655 rightLower =
Min(rightLower, intervalsUpper[i2].
lower);
660 leftUpper = intervalsUpper[i2].
upper;
666 while (i1 >= 0 && intervalsLower[i1].
lower >= rightLower)
673 rightLower, i1 + 1, leftUpper, i2 + 1);
708 commonEntriesCount = 0;
712 #define PLACE_LEFT(box, off) \
714 if (v->spl_nleft > 0) \
715 adjustBox(leftBox, box); \
718 v->spl_left[v->spl_nleft++] = off; \
721 #define PLACE_RIGHT(box, off) \
723 if (v->spl_nright > 0) \
724 adjustBox(rightBox, box); \
726 *rightBox = *(box); \
727 v->spl_right[v->spl_nright++] = off; \
743 if (context.
dim == 0)
760 commonEntries[commonEntriesCount++].
index =
i;
785 if (commonEntriesCount > 0)
797 for (i = 0; i < commonEntriesCount; i++)
813 for (i = 0; i < commonEntriesCount; i++)
821 if (v->
spl_nleft + (commonEntriesCount - i) <= m)
823 else if (v->
spl_nright + (commonEntriesCount - i) <= m)
862 *result = (b1 ==
NULL && b2 ==
NULL);
939 elog(
ERROR,
"unrecognized strategy number: %d", strategy);
1030 elog(
ERROR,
"unrecognized strategy number: %d", strategy);
1056 memcpy((
void *) r, (
void *) &(in->
boundbox),
sizeof(
BOX));
1188 box->
high = box->
low = *point;
1226 #define point_point_distance(p1,p2) \
1227 DatumGetFloat8(DirectFunctionCall2(point_distance, \
1228 PointPGetDatum(p1), PointPGetDatum(p2)))
1233 double result = 0.0;
1240 else if (point->
x <= box->
high.
x && point->
x >= box->
low.
x &&
1241 point->
y <= box->
high.
y && point->
y >= box->
low.
y)
1246 else if (point->
x <= box->
high.
x && point->
x >= box->
low.
x)
1250 if (point->
y > box->
high.
y)
1251 result = point->
y - box->
high.
y;
1252 else if (point->
y < box->
low.
y)
1253 result = box->
low.
y - point->
y;
1255 elog(
ERROR,
"inconsistent point values");
1257 else if (point->
y <= box->
high.
y && point->
y >= box->
low.
y)
1261 if (point->
x > box->
high.
x)
1262 result = point->
x - box->
high.
x;
1263 else if (point->
x < box->
low.
x)
1264 result = box->
low.
x - point->
x;
1266 elog(
ERROR,
"inconsistent point values");
1277 if (result > subresult)
1283 if (result > subresult)
1289 if (result > subresult)
1298 bool isLeaf,
BOX *key,
Point *query)
1300 bool result =
false;
1332 elog(
ERROR,
"unrecognized strategy number: %d", strategy);
1340 #define GeoStrategyNumberOffset 20
1341 #define PointStrategyNumberGroup 0
1342 #define BoxStrategyNumberGroup 1
1343 #define PolygonStrategyNumberGroup 2
1344 #define CircleStrategyNumberGroup 3
1355 switch (strategyGroup)
1384 result = (key->
high.
x >= query->
low.
x &&
1450 elog(
ERROR,
"unrecognized strategy number: %d", strategy);
1466 switch (strategyGroup)
1474 elog(
ERROR,
"unrecognized strategy number: %d", strategy);
1502 switch (strategyGroup)
1510 elog(
ERROR,
"unrecognized strategy number: %d", strategy);
Datum box_right(PG_FUNCTION_ARGS)
#define PG_RETURN_POINTER(x)
Datum box_contained(PG_FUNCTION_ARGS)
static bool rtree_internal_consistent(BOX *key, BOX *query, StrategyNumber strategy)
#define GeoStrategyNumberOffset
Datum box_same(PG_FUNCTION_ARGS)
static struct cvec * range(struct vars *v, celt a, celt b, int cases)
#define PLACE_LEFT(box, off)
#define BoxStrategyNumberGroup
static bool gist_box_leaf_consistent(BOX *key, BOX *query, StrategyNumber strategy)
Datum gist_box_decompress(PG_FUNCTION_ARGS)
#define PG_GETARG_BOX_P(n)
Datum box_left(PG_FUNCTION_ARGS)
Datum gist_box_fetch(PG_FUNCTION_ARGS)
#define RTOldContainsStrategyNumber
static double size_box(BOX *box)
#define RTOldContainedByStrategyNumber
#define RTLeftStrategyNumber
Datum lower(PG_FUNCTION_ARGS)
static void adjustBox(BOX *b, BOX *addon)
static int interval_cmp_lower(const void *i1, const void *i2)
Datum box_overright(PG_FUNCTION_ARGS)
#define CircleStrategyNumberGroup
#define PointerGetDatum(X)
#define PG_GETARG_DATUM(n)
static int interval_cmp_upper(const void *i1, const void *i2)
#define PG_RETURN_FLOAT8(x)
#define PolygonPGetDatum(X)
Datum gist_point_consistent(PG_FUNCTION_ARGS)
Datum box_overlap(PG_FUNCTION_ARGS)
#define RTOverBelowStrategyNumber
static int common_entry_cmp(const void *i1, const void *i2)
Datum gist_box_same(PG_FUNCTION_ARGS)
Datum gist_box_picksplit(PG_FUNCTION_ARGS)
static double box_penalty(BOX *original, BOX *new)
#define RTContainedByStrategyNumber
#define PG_GETARG_POINTER(n)
Datum poly_contain_pt(PG_FUNCTION_ARGS)
Datum gist_point_fetch(PG_FUNCTION_ARGS)
Datum upper(PG_FUNCTION_ARGS)
#define PLACE_RIGHT(box, off)
#define RTBelowStrategyNumber
#define PG_GETARG_POLYGON_P(n)
Datum gist_box_consistent(PG_FUNCTION_ARGS)
#define PointStrategyNumberGroup
Datum gist_poly_compress(PG_FUNCTION_ARGS)
GISTENTRY vector[FLEXIBLE_ARRAY_MEMBER]
#define RTOverAboveStrategyNumber
#define CirclePGetDatum(X)
Datum gist_point_distance(PG_FUNCTION_ARGS)
#define point_point_distance(p1, p2)
#define PG_GETARG_POINT_P(n)
static void g_box_consider_split(ConsiderSplitContext *context, int dimNum, double rightLower, int minLeftCount, double leftUpper, int maxLeftCount)
Datum box_contain(PG_FUNCTION_ARGS)
static void rt_box_union(BOX *n, BOX *a, BOX *b)
Datum box_above(PG_FUNCTION_ARGS)
#define DatumGetCircleP(X)
#define FirstOffsetNumber
#define RTSameStrategyNumber
static void fallbackSplit(GistEntryVector *entryvec, GIST_SPLITVEC *v)
#define RTOverRightStrategyNumber
static double gist_bbox_distance(GISTENTRY *entry, Datum query, StrategyNumber strategy, bool *recheck)
static bool gist_point_consistent_internal(StrategyNumber strategy, bool isLeaf, BOX *key, Point *query)
#define DirectFunctionCall5(func, arg1, arg2, arg3, arg4, arg5)
#define RTOverLeftStrategyNumber
void * palloc0(Size size)
#define PG_RETURN_BOOL(x)
Datum circle_contain_pt(PG_FUNCTION_ARGS)
Datum gist_circle_consistent(PG_FUNCTION_ARGS)
Datum gist_box_compress(PG_FUNCTION_ARGS)
Datum box_overbelow(PG_FUNCTION_ARGS)
#define PolygonStrategyNumberGroup
#define PG_GETARG_CIRCLE_P(n)
Datum gist_box_penalty(PG_FUNCTION_ARGS)
Datum gist_circle_compress(PG_FUNCTION_ARGS)
Datum box_below(PG_FUNCTION_ARGS)
#define RTAboveStrategyNumber
static double computeDistance(bool isLeaf, BOX *box, Point *point)
#define Assert(condition)
#define gistentryinit(e, k, r, pg, o, l)
#define RTRightStrategyNumber
#define DatumGetPointP(X)
static float non_negative(float val)
Datum box_overleft(PG_FUNCTION_ARGS)
#define OffsetNumberNext(offsetNumber)
#define PG_FREE_IF_COPY(ptr, n)
#define RTContainsStrategyNumber
Datum gist_poly_consistent(PG_FUNCTION_ARGS)
Datum gist_point_compress(PG_FUNCTION_ARGS)
#define PG_GETARG_UINT16(n)
#define DatumGetPolygonP(X)
Datum gist_circle_distance(PG_FUNCTION_ARGS)
Datum gist_box_union(PG_FUNCTION_ARGS)
#define RTOverlapStrategyNumber
Datum box_overabove(PG_FUNCTION_ARGS)
#define qsort(a, b, c, d)
Datum gist_poly_distance(PG_FUNCTION_ARGS)
#define DirectFunctionCall2(func, arg1, arg2)
#define PointPGetDatum(X)