PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ pg_nd_stats_from_tuple()

static ND_STATS* pg_nd_stats_from_tuple ( HeapTuple  stats_tuple,
int  mode 
)
static

Definition at line 828 of file gserialized_estimate.c.

References STATISTIC_KIND_2D, and STATISTIC_KIND_ND.

Referenced by gserialized_gist_sel(), and pg_get_nd_stats().

829 {
830  int stats_kind = STATISTIC_KIND_ND;
831  int rv;
832  ND_STATS *nd_stats;
833 
834  /* If we're in 2D mode, set the kind appropriately */
835  if ( mode == 2 ) stats_kind = STATISTIC_KIND_2D;
836 
837  /* Then read the geom status histogram from that */
838 
839 #if POSTGIS_PGSQL_VERSION < 100
840  float4 *floatptr;
841  int nvalues;
842 
843  rv = get_attstatsslot(stats_tuple, 0, 0, stats_kind, InvalidOid,
844  NULL, NULL, NULL, &floatptr, &nvalues);
845 
846  if ( ! rv ) {
847  POSTGIS_DEBUGF(2,
848  "no slot of kind %d in stats tuple", stats_kind);
849  return NULL;
850  }
851 
852  /* Clone the stats here so we can release the attstatsslot immediately */
853  nd_stats = palloc(sizeof(float) * nvalues);
854  memcpy(nd_stats, floatptr, sizeof(float) * nvalues);
855 
856  /* Clean up */
857  free_attstatsslot(0, NULL, 0, floatptr, nvalues);
858 #else /* PostgreSQL 10 or higher */
859  AttStatsSlot sslot;
860  rv = get_attstatsslot(&sslot, stats_tuple, stats_kind, InvalidOid,
861  ATTSTATSSLOT_NUMBERS);
862  if ( ! rv ) {
863  POSTGIS_DEBUGF(2,
864  "no slot of kind %d in stats tuple", stats_kind);
865  return NULL;
866  }
867 
868  /* Clone the stats here so we can release the attstatsslot immediately */
869  nd_stats = palloc(sizeof(float4) * sslot.nnumbers);
870  memcpy(nd_stats, sslot.numbers, sizeof(float4) * sslot.nnumbers);
871 
872  free_attstatsslot(&sslot);
873 #endif
874 
875  return nd_stats;
876 }
#define STATISTIC_KIND_2D
N-dimensional statistics structure.
#define STATISTIC_KIND_ND
Assign a number to the n-dimensional statistics kind.
Here is the caller graph for this function: