PostGIS  2.5.0dev-r@@SVN_REVISION@@
static Oid table_get_spatial_index ( Oid  tbl_oid,
text *  col,
int *  key_type 
)
static

Definition at line 2408 of file gserialized_estimate.c.

References INDEX_KEY_2D, INDEX_KEY_ND, STATISTIC_SLOT_2D, STATISTIC_SLOT_ND, text2cstring(), and typname_to_oid().

Referenced by _postgis_gserialized_index_extent(), and gserialized_estimated_extent().

2409 {
2410  Relation tbl_rel;
2411  ListCell *lc;
2412  List *idx_list;
2413  Oid result = InvalidOid;
2414  char *colname = text2cstring(col);
2415 
2416  /* Lookup our spatial index key types */
2417  Oid b2d_oid = typname_to_oid(INDEX_KEY_2D);
2418  Oid gdx_oid = typname_to_oid(INDEX_KEY_ND);
2419 
2420  if (!(b2d_oid && gdx_oid))
2421  return InvalidOid;
2422 
2423  tbl_rel = RelationIdGetRelation(tbl_oid);
2424  idx_list = RelationGetIndexList(tbl_rel);
2425  RelationClose(tbl_rel);
2426 
2427  /* For each index associated with this table... */
2428  foreach(lc, idx_list)
2429  {
2430  Form_pg_class idx_form;
2431  HeapTuple idx_tup;
2432  int idx_relam;
2433  Oid idx_oid = lfirst_oid(lc);
2434 
2435  idx_tup = SearchSysCache1(RELOID, ObjectIdGetDatum(idx_oid));
2436  if (!HeapTupleIsValid(idx_tup))
2437  elog(ERROR, "%s: unable to lookup index %u in syscache", __func__, idx_oid);
2438  idx_form = (Form_pg_class) GETSTRUCT(idx_tup);
2439  idx_relam = idx_form->relam;
2440  ReleaseSysCache(idx_tup);
2441 
2442  /* Does the index use a GIST access method? */
2443  if (idx_relam == GIST_AM_OID)
2444  {
2445  Form_pg_attribute att;
2446  Oid atttypid;
2447  /* Is the index on the column name we are looking for? */
2448  HeapTuple att_tup = SearchSysCache2(ATTNAME,
2449  ObjectIdGetDatum(idx_oid),
2450  PointerGetDatum(colname));
2451  if (!HeapTupleIsValid(att_tup))
2452  continue;
2453 
2454  att = (Form_pg_attribute) GETSTRUCT(att_tup);
2455  atttypid = att->atttypid;
2456  ReleaseSysCache(att_tup);
2457 
2458  /* Is the column actually spatial? */
2459  if (b2d_oid == atttypid || gdx_oid == atttypid)
2460  {
2461  /* Save result, clean up, and break out */
2462  result = idx_oid;
2463  if (key_type)
2464  *key_type = (atttypid == b2d_oid ? STATISTIC_SLOT_2D : STATISTIC_SLOT_ND);
2465  break;
2466  }
2467  }
2468  }
2469  return result;
2470 }
#define INDEX_KEY_ND
static Oid typname_to_oid(const char *typname)
#define STATISTIC_SLOT_2D
#define INDEX_KEY_2D
char * text2cstring(const text *textptr)
#define STATISTIC_SLOT_ND

Here is the call graph for this function:

Here is the caller graph for this function: