PostGIS  2.5.2dev-r@@SVN_REVISION@@

◆ _postgis_gserialized_stats()

Datum _postgis_gserialized_stats ( PG_FUNCTION_ARGS  )

Definition at line 2065 of file gserialized_estimate.c.

References _postgis_gserialized_sel(), nd_stats_to_json(), PG_FUNCTION_INFO_V1(), pg_get_nd_stats_by_name(), text_p_get_mode(), and text_to_cstring().

Referenced by estimate_selectivity().

2066 {
2067  Oid table_oid = PG_GETARG_OID(0);
2068  text *att_text = PG_GETARG_TEXT_P(1);
2069  ND_STATS *nd_stats;
2070  char *str;
2071  text *json;
2072  int mode = 2; /* default to 2D mode */
2073  bool only_parent = false; /* default to whole tree stats */
2074 
2075  /* Check if we've been asked to not use 2d mode */
2076  if ( ! PG_ARGISNULL(2) )
2077  mode = text_p_get_mode(PG_GETARG_TEXT_P(2));
2078 
2079  /* Check if we've been asked to only use stats from parent */
2080  if ( ! PG_ARGISNULL(3) )
2081  only_parent = PG_GETARG_BOOL(3);
2082 
2083  /* Retrieve the stats object */
2084  nd_stats = pg_get_nd_stats_by_name(table_oid, att_text, mode, only_parent);
2085  if ( ! nd_stats )
2086  elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid), text_to_cstring(att_text));
2087 
2088  /* Convert to JSON */
2089  str = nd_stats_to_json(nd_stats);
2090  json = cstring_to_text(str);
2091  pfree(str);
2092  pfree(nd_stats);
2093  PG_RETURN_TEXT_P(json);
2094 }
char * text_to_cstring(const text *textptr)
static ND_STATS * pg_get_nd_stats_by_name(const Oid table_oid, const text *att_text, int mode, bool only_parent)
Pull the stats object from the PgSQL system catalogs.
static int text_p_get_mode(const text *txt)
Utility function to see if the first letter of the mode argument is 'N'.
static char * nd_stats_to_json(const ND_STATS *nd_stats)
Convert an ND_STATS to a JSON representation for external use.
N-dimensional statistics structure.
Here is the call graph for this function:
Here is the caller graph for this function: