PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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 2431 of file gserialized_estimate.c.

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

References STATISTIC_SLOT_2D, STATISTIC_SLOT_ND, and text_to_cstring().

Referenced by _postgis_gserialized_index_extent(), and gserialized_estimated_extent().

Here is the call graph for this function:
Here is the caller graph for this function: