PostGIS  2.5.0beta1dev-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 875 of file gserialized_estimate.c.

References STATISTIC_KIND_2D, and STATISTIC_KIND_ND.

Referenced by gserialized_gist_sel(), and pg_get_nd_stats().

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