Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7661809

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 01aa88f commit 7661809

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
@@ -1326,7 +1326,9 @@ deleteOneObject(const ObjectAddress *object, Relation *depRel, int flags)
13261326
/*
13271327
* Delete any comments, security labels, or initial privileges associated
13281328
* with this object. (This is a convenient place to do these things,
1329-
* rather than having every object type know to do it.)
1329+
* rather than having every object type know to do it.) As above, all
1330+
* these functions must remove records for sub-objects too if the subid is
1331+
* zero.
13301332
*/
13311333
DeleteComments(object->objectId, object->classId, object->objectSubId);
13321334
DeleteSecurityLabel(object);
@@ -2784,6 +2786,7 @@ DeleteInitPrivs(const ObjectAddress *object)
27842786
{
27852787
Relation relation;
27862788
ScanKeyData key[3];
2789+
int nkeys;
27872790
SysScanDesc scan;
27882791
HeapTuple oldtuple;
27892792

@@ -2797,13 +2800,19 @@ DeleteInitPrivs(const ObjectAddress *object)
27972800
Anum_pg_init_privs_classoid,
27982801
BTEqualStrategyNumber, F_OIDEQ,
27992802
ObjectIdGetDatum(object->classId));
2800-
ScanKeyInit(&key[2],
2801-
Anum_pg_init_privs_objsubid,
2802-
BTEqualStrategyNumber, F_INT4EQ,
2803-
Int32GetDatum(object->objectSubId));
2803+
if (object->objectSubId != 0)
2804+
{
2805+
ScanKeyInit(&key[2],
2806+
Anum_pg_init_privs_objsubid,
2807+
BTEqualStrategyNumber, F_INT4EQ,
2808+
Int32GetDatum(object->objectSubId));
2809+
nkeys = 3;
2810+
}
2811+
else
2812+
nkeys = 2;
28042813

28052814
scan = systable_beginscan(relation, InitPrivsObjIndexId, true,
2806-
NULL, 3, key);
2815+
NULL, nkeys, key);
28072816

28082817
while (HeapTupleIsValid(oldtuple = systable_getnext(scan)))
28092818
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
@@ -276,3 +276,10 @@ SELECT pg_describe_object(classid,objid,objsubid) COLLATE "C" AS obj,
276276
(0 rows)
277277

278278
DROP ROLE regress_dump_test_role;
279+
DROP EXTENSION test_pg_dump;
280+
-- shouldn't be anything left in pg_init_privs
281+
SELECT * FROM pg_init_privs WHERE privtype = 'e';
282+
objoid | classoid | objsubid | privtype | initprivs
283+
--------+----------+----------+----------+-----------
284+
(0 rows)
285+

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

+5
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,8 @@ SELECT pg_describe_object(classid,objid,objsubid) COLLATE "C" AS obj,
146146
ORDER BY 1, 3;
147147

148148
DROP ROLE regress_dump_test_role;
149+
150+
DROP EXTENSION test_pg_dump;
151+
152+
-- shouldn't be anything left in pg_init_privs
153+
SELECT * FROM pg_init_privs WHERE privtype = 'e';

0 commit comments

Comments
 (0)