diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c index 05d48412f82..5014845e89c 100644 --- a/src/backend/utils/adt/acl.c +++ b/src/backend/utils/adt/acl.c @@ -5481,6 +5481,7 @@ select_best_grantor(Oid roleId, AclMode privileges, List *roles_list; int nrights; ListCell *l; + AclMode otherprivs; /* * The object owner is always treated as having all grant options, so if @@ -5504,6 +5505,17 @@ select_best_grantor(Oid roleId, AclMode privileges, roles_list = roles_is_member_of(roleId, ROLERECURSE_PRIVS, InvalidOid, NULL); + otherprivs = aclmask_direct(acl, roleId, ownerId, + needed_goptions, ACLMASK_ANY); + + if (otherprivs != 0) + { + /* Found a suitable grantor */ + *grantorId = roleId; + *grantOptions = otherprivs; + return; + } + /* initialize candidate result as default */ *grantorId = roleId; *grantOptions = ACL_NO_RIGHTS; @@ -5512,7 +5524,6 @@ select_best_grantor(Oid roleId, AclMode privileges, foreach(l, roles_list) { Oid otherrole = lfirst_oid(l); - AclMode otherprivs; otherprivs = aclmask_direct(acl, otherrole, ownerId, needed_goptions, ACLMASK_ALL);