1800 GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
1801 GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
1815 POSTGIS_DEBUG(3,
"[GIST] 'picksplit' entered");
1819 maxoff = entryvec->n - 1;
1820 nentries = context.
entriesCount = maxoff - FirstOffsetNumber + 1;
1829 for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
1831 box = (BOX2DF *) DatumGetPointer(entryvec->vector[i].key);
1832 if (i == FirstOffsetNumber)
1844 context.
first =
true;
1845 for (dim = 0; dim < 2; dim++)
1853 for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
1855 box = (BOX2DF *) DatumGetPointer(entryvec->vector[i].key);
1858 intervalsLower[i - FirstOffsetNumber].
lower = box->xmin;
1859 intervalsLower[i - FirstOffsetNumber].
upper = box->xmax;
1863 intervalsLower[i - FirstOffsetNumber].
lower = box->ymin;
1864 intervalsLower[i - FirstOffsetNumber].
upper = box->ymax;
1872 memcpy(intervalsUpper, intervalsLower,
1915 rightLower = intervalsLower[i1].
lower;
1916 leftUpper = intervalsUpper[i2].
lower;
1922 while (i1 < nentries && (rightLower == intervalsLower[i1].lower ||
1923 isnan(intervalsLower[i1].lower)))
1925 leftUpper = Max(leftUpper, intervalsLower[i1].upper);
1930 rightLower = intervalsLower[i1].
lower;
1936 while (i2 < nentries && intervalsUpper[i2].upper <= leftUpper)
1951 rightLower = intervalsLower[i1].
upper;
1952 leftUpper = intervalsUpper[i2].
upper;
1958 while (i2 >= 0 && (leftUpper == intervalsUpper[i2].upper ||
1959 isnan(intervalsUpper[i2].upper)))
1961 rightLower = Min(rightLower, intervalsUpper[i2].lower);
1966 leftUpper = intervalsUpper[i2].
upper;
1972 while (i1 >= 0 && intervalsLower[i1].lower >= rightLower)
1979 rightLower, i1 + 1, leftUpper, i2 + 1);
1988 POSTGIS_DEBUG(4,
"no acceptable splits, trivial split");
1990 PG_RETURN_POINTER(v);
2001 POSTGIS_DEBUGF(4,
"split direction: %d", context.
dim);
2004 v->spl_left = (OffsetNumber *) palloc(nentries *
sizeof(OffsetNumber));
2005 v->spl_right = (OffsetNumber *) palloc(nentries *
sizeof(OffsetNumber));
2010 leftBox = palloc0(
sizeof(BOX2DF));
2011 rightBox = palloc0(
sizeof(BOX2DF));
2017 commonEntriesCount = 0;
2021 #define PLACE_LEFT(box, off) \ 2023 if (v->spl_nleft > 0) \ 2024 adjustBox(leftBox, box); \ 2026 *leftBox = *(box); \ 2027 v->spl_left[v->spl_nleft++] = off; \ 2030 #define PLACE_RIGHT(box, off) \ 2032 if (v->spl_nright > 0) \ 2033 adjustBox(rightBox, box); \ 2035 *rightBox = *(box); \ 2036 v->spl_right[v->spl_nright++] = off; \ 2043 for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
2051 box = (BOX2DF *) DatumGetPointer(entryvec->vector[i].key);
2052 if (context.
dim == 0)
2063 if (upper <= context.
leftUpper || isnan(upper))
2066 if (lower >= context.
rightLower || isnan(lower))
2069 commonEntries[commonEntriesCount++].
index = i;
2097 if (commonEntriesCount > 0)
2109 for (i = 0; i < commonEntriesCount; i++)
2111 box = (BOX2DF *) DatumGetPointer(entryvec->vector[
2112 commonEntries[i].
index].key);
2126 for (i = 0; i < commonEntriesCount; i++)
2128 box = (BOX2DF *) DatumGetPointer(entryvec->vector[
2129 commonEntries[i].
index].key);
2135 if (v->spl_nleft + (commonEntriesCount - i) <= m)
2137 else if (v->spl_nright + (commonEntriesCount - i) <= m)
2149 v->spl_ldatum = PointerGetDatum(leftBox);
2150 v->spl_rdatum = PointerGetDatum(rightBox);
2152 POSTGIS_DEBUG(4,
"[GIST] 'picksplit' completed");
2154 PG_RETURN_POINTER(v);
static void fallbackSplit(GistEntryVector *entryvec, GIST_SPLITVEC *v)
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 void adjustBox(BOX2DF *b, BOX2DF *addon)
static char * box2df_to_string(const BOX2DF *a)
static int interval_cmp_upper(const void *i1, const void *i2)
static int common_entry_cmp(const void *i1, const void *i2)
#define PLACE_RIGHT(box, off)
#define PLACE_LEFT(box, off)
static float box_penalty(BOX2DF *original, BOX2DF *new)