Skip to content

Commit f3f6a14

Browse files
committed
Clean out column-level pg_init_privs entries when dropping tables.
DeleteInitPrivs did not get the memo about how, when dropping a whole object (with subid == 0), you should drop entries relating to its sub-objects too. This is visible in the test_pg_dump test case if one drops the extension at the end: the entry for GRANT SELECT(col1) ON regress_pg_dump_table TO public; was still present in pg_init_privs afterwards, although it was pointing to a dangling table OID. Noted while fooling with a fix for REASSIGN OWNED for pg_init_privs entries. This bug is aboriginal in the pg_init_privs feature though, and there seems no reason not to back-patch the fix.
1 parent 5912bf7 commit f3f6a14

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/backend/catalog/dependency.c

+15-6
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,9 @@ deleteOneObject(const ObjectAddress *object, Relation *depRel, int flags)
13781378
/*
13791379
* Delete any comments, security labels, or initial privileges associated
13801380
* with this object. (This is a convenient place to do these things,
1381-
* rather than having every object type know to do it.)
1381+
* rather than having every object type know to do it.) As above, all
1382+
* these functions must remove records for sub-objects too if the subid is
1383+
* zero.
13821384
*/
13831385
DeleteComments(object->objectId, object->classId, object->objectSubId);
13841386
DeleteSecurityLabel(object);
@@ -2909,6 +2911,7 @@ DeleteInitPrivs(const ObjectAddress *object)
29092911
{
29102912
Relation relation;
29112913
ScanKeyData key[3];
2914+
int nkeys;
29122915
SysScanDesc scan;
29132916
HeapTuple oldtuple;
29142917

@@ -2922,13 +2925,19 @@ DeleteInitPrivs(const ObjectAddress *object)
29222925
Anum_pg_init_privs_classoid,
29232926
BTEqualStrategyNumber, F_OIDEQ,
29242927
ObjectIdGetDatum(object->classId));
2925-
ScanKeyInit(&key[2],
2926-
Anum_pg_init_privs_objsubid,
2927-
BTEqualStrategyNumber, F_INT4EQ,
2928-
Int32GetDatum(object->objectSubId));
2928+
if (object->objectSubId != 0)
2929+
{
2930+
ScanKeyInit(&key[2],
2931+
Anum_pg_init_privs_objsubid,
2932+
BTEqualStrategyNumber, F_INT4EQ,
2933+
Int32GetDatum(object->objectSubId));
2934+
nkeys = 3;
2935+
}
2936+
else
2937+
nkeys = 2;
29292938

29302939
scan = systable_beginscan(relation, InitPrivsObjIndexId, true,
2931-
NULL, 3, key);
2940+
NULL, nkeys, key);
29322941

29332942
while (HeapTupleIsValid(oldtuple = systable_getnext(scan)))
29342943
CatalogTupleDelete(relation, &oldtuple->t_self);

src/test/modules/test_pg_dump/expected/test_pg_dump.out

+7
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,10 @@ ALTER EXTENSION test_pg_dump DROP SERVER s0;
9191
ALTER EXTENSION test_pg_dump DROP TABLE test_pg_dump_t1;
9292
ALTER EXTENSION test_pg_dump DROP TYPE test_pg_dump_e1;
9393
ALTER EXTENSION test_pg_dump DROP VIEW test_pg_dump_v1;
94+
DROP EXTENSION test_pg_dump;
95+
-- shouldn't be anything left in pg_init_privs
96+
SELECT * FROM pg_init_privs WHERE privtype = 'e';
97+
objoid | classoid | objsubid | privtype | initprivs
98+
--------+----------+----------+----------+-----------
99+
(0 rows)
100+

src/test/modules/test_pg_dump/sql/test_pg_dump.sql

+5
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,8 @@ ALTER EXTENSION test_pg_dump DROP SERVER s0;
106106
ALTER EXTENSION test_pg_dump DROP TABLE test_pg_dump_t1;
107107
ALTER EXTENSION test_pg_dump DROP TYPE test_pg_dump_e1;
108108
ALTER EXTENSION test_pg_dump DROP VIEW test_pg_dump_v1;
109+
110+
DROP EXTENSION test_pg_dump;
111+
112+
-- shouldn't be anything left in pg_init_privs
113+
SELECT * FROM pg_init_privs WHERE privtype = 'e';

0 commit comments

Comments
 (0)