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

Commit50b797d

Browse files
committed
Fix DROP ROLE when specifying duplicated roles
This commit fixes failures with "tuple already updated by self" whenlisting twice the same role and in a DROP ROLE query.This is an oversight in6566133, that has introduced a two-phaselogic in DropRole() where dependencies of all the roles to drop areremoved in a first phase, with the roles themselves removed frompg_authid in a second phase.The code is simplified to not rely on a List of ObjectAddress built inthe first phase used to remove the pg_authid entries in the secondphase, switching to a list of OIDs. Duplicated OIDs can be simplyavoided in the first phase thanks to that. Using ObjectAddress was notnecessary for the roles as they are not used for anything specific todependency.c, building all the ObjectAddress in the List withAuthIdRelationId as class ID.In 15 and older versions, where a single phase is used, DROP ROLE withduplicated role names would fail on "role \"blah\" does not exist" forthe second entry after the CCI() done by the first deletion. This isnot really incorrect, but it does not seem worth changing based on alack of complaints.Reported-by: Alexander LakhinReviewed-by: Tender WangDiscussion:https://postgr.es/m/18310-1eb233c5908189c8@postgresql.orgBackpatch-through: 16
1 parenta3a836f commit50b797d

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

‎src/backend/commands/user.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ DropRole(DropRoleStmt *stmt)
10931093
Relationpg_authid_rel,
10941094
pg_auth_members_rel;
10951095
ListCell*item;
1096-
List*role_addresses=NIL;
1096+
List*role_oids=NIL;
10971097

10981098
if (!have_createrole_privilege())
10991099
ereport(ERROR,
@@ -1119,7 +1119,6 @@ DropRole(DropRoleStmt *stmt)
11191119
ScanKeyDatascankey;
11201120
SysScanDescsscan;
11211121
Oidroleid;
1122-
ObjectAddress*role_address;
11231122

11241123
if (rolspec->roletype!=ROLESPEC_CSTRING)
11251124
ereport(ERROR,
@@ -1260,21 +1259,16 @@ DropRole(DropRoleStmt *stmt)
12601259
*/
12611260
CommandCounterIncrement();
12621261

1263-
/* Looks tentatively OK, add it to the list. */
1264-
role_address=palloc(sizeof(ObjectAddress));
1265-
role_address->classId=AuthIdRelationId;
1266-
role_address->objectId=roleid;
1267-
role_address->objectSubId=0;
1268-
role_addresses=lappend(role_addresses,role_address);
1262+
/* Looks tentatively OK, add it to the list if not there yet. */
1263+
role_oids=list_append_unique_oid(role_oids,roleid);
12691264
}
12701265

12711266
/*
12721267
* Second pass over the roles to be removed.
12731268
*/
1274-
foreach(item,role_addresses)
1269+
foreach(item,role_oids)
12751270
{
1276-
ObjectAddress*role_address=lfirst(item);
1277-
Oidroleid=role_address->objectId;
1271+
Oidroleid=lfirst_oid(item);
12781272
HeapTupletuple;
12791273
Form_pg_authidroleform;
12801274
char*detail;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ DROP INDEX tenant_idx;
251251
DROP TABLE tenant_table;
252252
DROP VIEW tenant_view;
253253
DROP SCHEMA regress_tenant2_schema;
254-
DROP ROLE regress_tenant;
254+
-- check for duplicated drop
255+
DROP ROLE regress_tenant, regress_tenant;
255256
DROP ROLE regress_tenant2;
256257
DROP ROLE regress_rolecreator;
257258
DROP ROLE regress_role_admin;

‎src/test/regress/sql/create_role.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ DROP INDEX tenant_idx;
206206
DROPTABLE tenant_table;
207207
DROPVIEW tenant_view;
208208
DROPSCHEMA regress_tenant2_schema;
209-
DROP ROLE regress_tenant;
209+
-- check for duplicated drop
210+
DROP ROLE regress_tenant, regress_tenant;
210211
DROP ROLE regress_tenant2;
211212
DROP ROLE regress_rolecreator;
212213
DROP ROLE regress_role_admin;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp