PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ gserialized_estimated_extent()

Datum gserialized_estimated_extent ( PG_FUNCTION_ARGS  )

Definition at line 2240 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().

2241 {
2242  char *nsp = NULL;
2243  char *tbl = NULL;
2244  text *col = NULL;
2245  char *nsp_tbl = NULL;
2246  Oid tbl_oid;
2247  ND_STATS *nd_stats;
2248  GBOX *gbox;
2249  bool only_parent = FALSE;
2250 
2251  if ( PG_NARGS() == 4 )
2252  {
2253  nsp = text2cstring(PG_GETARG_TEXT_P(0));
2254  tbl = text2cstring(PG_GETARG_TEXT_P(1));
2255  col = PG_GETARG_TEXT_P(2);
2256  only_parent = PG_GETARG_BOOL(3);
2257  nsp_tbl = palloc(strlen(nsp) + strlen(tbl) + 6);
2258  sprintf(nsp_tbl, "\"%s\".\"%s\"", nsp, tbl);
2259  tbl_oid = DatumGetObjectId(DirectFunctionCall1(regclassin, CStringGetDatum(nsp_tbl)));
2260  pfree(nsp_tbl);
2261  }
2262  else if ( PG_NARGS() == 3 )
2263  {
2264  nsp = text2cstring(PG_GETARG_TEXT_P(0));
2265  tbl = text2cstring(PG_GETARG_TEXT_P(1));
2266  col = PG_GETARG_TEXT_P(2);
2267  nsp_tbl = palloc(strlen(nsp) + strlen(tbl) + 6);
2268  sprintf(nsp_tbl, "\"%s\".\"%s\"", nsp, tbl);
2269  tbl_oid = DatumGetObjectId(DirectFunctionCall1(regclassin, CStringGetDatum(nsp_tbl)));
2270  pfree(nsp_tbl);
2271  }
2272  else if ( PG_NARGS() == 2 )
2273  {
2274  tbl = text2cstring(PG_GETARG_TEXT_P(0));
2275  col = PG_GETARG_TEXT_P(1);
2276  nsp_tbl = palloc(strlen(tbl) + 3);
2277  sprintf(nsp_tbl, "\"%s\"", tbl);
2278  tbl_oid = DatumGetObjectId(DirectFunctionCall1(regclassin, CStringGetDatum(nsp_tbl)));
2279  pfree(nsp_tbl);
2280  }
2281  else
2282  {
2283  elog(ERROR, "estimated_extent() called with wrong number of arguments");
2284  PG_RETURN_NULL();
2285  }
2286 
2287  /* Estimated extent only returns 2D bounds, so use mode 2 */
2288  nd_stats = pg_get_nd_stats_by_name(tbl_oid, col, 2, only_parent);
2289 
2290  /* Error out on no stats */
2291  if ( ! nd_stats ) {
2292  elog(WARNING, "stats for \"%s.%s\" do not exist", tbl, text2cstring(col));
2293  PG_RETURN_NULL();
2294  }
2295 
2296  /* Construct the box */
2297  gbox = palloc(sizeof(GBOX));
2298  FLAGS_SET_GEODETIC(gbox->flags, 0);
2299  FLAGS_SET_Z(gbox->flags, 0);
2300  FLAGS_SET_M(gbox->flags, 0);
2301  gbox->xmin = nd_stats->extent.min[0];
2302  gbox->xmax = nd_stats->extent.max[0];
2303  gbox->ymin = nd_stats->extent.min[1];
2304  gbox->ymax = nd_stats->extent.max[1];
2305 
2306  pfree(nd_stats);
2307  PG_RETURN_POINTER(gbox);
2308 }
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:292
#define FLAGS_SET_GEODETIC(flags, value)
Definition: liblwgeom.h:148
#define FLAGS_SET_Z(flags, value)
Definition: liblwgeom.h:145
double ymin
Definition: liblwgeom.h:293
double xmin
Definition: liblwgeom.h:291
char * text2cstring(const text *textptr)
double ymax
Definition: liblwgeom.h:294
uint8_t flags
Definition: liblwgeom.h:290
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:146
Here is the call graph for this function:
Here is the caller graph for this function: