PostGIS  2.1.10dev-r@@SVN_REVISION@@
static ND_STATS* pg_get_nd_stats ( const Oid  table_oid,
AttrNumber  att_num,
int  mode 
)
static

Pull the stats object from the PgSQL system catalogs.

Used by the selectivity functions and the debugging functions.

Definition at line 808 of file gserialized_estimate.c.

References STATISTIC_KIND_2D, and STATISTIC_KIND_ND.

Referenced by gserialized_gist_joinsel(), gserialized_gist_sel(), and pg_get_nd_stats_by_name().

809 {
810  HeapTuple stats_tuple;
811  float4 *floatptr;
812  ND_STATS *nd_stats;
813  int rv, nvalues;
814  int stats_kind = STATISTIC_KIND_ND;
815 
816  /* First pull the stats tuple */
817  stats_tuple = SearchSysCache2(STATRELATT, table_oid, att_num);
818  if ( ! stats_tuple )
819  {
820  POSTGIS_DEBUGF(2, "stats for \"%s\" do not exist", get_rel_name(table_oid)? get_rel_name(table_oid) : "NULL");
821  return NULL;
822  }
823 
824  /* If we're in 2D mode, set the kind appropriately */
825  if ( mode == 2 )
826  stats_kind = STATISTIC_KIND_2D;
827 
828  /* Then read the geom status histogram from that */
829  rv = get_attstatsslot(stats_tuple, 0, 0, stats_kind, InvalidOid, NULL, NULL, NULL, &floatptr, &nvalues);
830  if ( ! rv )
831  {
832  ReleaseSysCache(stats_tuple);
833  POSTGIS_DEBUGF(2, "histogram for \"%s\" does not exist?", get_rel_name(table_oid));
834  return NULL;
835  }
836 
837  /* Clone the stats here so we can release the attstatsslot immediately */
838  nd_stats = palloc(sizeof(float) * nvalues);
839  memcpy(nd_stats, floatptr, sizeof(float) * nvalues);
840 
841  /* Clean up */
842  free_attstatsslot(0, NULL, 0, floatptr, nvalues);
843  ReleaseSysCache(stats_tuple);
844 
845  return nd_stats;
846 }
#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: