PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ nd_box_overlap()

static int nd_box_overlap ( const ND_STATS nd_stats,
const ND_BOX nd_box,
ND_IBOX nd_ibox 
)
inlinestatic

What stats cells overlap with this ND_BOX? Put the lowest cell addresses in ND_IBOX->min and the highest in ND_IBOX->max.

Definition at line 662 of file gserialized_estimate.c.

663{
664 int d;
665
666 POSTGIS_DEBUGF(4, " nd_box: %s", nd_box_to_json(nd_box, nd_stats->ndims));
667
668 /* Initialize ibox */
669 memset(nd_ibox, 0, sizeof(ND_IBOX));
670
671 /* In each dimension... */
672 for ( d = 0; d < nd_stats->ndims; d++ )
673 {
674 double smin = nd_stats->extent.min[d];
675 double smax = nd_stats->extent.max[d];
676 double width = smax - smin;
677
678 if (width < MIN_DIMENSION_WIDTH)
679 {
680 nd_ibox->min[d] = nd_ibox->max[d] = nd_stats->extent.min[d];
681 }
682 else
683 {
684 int size = (int)roundf(nd_stats->size[d]);
685
686 /* ... find cells the box overlaps with in this dimension */
687 nd_ibox->min[d] = floor(size * (nd_box->min[d] - smin) / width);
688 nd_ibox->max[d] = floor(size * (nd_box->max[d] - smin) / width);
689
690 POSTGIS_DEBUGF(5, " stats: dim %d: min %g: max %g: width %g", d, smin, smax, width);
691 POSTGIS_DEBUGF(5, " overlap: dim %d: (%d, %d)", d, nd_ibox->min[d], nd_ibox->max[d]);
692
693 /* Push any out-of range values into range */
694 nd_ibox->min[d] = Max(nd_ibox->min[d], 0);
695 nd_ibox->max[d] = Min(nd_ibox->max[d], size - 1);
696 }
697 }
698 return true;
699}
static char * nd_box_to_json(const ND_BOX *nd_box, int ndims)
Convert an ND_BOX to a JSON string for printing.
#define MIN_DIMENSION_WIDTH
Minimum width of a dimension that we'll bother trying to compute statistics on.
float4 max[ND_DIMS]
float4 min[ND_DIMS]
int max[ND_DIMS]
int min[ND_DIMS]
N-dimensional box index type.
float4 size[ND_DIMS]

References ND_STATS_T::extent, ND_BOX_T::max, ND_IBOX_T::max, ND_BOX_T::min, ND_IBOX_T::min, MIN_DIMENSION_WIDTH, nd_box_to_json(), ND_STATS_T::ndims, and ND_STATS_T::size.

Referenced by compute_gserialized_stats_mode(), estimate_join_selectivity(), and estimate_selectivity().

Here is the call graph for this function:
Here is the caller graph for this function: