1864 GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
1865 GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
1879 POSTGIS_DEBUG(3,
"[GIST] 'picksplit' entered");
1883 maxoff = entryvec->n - 1;
1884 nentries = context.
entriesCount = maxoff - FirstOffsetNumber + 1;
1893 for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
1895 box = (BOX2DF *) DatumGetPointer(entryvec->vector[i].key);
1896 if (i == FirstOffsetNumber)
1908 context.
first =
true;
1909 for (dim = 0; dim < 2; dim++)
1917 for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
1919 box = (BOX2DF *) DatumGetPointer(entryvec->vector[i].key);
1922 intervalsLower[i - FirstOffsetNumber].
lower = box->xmin;
1923 intervalsLower[i - FirstOffsetNumber].
upper = box->xmax;
1927 intervalsLower[i - FirstOffsetNumber].
lower = box->ymin;
1928 intervalsLower[i - FirstOffsetNumber].
upper = box->ymax;
1936 memcpy(intervalsUpper, intervalsLower,
1979 rightLower = intervalsLower[i1].
lower;
1980 leftUpper = intervalsUpper[i2].
lower;
1986 while (i1 < nentries && (rightLower == intervalsLower[i1].lower ||
1987 isnan(intervalsLower[i1].lower)))
1989 leftUpper = Max(leftUpper, intervalsLower[i1].upper);
1994 rightLower = intervalsLower[i1].
lower;
2000 while (i2 < nentries && intervalsUpper[i2].upper <= leftUpper)
2015 rightLower = intervalsLower[i1].
upper;
2016 leftUpper = intervalsUpper[i2].
upper;
2022 while (i2 >= 0 && (leftUpper == intervalsUpper[i2].upper ||
2023 isnan(intervalsUpper[i2].upper)))
2025 rightLower = Min(rightLower, intervalsUpper[i2].lower);
2030 leftUpper = intervalsUpper[i2].
upper;
2036 while (i1 >= 0 && intervalsLower[i1].lower >= rightLower)
2043 rightLower, i1 + 1, leftUpper, i2 + 1);
2052 POSTGIS_DEBUG(4,
"no acceptable splits, trivial split");
2054 PG_RETURN_POINTER(v);
2065 POSTGIS_DEBUGF(4,
"split direction: %d", context.
dim);
2068 v->spl_left = (OffsetNumber *) palloc(nentries *
sizeof(OffsetNumber));
2069 v->spl_right = (OffsetNumber *) palloc(nentries *
sizeof(OffsetNumber));
2074 leftBox = palloc0(
sizeof(BOX2DF));
2075 rightBox = palloc0(
sizeof(BOX2DF));
2081 commonEntriesCount = 0;
2085 #define PLACE_LEFT(box, off) \
2087 if (v->spl_nleft > 0) \
2088 adjustBox(leftBox, box); \
2090 *leftBox = *(box); \
2091 v->spl_left[v->spl_nleft++] = off; \
2094 #define PLACE_RIGHT(box, off) \
2096 if (v->spl_nright > 0) \
2097 adjustBox(rightBox, box); \
2099 *rightBox = *(box); \
2100 v->spl_right[v->spl_nright++] = off; \
2107 for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
2115 box = (BOX2DF *) DatumGetPointer(entryvec->vector[i].key);
2116 if (context.
dim == 0)
2127 if (upper <= context.
leftUpper || isnan(upper))
2130 if (lower >= context.
rightLower || isnan(lower))
2133 commonEntries[commonEntriesCount++].
index = i;
2161 if (commonEntriesCount > 0)
2173 for (i = 0; i < commonEntriesCount; i++)
2175 box = (BOX2DF *) DatumGetPointer(entryvec->vector[
2176 commonEntries[i].index].key);
2190 for (i = 0; i < commonEntriesCount; i++)
2192 box = (BOX2DF *) DatumGetPointer(entryvec->vector[
2193 commonEntries[i].index].key);
2199 if (v->spl_nleft + (commonEntriesCount - i) <= m)
2201 else if (v->spl_nright + (commonEntriesCount - i) <= m)
2213 v->spl_ldatum = PointerGetDatum(leftBox);
2214 v->spl_rdatum = PointerGetDatum(rightBox);
2216 POSTGIS_DEBUG(4,
"[GIST] 'picksplit' completed");
2218 PG_RETURN_POINTER(v);
static char * box2df_to_string(const BOX2DF *a)
static void fallbackSplit(GistEntryVector *entryvec, GIST_SPLITVEC *v)
static int interval_cmp_upper(const void *i1, const void *i2)
#define PLACE_RIGHT(box, off)
static float box_penalty(BOX2DF *original, BOX2DF *new)
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 void adjustBox(BOX2DF *b, BOX2DF *addon)