PostGIS  3.0.0dev-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 888 of file gserialized_estimate.c.

References STATISTIC_KIND_2D, and STATISTIC_KIND_ND.

Referenced by gserialized_gist_sel(), and pg_get_nd_stats().

889 {
890  int stats_kind = STATISTIC_KIND_ND;
891  int rv;
892  ND_STATS *nd_stats;
893 
894  /* If we're in 2D mode, set the kind appropriately */
895  if ( mode == 2 ) stats_kind = STATISTIC_KIND_2D;
896 
897  /* Then read the geom status histogram from that */
898 
899 #if POSTGIS_PGSQL_VERSION < 100
900  {
901  float4 *floatptr;
902  int nvalues;
903 
904  rv = get_attstatsslot(stats_tuple, 0, 0, stats_kind, InvalidOid,
905  NULL, NULL, NULL, &floatptr, &nvalues);
906 
907  if ( ! rv ) {
908  POSTGIS_DEBUGF(2, "no slot of kind %d in stats tuple", stats_kind);
909  return NULL;
910  }
911 
912  /* Clone the stats here so we can release the attstatsslot immediately */
913  nd_stats = palloc(sizeof(float) * nvalues);
914  memcpy(nd_stats, floatptr, sizeof(float) * nvalues);
915 
916  /* Clean up */
917  free_attstatsslot(0, NULL, 0, floatptr, nvalues);
918  }
919 #else /* PostgreSQL 10 or higher */
920  {
921  AttStatsSlot sslot;
922  rv = get_attstatsslot(&sslot, stats_tuple, stats_kind, InvalidOid,
923  ATTSTATSSLOT_NUMBERS);
924  if ( ! rv ) {
925  POSTGIS_DEBUGF(2, "no slot of kind %d in stats tuple", stats_kind);
926  return NULL;
927  }
928 
929  /* Clone the stats here so we can release the attstatsslot immediately */
930  nd_stats = palloc(sizeof(float4) * sslot.nnumbers);
931  memcpy(nd_stats, sslot.numbers, sizeof(float4) * sslot.nnumbers);
932 
933  free_attstatsslot(&sslot);
934  }
935 #endif
936 
937  return nd_stats;
938 }
#define STATISTIC_KIND_2D
N-dimensional statistics structure.
#define STATISTIC_KIND_ND
Here is the caller graph for this function: