--- build-tree/postgresql-8.0.3/src/backend/commands/user.c.orig 2005-10-14 11:00:16.000000000 +1300 +++ build-tree/postgresql-8.0.3/src/backend/commands/user.c 2005-10-14 11:01:09.000000000 +1300 @@ -17,6 +17,7 @@ #include #include +#include "access/genam.h" #include "access/heapam.h" #include "catalog/catname.h" #include "catalog/indexing.h" @@ -154,6 +155,27 @@ HeapScanDesc scan; HeapTuple tuple; TupleDesc dsc = RelationGetDescr(grel); + /* Look up user names by user system id. */ + Relation urel = heap_openr(ShadowRelationName, AccessShareLock), + ureli = index_openr(ShadowSysidIndex); + + /* Scan for system id equality. */ + ScanKeyData ukey = + { + .sk_flags = 0, + .sk_attno = 1, + .sk_strategy = BTEqualStrategyNumber, + .sk_subtype = InvalidOid + }; + + /* We expect the first index column to be in order. */ + Assert(Anum_pg_shadow_usesysid == ureli->rd_index->indkey[0]); + + /* And only one system identifier column type. */ + Assert(RelationGetDescr(urel)->attrs[Anum_pg_shadow_usesysid - 1]->atttypid == INT4OID); + + /* Finish scan key initialisation. */ + fmgr_info(F_INT4EQ, &ukey.sk_func); /* * Create a temporary filename to be renamed later. This prevents the @@ -192,6 +214,7 @@ num; char *usename; bool first_user = true; + IndexScanDesc userscan; datum = heap_getattr(tuple, Anum_pg_group_groname, dsc, &isnull); /* ignore NULL groupnames --- shouldn't happen */ @@ -221,11 +244,12 @@ /* scan grolist */ num = IDLIST_NUM(grolist_p); aidp = IDLIST_DAT(grolist_p); - for (i = 0; i < num; ++i) + for (i = 0; i < num; ++i, index_endscan(userscan)) { - tuple = SearchSysCache(SHADOWSYSID, - PointerGetDatum(aidp[i]), - 0, 0, 0); + ukey.sk_argument = PointerGetDatum(aidp[i]); + userscan = index_beginscan(urel, ureli, SnapshotSelf, 1, &ukey); + tuple = index_getnext(userscan, ForwardScanDirection); + if (HeapTupleIsValid(tuple)) { usename = NameStr(((Form_pg_shadow) GETSTRUCT(tuple))->usename); @@ -254,8 +278,6 @@ first_user = false; fputs_quote(usename, fp); - - ReleaseSysCache(tuple); } } if (!first_user) @@ -265,6 +287,8 @@ pfree(grolist_p); } heap_endscan(scan); + index_close(ureli); + heap_close(urel, AccessShareLock); if (FreeFile(fp)) ereport(ERROR,