PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ gserialized_estimated_extent()

Datum gserialized_estimated_extent ( PG_FUNCTION_ARGS  )

Definition at line 2306 of file gserialized_estimate.c.

2307 {
2308  char *nsp = NULL;
2309  char *tbl = NULL;
2310  text *col = NULL;
2311  char *nsp_tbl = NULL;
2312  Oid tbl_oid, idx_oid;
2313  ND_STATS *nd_stats;
2314  GBOX *gbox = NULL;
2315  bool only_parent = false;
2316  int key_type;
2317 
2318  if ( PG_NARGS() == 4 )
2319  {
2320  nsp = text_to_cstring(PG_GETARG_TEXT_P(0));
2321  tbl = text_to_cstring(PG_GETARG_TEXT_P(1));
2322  col = PG_GETARG_TEXT_P(2);
2323  only_parent = PG_GETARG_BOOL(3);
2324  nsp_tbl = palloc(strlen(nsp) + strlen(tbl) + 6);
2325  sprintf(nsp_tbl, "\"%s\".\"%s\"", nsp, tbl);
2326  tbl_oid = DatumGetObjectId(DirectFunctionCall1(regclassin, CStringGetDatum(nsp_tbl)));
2327  pfree(nsp_tbl);
2328  }
2329  else if ( PG_NARGS() == 3 )
2330  {
2331  nsp = text_to_cstring(PG_GETARG_TEXT_P(0));
2332  tbl = text_to_cstring(PG_GETARG_TEXT_P(1));
2333  col = PG_GETARG_TEXT_P(2);
2334  nsp_tbl = palloc(strlen(nsp) + strlen(tbl) + 6);
2335  sprintf(nsp_tbl, "\"%s\".\"%s\"", nsp, tbl);
2336  tbl_oid = DatumGetObjectId(DirectFunctionCall1(regclassin, CStringGetDatum(nsp_tbl)));
2337  pfree(nsp_tbl);
2338  }
2339  else if ( PG_NARGS() == 2 )
2340  {
2341  tbl = text_to_cstring(PG_GETARG_TEXT_P(0));
2342  col = PG_GETARG_TEXT_P(1);
2343  nsp_tbl = palloc(strlen(tbl) + 3);
2344  sprintf(nsp_tbl, "\"%s\"", tbl);
2345  tbl_oid = DatumGetObjectId(DirectFunctionCall1(regclassin, CStringGetDatum(nsp_tbl)));
2346  pfree(nsp_tbl);
2347  }
2348  else
2349  {
2350  elog(ERROR, "estimated_extent() called with wrong number of arguments");
2351  PG_RETURN_NULL();
2352  }
2353 
2354 #if 1
2355  /* Read the extent from the head of the spatial index, if there is one */
2356  idx_oid = table_get_spatial_index(tbl_oid, col, &key_type);
2357  if (!idx_oid)
2358  elog(DEBUG2, "index for \"%s.%s\" does not exist", tbl, text_to_cstring(col));
2359  gbox = spatial_index_read_extent(idx_oid, key_type);
2360 #endif
2361 
2362  /* Fall back to reading the stats, if no index answer */
2363  if (!gbox)
2364  {
2365  /* Estimated extent only returns 2D bounds, so use mode 2 */
2366  nd_stats = pg_get_nd_stats_by_name(tbl_oid, col, 2, only_parent);
2367 
2368  /* Error out on no stats */
2369  if ( ! nd_stats ) {
2370  elog(WARNING, "stats for \"%s.%s\" do not exist", tbl, text_to_cstring(col));
2371  PG_RETURN_NULL();
2372  }
2373 
2374  /* Construct the box */
2375  gbox = palloc(sizeof(GBOX));
2376  FLAGS_SET_GEODETIC(gbox->flags, 0);
2377  FLAGS_SET_Z(gbox->flags, 0);
2378  FLAGS_SET_M(gbox->flags, 0);
2379  gbox->xmin = nd_stats->extent.min[0];
2380  gbox->xmax = nd_stats->extent.max[0];
2381  gbox->ymin = nd_stats->extent.min[1];
2382  gbox->ymax = nd_stats->extent.max[1];
2383  pfree(nd_stats);
2384  }
2385 
2386  PG_RETURN_POINTER(gbox);
2387 }
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 GBOX * spatial_index_read_extent(Oid idx_oid, int key_type)
static Oid table_get_spatial_index(Oid tbl_oid, text *col, int *key_type)
#define FLAGS_SET_GEODETIC(flags, value)
Definition: liblwgeom.h:149
#define FLAGS_SET_M(flags, value)
Definition: liblwgeom.h:147
#define FLAGS_SET_Z(flags, value)
Definition: liblwgeom.h:146
char * text_to_cstring(const text *textptr)
double ymax
Definition: liblwgeom.h:298
double xmax
Definition: liblwgeom.h:296
double ymin
Definition: liblwgeom.h:297
double xmin
Definition: liblwgeom.h:295
uint8_t flags
Definition: liblwgeom.h:294
float4 max[ND_DIMS]
float4 min[ND_DIMS]
N-dimensional statistics structure.

References ND_STATS_T::extent, GBOX::flags, FLAGS_SET_GEODETIC, FLAGS_SET_M, FLAGS_SET_Z, ND_BOX_T::max, ND_BOX_T::min, pg_get_nd_stats_by_name(), spatial_index_read_extent(), table_get_spatial_index(), text_to_cstring(), GBOX::xmax, GBOX::xmin, GBOX::ymax, and GBOX::ymin.

Referenced by geometry_estimated_extent().

Here is the call graph for this function:
Here is the caller graph for this function: