PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ gserialized_estimated_extent()

Datum gserialized_estimated_extent ( PG_FUNCTION_ARGS  )

Definition at line 2265 of file gserialized_estimate.c.

References ND_STATS_T::extent, FALSE, GBOX::flags, FLAGS_SET_GEODETIC, FLAGS_SET_M, FLAGS_SET_Z, geometry_estimated_extent(), ND_BOX_T::max, ND_BOX_T::min, PG_FUNCTION_INFO_V1(), pg_get_nd_stats_by_name(), text2cstring(), GBOX::xmax, GBOX::xmin, GBOX::ymax, and GBOX::ymin.

Referenced by geometry_estimated_extent(), and gserialized_gist_sel().

2266 {
2267  char *nsp = NULL;
2268  char *tbl = NULL;
2269  text *col = NULL;
2270  char *nsp_tbl = NULL;
2271  Oid tbl_oid;
2272  ND_STATS *nd_stats;
2273  GBOX *gbox;
2274  bool only_parent = FALSE;
2275 
2276  if ( PG_NARGS() == 4 )
2277  {
2278  nsp = text2cstring(PG_GETARG_TEXT_P(0));
2279  tbl = text2cstring(PG_GETARG_TEXT_P(1));
2280  col = PG_GETARG_TEXT_P(2);
2281  only_parent = PG_GETARG_BOOL(3);
2282  nsp_tbl = palloc(strlen(nsp) + strlen(tbl) + 6);
2283  sprintf(nsp_tbl, "\"%s\".\"%s\"", nsp, tbl);
2284  tbl_oid = DatumGetObjectId(DirectFunctionCall1(regclassin, CStringGetDatum(nsp_tbl)));
2285  pfree(nsp_tbl);
2286  }
2287  else if ( PG_NARGS() == 3 )
2288  {
2289  nsp = text2cstring(PG_GETARG_TEXT_P(0));
2290  tbl = text2cstring(PG_GETARG_TEXT_P(1));
2291  col = PG_GETARG_TEXT_P(2);
2292  nsp_tbl = palloc(strlen(nsp) + strlen(tbl) + 6);
2293  sprintf(nsp_tbl, "\"%s\".\"%s\"", nsp, tbl);
2294  tbl_oid = DatumGetObjectId(DirectFunctionCall1(regclassin, CStringGetDatum(nsp_tbl)));
2295  pfree(nsp_tbl);
2296  }
2297  else if ( PG_NARGS() == 2 )
2298  {
2299  tbl = text2cstring(PG_GETARG_TEXT_P(0));
2300  col = PG_GETARG_TEXT_P(1);
2301  nsp_tbl = palloc(strlen(tbl) + 3);
2302  sprintf(nsp_tbl, "\"%s\"", tbl);
2303  tbl_oid = DatumGetObjectId(DirectFunctionCall1(regclassin, CStringGetDatum(nsp_tbl)));
2304  pfree(nsp_tbl);
2305  }
2306  else
2307  {
2308  elog(ERROR, "estimated_extent() called with wrong number of arguments");
2309  PG_RETURN_NULL();
2310  }
2311 
2312  /* Estimated extent only returns 2D bounds, so use mode 2 */
2313  nd_stats = pg_get_nd_stats_by_name(tbl_oid, col, 2, only_parent);
2314 
2315  /* Error out on no stats */
2316  if ( ! nd_stats ) {
2317  elog(WARNING, "stats for \"%s.%s\" do not exist", tbl, text2cstring(col));
2318  PG_RETURN_NULL();
2319  }
2320 
2321  /* Construct the box */
2322  gbox = palloc(sizeof(GBOX));
2323  FLAGS_SET_GEODETIC(gbox->flags, 0);
2324  FLAGS_SET_Z(gbox->flags, 0);
2325  FLAGS_SET_M(gbox->flags, 0);
2326  gbox->xmin = nd_stats->extent.min[0];
2327  gbox->xmax = nd_stats->extent.max[0];
2328  gbox->ymin = nd_stats->extent.min[1];
2329  gbox->ymax = nd_stats->extent.max[1];
2330 
2331  pfree(nd_stats);
2332  PG_RETURN_POINTER(gbox);
2333 }
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.
double xmax
Definition: liblwgeom.h:293
#define FLAGS_SET_GEODETIC(flags, value)
Definition: liblwgeom.h:149
#define FLAGS_SET_Z(flags, value)
Definition: liblwgeom.h:146
double ymin
Definition: liblwgeom.h:294
double xmin
Definition: liblwgeom.h:292
char * text2cstring(const text *textptr)
double ymax
Definition: liblwgeom.h:295
uint8_t flags
Definition: liblwgeom.h:291
float4 max[ND_DIMS]
float4 min[ND_DIMS]
#define FALSE
Definition: dbfopen.c:168
N-dimensional statistics structure.
#define FLAGS_SET_M(flags, value)
Definition: liblwgeom.h:147
Here is the call graph for this function:
Here is the caller graph for this function: