2601 text *coltxt = NULL;
2603 int16 attnum, idx_attnum;
2604 Oid atttypid = InvalidOid;
2605 char nsp_tbl[2*NAMEDATALEN+6];
2607 Oid tbl_oid, idx_oid = 0;
2610 bool only_parent =
false;
2612 Oid geographyOid = postgis_oid(GEOGRAPHYOID);
2613 Oid geometryOid = postgis_oid(GEOMETRYOID);
2616 postgis_initialize_cache();
2618 if (PG_NARGS() < 2 || PG_NARGS() > 4)
2619 elog(ERROR,
"ST_EstimatedExtent() called with wrong number of arguments");
2621 if ( PG_NARGS() == 4 )
2623 only_parent = PG_GETARG_BOOL(3);
2625 if ( PG_NARGS() >= 3 )
2627 char *nsp = text_to_cstring(PG_GETARG_TEXT_P(0));
2628 tbl = text_to_cstring(PG_GETARG_TEXT_P(1));
2629 coltxt = PG_GETARG_TEXT_P(2);
2630 snprintf(nsp_tbl,
sizeof(nsp_tbl),
"\"%s\".\"%s\"", nsp, tbl);
2632 if ( PG_NARGS() == 2 )
2634 tbl = text_to_cstring(PG_GETARG_TEXT_P(0));
2635 coltxt = PG_GETARG_TEXT_P(1);
2636 snprintf(nsp_tbl,
sizeof(nsp_tbl),
"\"%s\"", tbl);
2640 tbl_oid = DatumGetObjectId(DirectFunctionCall1(regclassin, CStringGetDatum(nsp_tbl)));
2642 elog(ERROR,
"cannot lookup table %s", nsp_tbl);
2645 col = text_to_cstring(coltxt);
2647 elog(ERROR,
"column %s.\"%s\" does not exist", nsp_tbl, col);
2650 if ((atttypid != geographyOid) && (atttypid != geometryOid))
2652 elog(ERROR,
"column %s.\"%s\" must be a geometry or geography", nsp_tbl, col);
2658 if (idx_oid != InvalidOid)
2662 elog(DEBUG3,
"index for %s.\"%s\" exists, reading gbox from there", nsp_tbl, col);
2663 if (!gbox) PG_RETURN_NULL();
2670 elog(DEBUG3,
"index for %s.\"%s\" does not exist", nsp_tbl, col);
2673 if (atttypid == geographyOid)
2682 elog(WARNING,
"stats for \"%s.%s\" do not exist", tbl, col);
2692 if (stats_mode != 2)
2704 if (atttypid == geographyOid)
2708 PG_RETURN_POINTER(gbox_planar);
2711 PG_RETURN_POINTER(gbox);
GBOX * gbox_new(lwflags_t flags)
Create a new gbox with the dimensionality indicated by the flags.
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 bool get_attnum_attypid(Oid table_oid, const char *col, int16 *attnum, Oid *atttypid)
static GBOX * spatial_index_read_extent(Oid idx_oid, int idx_att_num, int key_type)
static Oid table_get_spatial_index(Oid tbl_oid, int16 attnum, int *key_type, int16 *idx_attnum)
#define FLAGS_SET_Z(flags, value)
int gbox_geocentric_get_gbox_cartesian(const GBOX *gbox_geocentric, GBOX *gbox_planar)
N-dimensional statistics structure.