25 #include "utils/fmgrprotos.h"
44 #define LIMIT_RATIO 0.3
149 b->high.x = addon->
high.
x;
151 b->low.x = addon->
low.
x;
153 b->high.y = addon->
high.
y;
155 b->low.y = addon->
low.
y;
173 numranges = entryvec->
n;
176 memcpy(pageunion,
cur,
sizeof(
BOX));
178 for (
i = 1;
i < numranges;
i++)
183 *sizep =
sizeof(
BOX);
224 maxoff = entryvec->
n - 1;
352 float8 rightLower,
int minLeftCount,
353 float8 leftUpper,
int maxLeftCount)
365 if (minLeftCount >= (
context->entriesCount + 1) / 2)
367 leftCount = minLeftCount;
371 if (maxLeftCount <= context->entriesCount / 2)
372 leftCount = maxLeftCount;
374 leftCount =
context->entriesCount / 2;
376 rightCount =
context->entriesCount - leftCount;
386 bool selectthis =
false;
407 else if (
context->dim == dimNum)
413 if (overlap < context->overlap ||
449 context->rightLower = rightLower;
450 context->leftUpper = leftUpper;
514 maxoff = entryvec->
n - 1;
537 for (dim = 0; dim < 2; dim++)
564 memcpy(intervalsUpper, intervalsLower,
607 rightLower = intervalsLower[i1].
lower;
608 leftUpper = intervalsUpper[i2].
lower;
614 while (i1 < nentries &&
618 leftUpper = intervalsLower[i1].
upper;
623 rightLower = intervalsLower[i1].
lower;
629 while (i2 < nentries &&
645 rightLower = intervalsLower[i1].
upper;
646 leftUpper = intervalsUpper[i2].
upper;
655 rightLower = intervalsUpper[i2].
lower;
660 leftUpper = intervalsUpper[i2].
upper;
666 while (i1 >= 0 &&
float8_ge(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; \
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)
864 *result = (b1 == NULL && b2 == NULL);
939 elog(
ERROR,
"unrecognized strategy number: %d", strategy);
1020 elog(
ERROR,
"unrecognized strategy number: %d", strategy);
1178 box->
high = box->
low = *point;
1216 #define point_point_distance(p1,p2) \
1217 DatumGetFloat8(DirectFunctionCall2(point_distance, \
1218 PointPGetDatum(p1), PointPGetDatum(p2)))
1230 else if (point->
x <= box->
high.
x && point->
x >= box->
low.
x &&
1231 point->
y <= box->
high.
y && point->
y >= box->
low.
y)
1236 else if (point->
x <= box->
high.
x && point->
x >= box->
low.
x)
1240 if (point->
y > box->
high.
y)
1242 else if (point->
y < box->
low.
y)
1245 elog(
ERROR,
"inconsistent point values");
1247 else if (point->
y <= box->
high.
y && point->
y >= box->
low.
y)
1251 if (point->
x > box->
high.
x)
1253 else if (point->
x < box->
low.
x)
1256 elog(
ERROR,
"inconsistent point values");
1267 if (result > subresult)
1273 if (result > subresult)
1279 if (result > subresult)
1290 bool result =
false;
1295 result =
FPlt(
key->low.x, query->
x);
1298 result =
FPgt(
key->high.x, query->
x);
1301 result =
FPgt(
key->high.y, query->
y);
1304 result =
FPlt(
key->low.y, query->
y);
1310 result = (
FPeq(
key->low.x, query->
x) &&
1315 result = (
FPle(query->
x,
key->high.x) &&
1322 elog(
ERROR,
"unrecognized strategy number: %d", strategy);
1330 #define GeoStrategyNumberOffset 20
1331 #define PointStrategyNumberGroup 0
1332 #define BoxStrategyNumberGroup 1
1333 #define PolygonStrategyNumberGroup 2
1334 #define CircleStrategyNumberGroup 3
1355 switch (strategyGroup)
1384 result = (
key->high.x >= query->
low.
x &&
1386 key->high.y >= query->
low.
y &&
1446 elog(
ERROR,
"unrecognized strategy number: %d", strategy);
1462 switch (strategyGroup)
1470 elog(
ERROR,
"unrecognized strategy number: %d", strategy);
1484 switch (strategyGroup)
1492 elog(
ERROR,
"unrecognized strategy number: %d", strategy);
1590 n = (n | (n << 16)) & UINT64CONST(0x0000FFFF0000FFFF);
1591 n = (n | (n << 8)) & UINT64CONST(0x00FF00FF00FF00FF);
1592 n = (n | (n << 4)) & UINT64CONST(0x0F0F0F0F0F0F0F0F);
1593 n = (n | (n << 2)) & UINT64CONST(0x3333333333333333);
1594 n = (n | (n << 1)) & UINT64CONST(0x5555555555555555);
1658 if ((u.i & 0x80000000) != 0)
1693 if (p1->
x ==
p2->x && p1->
y ==
p2->y)
1721 #if SIZEOF_DATUM == 8
1724 return (
Datum) (z >> 32);
#define Assert(condition)
static void PGresult const char * p2
int float8_cmp_internal(float8 a, float8 b)
static float8 float8_min(const float8 val1, const float8 val2)
static float8 float8_mul(const float8 val1, const float8 val2)
static float4 float4_div(const float4 val1, const float4 val2)
static float8 float8_pl(const float8 val1, const float8 val2)
static float8 float8_mi(const float8 val1, const float8 val2)
static float8 get_float8_infinity(void)
static bool float8_ge(const float8 val1, const float8 val2)
static float8 float8_max(const float8 val1, const float8 val2)
static bool float8_le(const float8 val1, const float8 val2)
static bool float8_eq(const float8 val1, const float8 val2)
static float8 float8_div(const float8 val1, const float8 val2)
static bool float8_lt(const float8 val1, const float8 val2)
static bool float8_gt(const float8 val1, const float8 val2)
#define PG_FREE_IF_COPY(ptr, n)
#define DirectFunctionCall2(func, arg1, arg2)
#define PG_RETURN_FLOAT8(x)
#define PG_GETARG_POINTER(n)
#define PG_GETARG_DATUM(n)
#define PG_GETARG_UINT16(n)
#define DirectFunctionCall5(func, arg1, arg2, arg3, arg4, arg5)
#define PG_RETURN_POINTER(x)
#define PG_RETURN_BOOL(x)
static bool FPlt(double A, double B)
static Point * DatumGetPointP(Datum X)
static CIRCLE * DatumGetCircleP(Datum X)
#define PG_GETARG_POINT_P(n)
static bool FPge(double A, double B)
static Datum PolygonPGetDatum(const POLYGON *X)
static POLYGON * DatumGetPolygonP(Datum X)
static BOX * DatumGetBoxP(Datum X)
static Datum PointPGetDatum(const Point *X)
#define PG_GETARG_BOX_P(n)
#define PG_GETARG_POLYGON_P(n)
static Datum CirclePGetDatum(const CIRCLE *X)
#define PG_GETARG_CIRCLE_P(n)
static bool FPgt(double A, double B)
static bool FPle(double A, double B)
static Datum BoxPGetDatum(const BOX *X)
static bool FPeq(double A, double B)
Datum box_left(PG_FUNCTION_ARGS)
Datum box_right(PG_FUNCTION_ARGS)
Datum box_same(PG_FUNCTION_ARGS)
Datum poly_contain_pt(PG_FUNCTION_ARGS)
Datum box_below(PG_FUNCTION_ARGS)
Datum box_overright(PG_FUNCTION_ARGS)
Datum box_overabove(PG_FUNCTION_ARGS)
Datum box_overlap(PG_FUNCTION_ARGS)
Datum box_contain(PG_FUNCTION_ARGS)
Datum circle_contain_pt(PG_FUNCTION_ARGS)
Datum box_overbelow(PG_FUNCTION_ARGS)
Datum box_contained(PG_FUNCTION_ARGS)
Datum box_overleft(PG_FUNCTION_ARGS)
Datum box_above(PG_FUNCTION_ARGS)
#define gistentryinit(e, k, r, pg, o, l)
static void adjustBox(BOX *b, const BOX *addon)
static void fallbackSplit(GistEntryVector *entryvec, GIST_SPLITVEC *v)
Datum gist_box_penalty(PG_FUNCTION_ARGS)
#define BoxStrategyNumberGroup
Datum gist_box_picksplit(PG_FUNCTION_ARGS)
Datum gist_circle_compress(PG_FUNCTION_ARGS)
static bool rtree_internal_consistent(BOX *key, BOX *query, StrategyNumber strategy)
Datum gist_box_consistent(PG_FUNCTION_ARGS)
static int interval_cmp_upper(const void *i1, const void *i2)
static int gist_bbox_zorder_cmp(Datum a, Datum b, SortSupport ssup)
Datum gist_box_distance(PG_FUNCTION_ARGS)
#define point_point_distance(p1, p2)
static float8 gist_bbox_distance(GISTENTRY *entry, Datum query, StrategyNumber strategy)
Datum gist_poly_compress(PG_FUNCTION_ARGS)
static void rt_box_union(BOX *n, const BOX *a, const BOX *b)
#define GeoStrategyNumberOffset
#define PLACE_RIGHT(box, off)
Datum gist_poly_distance(PG_FUNCTION_ARGS)
static void g_box_consider_split(ConsiderSplitContext *context, int dimNum, float8 rightLower, int minLeftCount, float8 leftUpper, int maxLeftCount)
Datum gist_point_distance(PG_FUNCTION_ARGS)
static float8 box_penalty(const BOX *original, const BOX *new)
Datum gist_circle_distance(PG_FUNCTION_ARGS)
static Datum gist_bbox_zorder_abbrev_convert(Datum original, SortSupport ssup)
#define CircleStrategyNumberGroup
static uint64 part_bits32_by2(uint32 x)
Datum gist_point_sortsupport(PG_FUNCTION_ARGS)
#define PointStrategyNumberGroup
Datum gist_box_union(PG_FUNCTION_ARGS)
static int interval_cmp_lower(const void *i1, const void *i2)
static float8 size_box(const BOX *box)
static uint32 ieee_float32_to_uint32(float f)
Datum gist_circle_consistent(PG_FUNCTION_ARGS)
static bool gist_box_leaf_consistent(BOX *key, BOX *query, StrategyNumber strategy)
static int common_entry_cmp(const void *i1, const void *i2)
#define PolygonStrategyNumberGroup
Datum gist_poly_consistent(PG_FUNCTION_ARGS)
Datum gist_point_compress(PG_FUNCTION_ARGS)
static uint64 point_zorder_internal(float4 x, float4 y)
Datum gist_point_consistent(PG_FUNCTION_ARGS)
static bool gist_point_consistent_internal(StrategyNumber strategy, bool isLeaf, BOX *key, Point *query)
Datum gist_box_same(PG_FUNCTION_ARGS)
#define PLACE_LEFT(box, off)
static bool gist_bbox_zorder_abbrev_abort(int memtupcount, SortSupport ssup)
static float8 computeDistance(bool isLeaf, BOX *box, Point *point)
Datum gist_point_fetch(PG_FUNCTION_ARGS)
static float non_negative(float val)
void * palloc0(Size size)
#define OffsetNumberNext(offsetNumber)
#define FirstOffsetNumber
Datum lower(PG_FUNCTION_ARGS)
Datum upper(PG_FUNCTION_ARGS)
#define qsort(a, b, c, d)
static bool DatumGetBool(Datum X)
static Datum PointerGetDatum(const void *X)
static Datum Int16GetDatum(int16 X)
static struct cvec * range(struct vars *v, chr a, chr b, int cases)
struct SortSupportData * SortSupport
#define RTOverlapStrategyNumber
#define RTLeftStrategyNumber
#define RTOverRightStrategyNumber
#define RTRightStrategyNumber
#define RTSameStrategyNumber
#define RTOverAboveStrategyNumber
#define RTOldBelowStrategyNumber
#define RTContainsStrategyNumber
#define RTOverBelowStrategyNumber
#define RTBelowStrategyNumber
#define RTOldAboveStrategyNumber
#define RTAboveStrategyNumber
#define RTOverLeftStrategyNumber
#define RTContainedByStrategyNumber
GISTENTRY vector[FLEXIBLE_ARRAY_MEMBER]
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Datum(* abbrev_converter)(Datum original, SortSupport ssup)
int(* abbrev_full_comparator)(Datum x, Datum y, SortSupport ssup)
bool(* abbrev_abort)(int memtupcount, SortSupport ssup)
int ssup_datum_unsigned_cmp(Datum x, Datum y, SortSupport ssup)