1615 GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
1616 GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
1630 POSTGIS_DEBUG(3,
"[GIST] 'picksplit' entered");
1634 maxoff = entryvec->n - 1;
1635 nentries = context.
entriesCount = maxoff - FirstOffsetNumber + 1;
1644 for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
1646 box = (BOX2DF *) DatumGetPointer(entryvec->vector[i].key);
1647 if (i == FirstOffsetNumber)
1659 context.
first =
true;
1660 for (dim = 0; dim < 2; dim++)
1668 for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
1670 box = (BOX2DF *) DatumGetPointer(entryvec->vector[i].key);
1673 intervalsLower[i - FirstOffsetNumber].
lower = box->xmin;
1674 intervalsLower[i - FirstOffsetNumber].
upper = box->xmax;
1678 intervalsLower[i - FirstOffsetNumber].
lower = box->ymin;
1679 intervalsLower[i - FirstOffsetNumber].
upper = box->ymax;
1687 memcpy(intervalsUpper, intervalsLower,
1730 rightLower = intervalsLower[i1].
lower;
1731 leftUpper = intervalsUpper[i2].
lower;
1737 while (i1 < nentries && (rightLower == intervalsLower[i1].lower ||
1738 isnan(intervalsLower[i1].lower)))
1740 leftUpper = Max(leftUpper, intervalsLower[i1].upper);
1745 rightLower = intervalsLower[i1].
lower;
1751 while (i2 < nentries && intervalsUpper[i2].upper <= leftUpper)
1766 rightLower = intervalsLower[i1].
upper;
1767 leftUpper = intervalsUpper[i2].
upper;
1773 while (i2 >= 0 && (leftUpper == intervalsUpper[i2].upper ||
1774 isnan(intervalsUpper[i2].upper)))
1776 rightLower = Min(rightLower, intervalsUpper[i2].lower);
1781 leftUpper = intervalsUpper[i2].
upper;
1787 while (i1 >= 0 && intervalsLower[i1].lower >= rightLower)
1794 rightLower, i1 + 1, leftUpper, i2 + 1);
1803 POSTGIS_DEBUG(4,
"no acceptable splits, trivial split");
1805 PG_RETURN_POINTER(v);
1816 POSTGIS_DEBUGF(4,
"split direction: %d", context.
dim);
1819 v->spl_left = (OffsetNumber *) palloc(nentries *
sizeof(OffsetNumber));
1820 v->spl_right = (OffsetNumber *) palloc(nentries *
sizeof(OffsetNumber));
1825 leftBox = palloc0(
sizeof(BOX2DF));
1826 rightBox = palloc0(
sizeof(BOX2DF));
1832 commonEntriesCount = 0;
1836 #define PLACE_LEFT(box, off) \
1838 if (v->spl_nleft > 0) \
1839 adjustBox(leftBox, box); \
1841 *leftBox = *(box); \
1842 v->spl_left[v->spl_nleft++] = off; \
1845 #define PLACE_RIGHT(box, off) \
1847 if (v->spl_nright > 0) \
1848 adjustBox(rightBox, box); \
1850 *rightBox = *(box); \
1851 v->spl_right[v->spl_nright++] = off; \
1858 for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
1866 box = (BOX2DF *) DatumGetPointer(entryvec->vector[i].key);
1867 if (context.
dim == 0)
1878 if (upper <= context.
leftUpper || isnan(upper))
1881 if (lower >= context.
rightLower || isnan(lower))
1884 commonEntries[commonEntriesCount++].
index = i;
1912 if (commonEntriesCount > 0)
1924 for (i = 0; i < commonEntriesCount; i++)
1926 box = (BOX2DF *) DatumGetPointer(entryvec->vector[
1927 commonEntries[i].index].key);
1940 for (i = 0; i < commonEntriesCount; i++)
1942 box = (BOX2DF *) DatumGetPointer(entryvec->vector[
1943 commonEntries[i].index].key);
1949 if (v->spl_nleft + (commonEntriesCount - i) <= m)
1951 else if (v->spl_nright + (commonEntriesCount - i) <= m)
1963 v->spl_ldatum = PointerGetDatum(leftBox);
1964 v->spl_rdatum = PointerGetDatum(rightBox);
1966 POSTGIS_DEBUG(4,
"[GIST] 'picksplit' completed");
1968 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 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)