PostGIS  3.1.6dev-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 2441 of file gserialized_estimate.c.

2442 {
2443  Relation tbl_rel;
2444  ListCell *lc;
2445  List *idx_list;
2446  Oid result = InvalidOid;
2447  char *colname = text_to_cstring(col);
2448 
2449  /* Lookup our spatial index key types */
2450  Oid b2d_oid = postgis_oid(BOX2DFOID);
2451  Oid gdx_oid = postgis_oid(BOX3DOID);
2452 
2453  if (!(b2d_oid && gdx_oid))
2454  return InvalidOid;
2455 
2456  tbl_rel = RelationIdGetRelation(tbl_oid);
2457  idx_list = RelationGetIndexList(tbl_rel);
2458  RelationClose(tbl_rel);
2459 
2460  /* For each index associated with this table... */
2461  foreach(lc, idx_list)
2462  {
2463  Form_pg_class idx_form;
2464  HeapTuple idx_tup;
2465  int idx_relam;
2466  Oid idx_oid = lfirst_oid(lc);
2467 
2468  idx_tup = SearchSysCache1(RELOID, ObjectIdGetDatum(idx_oid));
2469  if (!HeapTupleIsValid(idx_tup))
2470  elog(ERROR, "%s: unable to lookup index %u in syscache", __func__, idx_oid);
2471  idx_form = (Form_pg_class) GETSTRUCT(idx_tup);
2472  idx_relam = idx_form->relam;
2473  ReleaseSysCache(idx_tup);
2474 
2475  /* Does the index use a GIST access method? */
2476  if (idx_relam == GIST_AM_OID)
2477  {
2478  Form_pg_attribute att;
2479  Oid atttypid;
2480  int attnum;
2481  /* Is the index on the column name we are looking for? */
2482  HeapTuple att_tup = SearchSysCache2(ATTNAME,
2483  ObjectIdGetDatum(idx_oid),
2484  PointerGetDatum(colname));
2485  if (!HeapTupleIsValid(att_tup))
2486  continue;
2487 
2488  att = (Form_pg_attribute) GETSTRUCT(att_tup);
2489  atttypid = att->atttypid;
2490  attnum = att->attnum;
2491  ReleaseSysCache(att_tup);
2492 
2493  /* Is the column actually spatial? */
2494  if (b2d_oid == atttypid || gdx_oid == atttypid)
2495  {
2496  /* Save result, clean up, and break out */
2497  result = idx_oid;
2498  if (att_num)
2499  *att_num = attnum;
2500  if (key_type)
2501  *key_type = (atttypid == b2d_oid ? STATISTIC_KIND_2D : STATISTIC_KIND_ND);
2502  break;
2503  }
2504  }
2505  }
2506  return result;
2507 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
#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: