PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ g_box_consider_split()

static void g_box_consider_split ( ConsiderSplitContext context,
int  dimNum,
float  rightLower,
int  minLeftCount,
float  leftUpper,
int  maxLeftCount 
)
inlinestatic

Definition at line 1628 of file gserialized_gist_2d.c.

References ConsiderSplitContext::boundingBox, ConsiderSplitContext::dim, ConsiderSplitContext::entriesCount, ConsiderSplitContext::first, ConsiderSplitContext::leftUpper, LIMIT_RATIO, non_negative(), ConsiderSplitContext::overlap, ConsiderSplitContext::range, ConsiderSplitContext::ratio, and ConsiderSplitContext::rightLower.

Referenced by gserialized_gist_picksplit_2d().

1631 {
1632  int leftCount,
1633  rightCount;
1634  float4 ratio,
1635  overlap;
1636  float range;
1637 
1638  POSTGIS_DEBUGF(5, "consider split: dimNum = %d, rightLower = %f, "
1639  "minLeftCount = %d, leftUpper = %f, maxLeftCount = %d ",
1640  dimNum, rightLower, minLeftCount, leftUpper, maxLeftCount);
1641 
1642  /*
1643  * Calculate entries distribution ratio assuming most uniform distribution
1644  * of common entries.
1645  */
1646  if (minLeftCount >= (context->entriesCount + 1) / 2)
1647  {
1648  leftCount = minLeftCount;
1649  }
1650  else
1651  {
1652  if (maxLeftCount <= context->entriesCount / 2)
1653  leftCount = maxLeftCount;
1654  else
1655  leftCount = context->entriesCount / 2;
1656  }
1657  rightCount = context->entriesCount - leftCount;
1658 
1659  /*
1660  * Ratio of split - quotient between size of lesser group and total
1661  * entries count.
1662  */
1663  ratio = ((float4) Min(leftCount, rightCount)) /
1664  ((float4) context->entriesCount);
1665 
1666  if (ratio > LIMIT_RATIO)
1667  {
1668  bool selectthis = false;
1669 
1670  /*
1671  * The ratio is acceptable, so compare current split with previously
1672  * selected one. Between splits of one dimension we search for minimal
1673  * overlap (allowing negative values) and minimal ration (between same
1674  * overlaps. We switch dimension if find less overlap (non-negative)
1675  * or less range with same overlap.
1676  */
1677  if (dimNum == 0)
1678  range = context->boundingBox.xmax - context->boundingBox.xmin;
1679  else
1680  range = context->boundingBox.ymax - context->boundingBox.ymin;
1681 
1682  overlap = (leftUpper - rightLower) / range;
1683 
1684  /* If there is no previous selection, select this */
1685  if (context->first)
1686  selectthis = true;
1687  else if (context->dim == dimNum)
1688  {
1689  /*
1690  * Within the same dimension, choose the new split if it has a
1691  * smaller overlap, or same overlap but better ratio.
1692  */
1693  if (overlap < context->overlap ||
1694  (overlap == context->overlap && ratio > context->ratio))
1695  selectthis = true;
1696  }
1697  else
1698  {
1699  /*
1700  * Across dimensions, choose the new split if it has a smaller
1701  * *non-negative* overlap, or same *non-negative* overlap but
1702  * bigger range. This condition differs from the one described in
1703  * the article. On the datasets where leaf MBRs don't overlap
1704  * themselves, non-overlapping splits (i.e. splits which have zero
1705  * *non-negative* overlap) are frequently possible. In this case
1706  * splits tends to be along one dimension, because most distant
1707  * non-overlapping splits (i.e. having lowest negative overlap)
1708  * appears to be in the same dimension as in the previous split.
1709  * Therefore MBRs appear to be very prolonged along another
1710  * dimension, which leads to bad search performance. Using range
1711  * as the second split criteria makes MBRs more quadratic. Using
1712  * *non-negative* overlap instead of overlap as the first split
1713  * criteria gives to range criteria a chance to matter, because
1714  * non-overlapping splits are equivalent in this criteria.
1715  */
1716  if (non_negative(overlap) < non_negative(context->overlap) ||
1717  (range > context->range &&
1718  non_negative(overlap) <= non_negative(context->overlap)))
1719  selectthis = true;
1720  }
1721 
1722  if (selectthis)
1723  {
1724  /* save information about selected split */
1725  context->first = false;
1726  context->ratio = ratio;
1727  context->range = range;
1728  context->overlap = overlap;
1729  context->rightLower = rightLower;
1730  context->leftUpper = leftUpper;
1731  context->dim = dimNum;
1732  POSTGIS_DEBUG(5, "split selected");
1733  }
1734  }
1735 }
static float non_negative(float val)
#define LIMIT_RATIO
Here is the call graph for this function:
Here is the caller graph for this function: