diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2014-11-28 13:37:25 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2014-11-28 13:37:25 -0500 |
commit | f4e031c662a6b600b786c4849968a099c58fcce7 (patch) | |
tree | 6a082f889ff2ea5b64bb43c467760686e5f013b0 /src/backend/executor/execMain.c | |
parent | 96d66bcfc60d9bcb7db767f23d33abf4d8bc7021 (diff) | |
download | postgresql-f4e031c662a6b600b786c4849968a099c58fcce7.tar.gz postgresql-f4e031c662a6b600b786c4849968a099c58fcce7.zip |
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
Diffstat (limited to 'src/backend/executor/execMain.c')
-rw-r--r-- | src/backend/executor/execMain.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index c499486f016..8c799d3c21b 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -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; |