PostGIS  2.5.2dev-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 898 of file gserialized_estimate.c.

References STATISTIC_KIND_2D, and STATISTIC_KIND_ND.

Referenced by gserialized_gist_sel(), and pg_get_nd_stats().

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