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 832 of file gserialized_estimate.c.

References STATISTIC_KIND_2D, and STATISTIC_KIND_ND.

Referenced by gserialized_gist_sel(), and pg_get_nd_stats().

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