PostGIS  2.5.0beta2dev-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 2411 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().

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