Обсуждение: pgsql: Fix DROP ROLE when specifying duplicated roles

Поиск
Список
Период
Сортировка

pgsql: Fix DROP ROLE when specifying duplicated roles

От
Michael Paquier
Дата:
Fix DROP ROLE when specifying duplicated roles

This commit fixes failures with "tuple already updated by self" when
listing twice the same role and in a DROP ROLE query.

This is an oversight in 6566133c5f52, that has introduced a two-phase
logic in DropRole() where dependencies of all the roles to drop are
removed in a first phase, with the roles themselves removed from
pg_authid in a second phase.

The code is simplified to not rely on a List of ObjectAddress built in
the first phase used to remove the pg_authid entries in the second
phase, switching to a list of OIDs.  Duplicated OIDs can be simply
avoided in the first phase thanks to that.  Using ObjectAddress was not
necessary for the roles as they are not used for anything specific to
dependency.c, building all the ObjectAddress in the List with
AuthIdRelationId as class ID.

In 15 and older versions, where a single phase is used, DROP ROLE with
duplicated role names would fail on "role \"blah\" does not exist" for
the second entry after the CCI() done by the first deletion.  This is
not really incorrect, but it does not seem worth changing based on a
lack of complaints.

Reported-by: Alexander Lakhin
Reviewed-by: Tender Wang
Discussion: https://postgr.es/m/18310-1eb233c5908189c8@postgresql.org
Backpatch-through: 16

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/f57a580fd280fd1057f9526ca98d63f4805fa17b

Modified Files
--------------
src/backend/commands/user.c               | 16 +++++-----------
src/test/regress/expected/create_role.out |  3 ++-
src/test/regress/sql/create_role.sql      |  3 ++-
3 files changed, 9 insertions(+), 13 deletions(-)