1762 GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
1763 GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
1777 POSTGIS_DEBUG(3,
"[GIST] 'picksplit' entered");
1781 maxoff = entryvec->n - 1;
1782 nentries = context.
entriesCount = maxoff - FirstOffsetNumber + 1;
1791 for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
1793 box = (BOX2DF *) DatumGetPointer(entryvec->vector[i].key);
1794 if (i == FirstOffsetNumber)
1806 context.
first =
true;
1807 for (dim = 0; dim < 2; dim++)
1815 for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
1817 box = (BOX2DF *) DatumGetPointer(entryvec->vector[i].key);
1820 intervalsLower[i - FirstOffsetNumber].
lower = box->xmin;
1821 intervalsLower[i - FirstOffsetNumber].
upper = box->xmax;
1825 intervalsLower[i - FirstOffsetNumber].
lower = box->ymin;
1826 intervalsLower[i - FirstOffsetNumber].
upper = box->ymax;
1834 memcpy(intervalsUpper, intervalsLower,
1877 rightLower = intervalsLower[i1].
lower;
1878 leftUpper = intervalsUpper[i2].
lower;
1884 while (i1 < nentries && (rightLower == intervalsLower[i1].lower ||
1885 isnan(intervalsLower[i1].lower)))
1887 leftUpper = Max(leftUpper, intervalsLower[i1].upper);
1892 rightLower = intervalsLower[i1].
lower;
1898 while (i2 < nentries && intervalsUpper[i2].upper <= leftUpper)
1913 rightLower = intervalsLower[i1].
upper;
1914 leftUpper = intervalsUpper[i2].
upper;
1920 while (i2 >= 0 && (leftUpper == intervalsUpper[i2].upper ||
1921 isnan(intervalsUpper[i2].upper)))
1923 rightLower = Min(rightLower, intervalsUpper[i2].lower);
1928 leftUpper = intervalsUpper[i2].
upper;
1934 while (i1 >= 0 && intervalsLower[i1].lower >= rightLower)
1941 rightLower, i1 + 1, leftUpper, i2 + 1);
1950 POSTGIS_DEBUG(4,
"no acceptable splits, trivial split");
1952 PG_RETURN_POINTER(v);
1963 POSTGIS_DEBUGF(4,
"split direction: %d", context.
dim);
1966 v->spl_left = (OffsetNumber *) palloc(nentries *
sizeof(OffsetNumber));
1967 v->spl_right = (OffsetNumber *) palloc(nentries *
sizeof(OffsetNumber));
1972 leftBox = palloc0(
sizeof(BOX2DF));
1973 rightBox = palloc0(
sizeof(BOX2DF));
1979 commonEntriesCount = 0;
1983 #define PLACE_LEFT(box, off) \
1985 if (v->spl_nleft > 0) \
1986 adjustBox(leftBox, box); \
1988 *leftBox = *(box); \
1989 v->spl_left[v->spl_nleft++] = off; \
1992 #define PLACE_RIGHT(box, off) \
1994 if (v->spl_nright > 0) \
1995 adjustBox(rightBox, box); \
1997 *rightBox = *(box); \
1998 v->spl_right[v->spl_nright++] = off; \
2005 for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
2013 box = (BOX2DF *) DatumGetPointer(entryvec->vector[i].key);
2014 if (context.
dim == 0)
2025 if (upper <= context.
leftUpper || isnan(upper))
2028 if (lower >= context.
rightLower || isnan(lower))
2031 commonEntries[commonEntriesCount++].
index = i;
2059 if (commonEntriesCount > 0)
2072 for (i = 0; i < (OffsetNumber)commonEntriesCount; i++)
2074 box = (BOX2DF *) DatumGetPointer(entryvec->vector[
2075 commonEntries[i].index].key);
2089 for (i = 0; i < (OffsetNumber)commonEntriesCount; i++)
2091 float right_penalty, left_penalty;
2092 bool place_right =
true;
2093 box = (BOX2DF *)DatumGetPointer(entryvec->vector[commonEntries[i].index].key);
2100 if (right_penalty > 0 && left_penalty == 0)
2101 place_right =
false;
2102 else if (right_penalty == 0 && left_penalty > 0)
2105 else if (v->spl_nleft + (commonEntriesCount - i) <= m)
2106 place_right =
false;
2107 else if (v->spl_nright + (commonEntriesCount - i) <= m)
2110 else if (left_penalty < right_penalty)
2111 place_right =
false;
2112 else if (right_penalty < left_penalty)
2115 else if (v->spl_nleft < v->spl_nright)
2116 place_right =
false;
2126 v->spl_ldatum = PointerGetDatum(leftBox);
2127 v->spl_rdatum = PointerGetDatum(rightBox);
2129 POSTGIS_DEBUG(4,
"[GIST] 'picksplit' completed");
2131 PG_RETURN_POINTER(v);
static char * box2df_to_string(const BOX2DF *a)
static void fallbackSplit(GistEntryVector *entryvec, GIST_SPLITVEC *v)
#define INDEX_TUPLES_PER_PAGE
static int interval_cmp_upper(const void *i1, const void *i2)
#define PLACE_RIGHT(box, off)
static void g_box_consider_split(ConsiderSplitContext *context, int dimNum, float rightLower, int minLeftCount, float leftUpper, int maxLeftCount)
static int interval_cmp_lower(const void *i1, const void *i2)
static int common_entry_cmp(const void *i1, const void *i2)
#define PLACE_LEFT(box, off)
static float box2df_penalty(const BOX2DF *b1, const BOX2DF *b2)
static void adjustBox(BOX2DF *b, BOX2DF *addon)