Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit025e7e1

Browse files
Remove count_one_bits() in acl.c.
The only caller, select_best_grantor(), can instead usepg_popcount64(). This isn't performance-critical code, but wemight as well use the centralized implementation. While at it, addsome test coverage for this part of select_best_grantor().Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org>Discussion:https://postgr.es/m/Z9GtL7Nm6hsYyJnF%40nathan
1 parentff79b5b commit025e7e1

File tree

3 files changed

+50
-19
lines changed

3 files changed

+50
-19
lines changed

‎src/backend/utils/adt/acl.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5432,24 +5432,6 @@ select_best_admin(Oid member, Oid role)
54325432
returnadmin_role;
54335433
}
54345434

5435-
5436-
/* does what it says ... */
5437-
staticint
5438-
count_one_bits(AclModemask)
5439-
{
5440-
intnbits=0;
5441-
5442-
/* this code relies on AclMode being an unsigned type */
5443-
while (mask)
5444-
{
5445-
if (mask&1)
5446-
nbits++;
5447-
mask >>=1;
5448-
}
5449-
returnnbits;
5450-
}
5451-
5452-
54535435
/*
54545436
* Select the effective grantor ID for a GRANT or REVOKE operation.
54555437
*
@@ -5532,7 +5514,7 @@ select_best_grantor(Oid roleId, AclMode privileges,
55325514
*/
55335515
if (otherprivs!=ACL_NO_RIGHTS)
55345516
{
5535-
intnnewrights=count_one_bits(otherprivs);
5517+
intnnewrights=pg_popcount64(otherprivs);
55365518

55375519
if (nnewrights>nrights)
55385520
{

‎src/test/regress/expected/privileges.out

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3293,3 +3293,30 @@ DROP SCHEMA reindex_test;
32933293
DROP ROLE regress_no_maintain;
32943294
DROP ROLE regress_maintain;
32953295
DROP ROLE regress_maintain_all;
3296+
-- grantor selection
3297+
CREATE ROLE regress_grantor1;
3298+
CREATE ROLE regress_grantor2 ROLE regress_grantor1;
3299+
CREATE ROLE regress_grantor3;
3300+
CREATE TABLE grantor_test1 ();
3301+
CREATE TABLE grantor_test2 ();
3302+
CREATE TABLE grantor_test3 ();
3303+
GRANT SELECT ON grantor_test2 TO regress_grantor1 WITH GRANT OPTION;
3304+
GRANT SELECT, UPDATE ON grantor_test3 TO regress_grantor2 WITH GRANT OPTION;
3305+
SET ROLE regress_grantor1;
3306+
GRANT SELECT, UPDATE ON grantor_test1 TO regress_grantor3;
3307+
ERROR: permission denied for table grantor_test1
3308+
GRANT SELECT, UPDATE ON grantor_test2 TO regress_grantor3;
3309+
WARNING: not all privileges were granted for "grantor_test2"
3310+
GRANT SELECT, UPDATE ON grantor_test3 TO regress_grantor3;
3311+
RESET ROLE;
3312+
SELECT * FROM information_schema.table_privileges t
3313+
WHERE grantor LIKE 'regress_grantor%' ORDER BY ROW(t.*);
3314+
grantor | grantee | table_catalog | table_schema | table_name | privilege_type | is_grantable | with_hierarchy
3315+
------------------+------------------+---------------+--------------+---------------+----------------+--------------+----------------
3316+
regress_grantor1 | regress_grantor3 | regression | public | grantor_test2 | SELECT | NO | YES
3317+
regress_grantor2 | regress_grantor3 | regression | public | grantor_test3 | SELECT | NO | YES
3318+
regress_grantor2 | regress_grantor3 | regression | public | grantor_test3 | UPDATE | NO | NO
3319+
(3 rows)
3320+
3321+
DROP TABLE grantor_test1, grantor_test2, grantor_test3;
3322+
DROP ROLE regress_grantor1, regress_grantor2, regress_grantor3;

‎src/test/regress/sql/privileges.sql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,3 +2042,25 @@ DROP SCHEMA reindex_test;
20422042
DROP ROLE regress_no_maintain;
20432043
DROP ROLE regress_maintain;
20442044
DROP ROLE regress_maintain_all;
2045+
2046+
-- grantor selection
2047+
CREATE ROLE regress_grantor1;
2048+
CREATE ROLE regress_grantor2 ROLE regress_grantor1;
2049+
CREATE ROLE regress_grantor3;
2050+
CREATETABLEgrantor_test1 ();
2051+
CREATETABLEgrantor_test2 ();
2052+
CREATETABLEgrantor_test3 ();
2053+
GRANTSELECTON grantor_test2 TO regress_grantor1 WITHGRANT OPTION;
2054+
GRANTSELECT,UPDATEON grantor_test3 TO regress_grantor2 WITHGRANT OPTION;
2055+
2056+
SET ROLE regress_grantor1;
2057+
GRANTSELECT,UPDATEON grantor_test1 TO regress_grantor3;
2058+
GRANTSELECT,UPDATEON grantor_test2 TO regress_grantor3;
2059+
GRANTSELECT,UPDATEON grantor_test3 TO regress_grantor3;
2060+
RESET ROLE;
2061+
2062+
SELECT*FROMinformation_schema.table_privileges t
2063+
WHERE grantorLIKE'regress_grantor%'ORDER BY ROW(t.*);
2064+
2065+
DROPTABLE grantor_test1, grantor_test2, grantor_test3;
2066+
DROP ROLE regress_grantor1, regress_grantor2, regress_grantor3;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp