PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ table_get_spatial_index()

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

Definition at line 2421 of file gserialized_estimate.c.

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

References result, STATISTIC_KIND_2D, and STATISTIC_KIND_ND.

Referenced by _postgis_gserialized_index_extent(), and gserialized_estimated_extent().

Here is the caller graph for this function: