PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ _postgis_gserialized_stats()

Datum _postgis_gserialized_stats ( PG_FUNCTION_ARGS  )

Definition at line 2020 of file gserialized_estimate.c.

References _postgis_gserialized_sel(), FALSE, nd_stats_to_json(), PG_FUNCTION_INFO_V1(), pg_get_nd_stats_by_name(), text2cstring(), and text_p_get_mode().

Referenced by estimate_selectivity().

2021 {
2022  Oid table_oid = PG_GETARG_OID(0);
2023  text *att_text = PG_GETARG_TEXT_P(1);
2024  ND_STATS *nd_stats;
2025  char *str;
2026  text *json;
2027  int mode = 2; /* default to 2D mode */
2028  bool only_parent = FALSE; /* default to whole tree stats */
2029 
2030  /* Check if we've been asked to not use 2d mode */
2031  if ( ! PG_ARGISNULL(2) )
2032  mode = text_p_get_mode(PG_GETARG_TEXT_P(2));
2033 
2034  /* Retrieve the stats object */
2035  nd_stats = pg_get_nd_stats_by_name(table_oid, att_text, mode, only_parent);
2036  if ( ! nd_stats )
2037  elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid), text2cstring(att_text));
2038 
2039  /* Convert to JSON */
2040  str = nd_stats_to_json(nd_stats);
2041  json = cstring2text(str);
2042  pfree(str);
2043  pfree(nd_stats);
2044  PG_RETURN_TEXT_P(json);
2045 }
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'.
char * text2cstring(const text *textptr)
#define FALSE
Definition: dbfopen.c:168
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: