Skip to content

Commit 1c04d4b

Browse files
committed
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 cb9db2a. No backpatch.
1 parent cb9db2a commit 1c04d4b

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

src/backend/access/index/genam.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ BuildIndexValueDescription(Relation indexRelation,
180180
{
181181
StringInfoData buf;
182182
Form_pg_index idxrec;
183-
HeapTuple ht_idx;
184183
int indnkeyatts;
185184
int i;
186185
int keyno;
@@ -200,24 +199,13 @@ BuildIndexValueDescription(Relation indexRelation,
200199
* Next we need to check table-level SELECT access and then, if there is
201200
* no access there, check column-level permissions.
202201
*/
203-
204-
/*
205-
* Fetch the pg_index tuple by the Oid of the index
206-
*/
207-
ht_idx = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(indexrelid));
208-
if (!HeapTupleIsValid(ht_idx))
209-
elog(ERROR, "cache lookup failed for index %u", indexrelid);
210-
idxrec = (Form_pg_index) GETSTRUCT(ht_idx);
211-
202+
idxrec = indexRelation->rd_index;
212203
indrelid = idxrec->indrelid;
213204
Assert(indexrelid == idxrec->indexrelid);
214205

215206
/* RLS check- if RLS is enabled then we don't return anything. */
216207
if (check_enable_rls(indrelid, InvalidOid, true) == RLS_ENABLED)
217-
{
218-
ReleaseSysCache(ht_idx);
219208
return NULL;
220-
}
221209

222210
/* Table-level SELECT is enough, if the user has it */
223211
aclresult = pg_class_aclcheck(indrelid, GetUserId(), ACL_SELECT);
@@ -227,7 +215,7 @@ BuildIndexValueDescription(Relation indexRelation,
227215
* No table-level access, so step through the columns in the index and
228216
* make sure the user has SELECT rights on all of them.
229217
*/
230-
for (keyno = 0; keyno < idxrec->indnkeyatts; keyno++)
218+
for (keyno = 0; keyno < indnkeyatts; keyno++)
231219
{
232220
AttrNumber attnum = idxrec->indkey.values[keyno];
233221

@@ -242,12 +230,10 @@ BuildIndexValueDescription(Relation indexRelation,
242230
ACL_SELECT) != ACLCHECK_OK)
243231
{
244232
/* No access, so clean up and return */
245-
ReleaseSysCache(ht_idx);
246233
return NULL;
247234
}
248235
}
249236
}
250-
ReleaseSysCache(ht_idx);
251237

252238
initStringInfo(&buf);
253239
appendStringInfo(&buf, "(%s)=(",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy