PostGIS  2.4.9dev-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 856 of file gserialized_estimate.c.

References STATISTIC_KIND_2D, and STATISTIC_KIND_ND.

Referenced by gserialized_gist_sel(), and pg_get_nd_stats().

857 {
858  int stats_kind = STATISTIC_KIND_ND;
859  int rv;
860  ND_STATS *nd_stats;
861 
862  /* If we're in 2D mode, set the kind appropriately */
863  if ( mode == 2 ) stats_kind = STATISTIC_KIND_2D;
864 
865  /* Then read the geom status histogram from that */
866 
867 #if POSTGIS_PGSQL_VERSION < 100
868  float4 *floatptr;
869  int nvalues;
870 
871  rv = get_attstatsslot(stats_tuple, 0, 0, stats_kind, InvalidOid,
872  NULL, NULL, NULL, &floatptr, &nvalues);
873 
874  if ( ! rv ) {
875  POSTGIS_DEBUGF(2,
876  "no slot of kind %d in stats tuple", stats_kind);
877  return NULL;
878  }
879 
880  /* Clone the stats here so we can release the attstatsslot immediately */
881  nd_stats = palloc(sizeof(float) * nvalues);
882  memcpy(nd_stats, floatptr, sizeof(float) * nvalues);
883 
884  /* Clean up */
885  free_attstatsslot(0, NULL, 0, floatptr, nvalues);
886 #else /* PostgreSQL 10 or higher */
887  AttStatsSlot sslot;
888  rv = get_attstatsslot(&sslot, stats_tuple, stats_kind, InvalidOid,
889  ATTSTATSSLOT_NUMBERS);
890  if ( ! rv ) {
891  POSTGIS_DEBUGF(2,
892  "no slot of kind %d in stats tuple", stats_kind);
893  return NULL;
894  }
895 
896  /* Clone the stats here so we can release the attstatsslot immediately */
897  nd_stats = palloc(sizeof(float4) * sslot.nnumbers);
898  memcpy(nd_stats, sslot.numbers, sizeof(float4) * sslot.nnumbers);
899 
900  free_attstatsslot(&sslot);
901 #endif
902 
903  return nd_stats;
904 }
#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: