PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ table_get_spatial_index()

static Oid table_get_spatial_index ( Oid  tbl_oid,
text *  col,
int *  key_type 
)
static

Definition at line 2427 of file gserialized_estimate.c.

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

Referenced by _postgis_gserialized_index_extent(), and gserialized_estimated_extent().

2428 {
2429  Relation tbl_rel;
2430  ListCell *lc;
2431  List *idx_list;
2432  Oid result = InvalidOid;
2433  char *colname = text_to_cstring(col);
2434 
2435  /* Lookup our spatial index key types */
2436  Oid b2d_oid = typname_to_oid(INDEX_KEY_2D);
2437  Oid gdx_oid = typname_to_oid(INDEX_KEY_ND);
2438 
2439  if (!(b2d_oid && gdx_oid))
2440  return InvalidOid;
2441 
2442  tbl_rel = RelationIdGetRelation(tbl_oid);
2443  idx_list = RelationGetIndexList(tbl_rel);
2444  RelationClose(tbl_rel);
2445 
2446  /* For each index associated with this table... */
2447  foreach(lc, idx_list)
2448  {
2449  Form_pg_class idx_form;
2450  HeapTuple idx_tup;
2451  int idx_relam;
2452  Oid idx_oid = lfirst_oid(lc);
2453 
2454  idx_tup = SearchSysCache1(RELOID, ObjectIdGetDatum(idx_oid));
2455  if (!HeapTupleIsValid(idx_tup))
2456  elog(ERROR, "%s: unable to lookup index %u in syscache", __func__, idx_oid);
2457  idx_form = (Form_pg_class) GETSTRUCT(idx_tup);
2458  idx_relam = idx_form->relam;
2459  ReleaseSysCache(idx_tup);
2460 
2461  /* Does the index use a GIST access method? */
2462  if (idx_relam == GIST_AM_OID)
2463  {
2464  Form_pg_attribute att;
2465  Oid atttypid;
2466  /* Is the index on the column name we are looking for? */
2467  HeapTuple att_tup = SearchSysCache2(ATTNAME,
2468  ObjectIdGetDatum(idx_oid),
2469  PointerGetDatum(colname));
2470  if (!HeapTupleIsValid(att_tup))
2471  continue;
2472 
2473  att = (Form_pg_attribute) GETSTRUCT(att_tup);
2474  atttypid = att->atttypid;
2475  ReleaseSysCache(att_tup);
2476 
2477  /* Is the column actually spatial? */
2478  if (b2d_oid == atttypid || gdx_oid == atttypid)
2479  {
2480  /* Save result, clean up, and break out */
2481  result = idx_oid;
2482  if (key_type)
2483  *key_type = (atttypid == b2d_oid ? STATISTIC_SLOT_2D : STATISTIC_SLOT_ND);
2484  break;
2485  }
2486  }
2487  }
2488  return result;
2489 }
char * text_to_cstring(const text *textptr)
#define INDEX_KEY_ND
static Oid typname_to_oid(const char *typname)
#define STATISTIC_SLOT_2D
#define INDEX_KEY_2D
#define STATISTIC_SLOT_ND
Here is the call graph for this function:
Here is the caller graph for this function: