Commit 1c04d4be authored by Alvaro Herrera's avatar Alvaro Herrera

Revise BuildIndexValueDescription to simplify it

Getting a pg_index tuple from syscache when the open index relation is
available is pointless -- just use the one from relcache.

Noticed while reviewing code for cb9db2ab.

No backpatch.
parent cb9db2ab
...@@ -180,7 +180,6 @@ BuildIndexValueDescription(Relation indexRelation, ...@@ -180,7 +180,6 @@ BuildIndexValueDescription(Relation indexRelation,
{ {
StringInfoData buf; StringInfoData buf;
Form_pg_index idxrec; Form_pg_index idxrec;
HeapTuple ht_idx;
int indnkeyatts; int indnkeyatts;
int i; int i;
int keyno; int keyno;
...@@ -200,24 +199,13 @@ BuildIndexValueDescription(Relation indexRelation, ...@@ -200,24 +199,13 @@ BuildIndexValueDescription(Relation indexRelation,
* Next we need to check table-level SELECT access and then, if there is * Next we need to check table-level SELECT access and then, if there is
* no access there, check column-level permissions. * no access there, check column-level permissions.
*/ */
idxrec = indexRelation->rd_index;
/*
* Fetch the pg_index tuple by the Oid of the index
*/
ht_idx = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(indexrelid));
if (!HeapTupleIsValid(ht_idx))
elog(ERROR, "cache lookup failed for index %u", indexrelid);
idxrec = (Form_pg_index) GETSTRUCT(ht_idx);
indrelid = idxrec->indrelid; indrelid = idxrec->indrelid;
Assert(indexrelid == idxrec->indexrelid); Assert(indexrelid == idxrec->indexrelid);
/* RLS check- if RLS is enabled then we don't return anything. */ /* RLS check- if RLS is enabled then we don't return anything. */
if (check_enable_rls(indrelid, InvalidOid, true) == RLS_ENABLED) if (check_enable_rls(indrelid, InvalidOid, true) == RLS_ENABLED)
{
ReleaseSysCache(ht_idx);
return NULL; return NULL;
}
/* Table-level SELECT is enough, if the user has it */ /* Table-level SELECT is enough, if the user has it */
aclresult = pg_class_aclcheck(indrelid, GetUserId(), ACL_SELECT); aclresult = pg_class_aclcheck(indrelid, GetUserId(), ACL_SELECT);
...@@ -227,7 +215,7 @@ BuildIndexValueDescription(Relation indexRelation, ...@@ -227,7 +215,7 @@ BuildIndexValueDescription(Relation indexRelation,
* No table-level access, so step through the columns in the index and * No table-level access, so step through the columns in the index and
* make sure the user has SELECT rights on all of them. * make sure the user has SELECT rights on all of them.
*/ */
for (keyno = 0; keyno < idxrec->indnkeyatts; keyno++) for (keyno = 0; keyno < indnkeyatts; keyno++)
{ {
AttrNumber attnum = idxrec->indkey.values[keyno]; AttrNumber attnum = idxrec->indkey.values[keyno];
...@@ -242,12 +230,10 @@ BuildIndexValueDescription(Relation indexRelation, ...@@ -242,12 +230,10 @@ BuildIndexValueDescription(Relation indexRelation,
ACL_SELECT) != ACLCHECK_OK) ACL_SELECT) != ACLCHECK_OK)
{ {
/* No access, so clean up and return */ /* No access, so clean up and return */
ReleaseSysCache(ht_idx);
return NULL; return NULL;
} }
} }
} }
ReleaseSysCache(ht_idx);
initStringInfo(&buf); initStringInfo(&buf);
appendStringInfo(&buf, "(%s)=(", appendStringInfo(&buf, "(%s)=(",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment