1743 GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
1744 GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
1758 POSTGIS_DEBUG(3,
"[GIST] 'picksplit' entered");
1762 maxoff = entryvec->n - 1;
1763 nentries = context.
entriesCount = maxoff - FirstOffsetNumber + 1;
1772 for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
1774 box = (BOX2DF *) DatumGetPointer(entryvec->vector[i].key);
1775 if (i == FirstOffsetNumber)
1787 context.
first =
true;
1788 for (dim = 0; dim < 2; dim++)
1796 for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
1798 box = (BOX2DF *) DatumGetPointer(entryvec->vector[i].key);
1801 intervalsLower[i - FirstOffsetNumber].
lower = box->xmin;
1802 intervalsLower[i - FirstOffsetNumber].
upper = box->xmax;
1806 intervalsLower[i - FirstOffsetNumber].
lower = box->ymin;
1807 intervalsLower[i - FirstOffsetNumber].
upper = box->ymax;
1815 memcpy(intervalsUpper, intervalsLower,
1858 rightLower = intervalsLower[i1].
lower;
1859 leftUpper = intervalsUpper[i2].
lower;
1865 while (i1 < nentries && (rightLower == intervalsLower[i1].lower ||
1866 isnan(intervalsLower[i1].lower)))
1868 leftUpper = Max(leftUpper, intervalsLower[i1].upper);
1873 rightLower = intervalsLower[i1].
lower;
1879 while (i2 < nentries && intervalsUpper[i2].upper <= leftUpper)
1894 rightLower = intervalsLower[i1].
upper;
1895 leftUpper = intervalsUpper[i2].
upper;
1901 while (i2 >= 0 && (leftUpper == intervalsUpper[i2].upper ||
1902 isnan(intervalsUpper[i2].upper)))
1904 rightLower = Min(rightLower, intervalsUpper[i2].lower);
1909 leftUpper = intervalsUpper[i2].
upper;
1915 while (i1 >= 0 && intervalsLower[i1].lower >= rightLower)
1922 rightLower, i1 + 1, leftUpper, i2 + 1);
1931 POSTGIS_DEBUG(4,
"no acceptable splits, trivial split");
1933 PG_RETURN_POINTER(v);
1944 POSTGIS_DEBUGF(4,
"split direction: %d", context.
dim);
1947 v->spl_left = (OffsetNumber *) palloc(nentries *
sizeof(OffsetNumber));
1948 v->spl_right = (OffsetNumber *) palloc(nentries *
sizeof(OffsetNumber));
1953 leftBox = palloc0(
sizeof(BOX2DF));
1954 rightBox = palloc0(
sizeof(BOX2DF));
1960 commonEntriesCount = 0;
1964 #define PLACE_LEFT(box, off) \
1966 if (v->spl_nleft > 0) \
1967 adjustBox(leftBox, box); \
1969 *leftBox = *(box); \
1970 v->spl_left[v->spl_nleft++] = off; \
1973 #define PLACE_RIGHT(box, off) \
1975 if (v->spl_nright > 0) \
1976 adjustBox(rightBox, box); \
1978 *rightBox = *(box); \
1979 v->spl_right[v->spl_nright++] = off; \
1986 for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
1994 box = (BOX2DF *) DatumGetPointer(entryvec->vector[i].key);
1995 if (context.
dim == 0)
2006 if (upper <= context.
leftUpper || isnan(upper))
2009 if (lower >= context.
rightLower || isnan(lower))
2012 commonEntries[commonEntriesCount++].
index = i;
2040 if (commonEntriesCount > 0)
2053 for (i = 0; i < commonEntriesCount; i++)
2055 box = (BOX2DF *) DatumGetPointer(entryvec->vector[
2056 commonEntries[i].index].key);
2070 for (i = 0; i < commonEntriesCount; i++)
2072 float right_penalty, left_penalty;
2073 bool place_right =
true;
2074 box = (BOX2DF *)DatumGetPointer(entryvec->vector[commonEntries[i].index].key);
2081 if (right_penalty > 0 && left_penalty == 0)
2082 place_right =
false;
2083 else if (right_penalty == 0 && left_penalty > 0)
2086 else if (v->spl_nleft + (commonEntriesCount - i) <= m)
2087 place_right =
false;
2088 else if (v->spl_nright + (commonEntriesCount - i) <= m)
2091 else if (left_penalty < right_penalty)
2092 place_right =
false;
2093 else if (right_penalty < left_penalty)
2096 else if (v->spl_nleft < v->spl_nright)
2097 place_right =
false;
2107 v->spl_ldatum = PointerGetDatum(leftBox);
2108 v->spl_rdatum = PointerGetDatum(rightBox);
2110 POSTGIS_DEBUG(4,
"[GIST] 'picksplit' completed");
2112 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)