PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ gserialized_estimated_extent()

Datum gserialized_estimated_extent ( PG_FUNCTION_ARGS  )

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

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