mirror of
https://github.com/postgres/postgres.git
synced 2025-06-14 18:42:34 +03:00
Add bms_next_member(), and use it where appropriate.
This patch adds a way of iterating through the members of a bitmapset nondestructively, unlike the old way with bms_first_member(). While bms_next_member() is very slightly slower than bms_first_member() (at least for typical-size bitmapsets), eliminating the need to palloc and pfree a temporary copy of the target bitmapset is a significant win. So this method should be preferred in all cases where a temporary copy would be necessary. Tom Lane, with suggestions from Dean Rasheed and David Rowley
This commit is contained in:
@ -547,7 +547,6 @@ ExecCheckRTEPerms(RangeTblEntry *rte)
|
||||
AclMode remainingPerms;
|
||||
Oid relOid;
|
||||
Oid userid;
|
||||
Bitmapset *tmpset;
|
||||
int col;
|
||||
|
||||
/*
|
||||
@ -614,12 +613,13 @@ ExecCheckRTEPerms(RangeTblEntry *rte)
|
||||
return false;
|
||||
}
|
||||
|
||||
tmpset = bms_copy(rte->selectedCols);
|
||||
while ((col = bms_first_member(tmpset)) >= 0)
|
||||
col = -1;
|
||||
while ((col = bms_next_member(rte->selectedCols, col)) >= 0)
|
||||
{
|
||||
/* remove the column number offset */
|
||||
col += FirstLowInvalidHeapAttributeNumber;
|
||||
if (col == InvalidAttrNumber)
|
||||
/* bit #s are offset by FirstLowInvalidHeapAttributeNumber */
|
||||
AttrNumber attno = col + FirstLowInvalidHeapAttributeNumber;
|
||||
|
||||
if (attno == InvalidAttrNumber)
|
||||
{
|
||||
/* Whole-row reference, must have priv on all cols */
|
||||
if (pg_attribute_aclcheck_all(relOid, userid, ACL_SELECT,
|
||||
@ -628,12 +628,11 @@ ExecCheckRTEPerms(RangeTblEntry *rte)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pg_attribute_aclcheck(relOid, col, userid,
|
||||
if (pg_attribute_aclcheck(relOid, attno, userid,
|
||||
ACL_SELECT) != ACLCHECK_OK)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bms_free(tmpset);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -656,24 +655,24 @@ ExecCheckRTEPerms(RangeTblEntry *rte)
|
||||
return false;
|
||||
}
|
||||
|
||||
tmpset = bms_copy(rte->modifiedCols);
|
||||
while ((col = bms_first_member(tmpset)) >= 0)
|
||||
col = -1;
|
||||
while ((col = bms_next_member(rte->modifiedCols, col)) >= 0)
|
||||
{
|
||||
/* remove the column number offset */
|
||||
col += FirstLowInvalidHeapAttributeNumber;
|
||||
if (col == InvalidAttrNumber)
|
||||
/* bit #s are offset by FirstLowInvalidHeapAttributeNumber */
|
||||
AttrNumber attno = col + FirstLowInvalidHeapAttributeNumber;
|
||||
|
||||
if (attno == InvalidAttrNumber)
|
||||
{
|
||||
/* whole-row reference can't happen here */
|
||||
elog(ERROR, "whole-row update is not implemented");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pg_attribute_aclcheck(relOid, col, userid,
|
||||
if (pg_attribute_aclcheck(relOid, attno, userid,
|
||||
remainingPerms) != ACLCHECK_OK)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bms_free(tmpset);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user