PostGIS  3.3.9dev-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 2423 of file gserialized_estimate.c.

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