🌐 AI搜索 & 代理 主页
Skip to content

Commit ef81db9

Browse files
committed
Fix oversights in pg_event_trigger_dropped_objects() fixes.
Commit a0b99fc caused pg_event_trigger_dropped_objects() to not fill the object_name field for schemas, which it should have; and caused it to fill the object_name field for default values, which it should not have. In addition, triggers and RLS policies really should behave the same way as we're making column defaults do; that is, they should have is_temporary = true if they belong to a temporary table. Fix those things, and upgrade event_trigger.sql's woefully inadequate test coverage of these secondary output columns. As before, back-patch only to v15. Reported-by: Sergey Shinderuk <s.shinderuk@postgrespro.ru> Author: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/bd7b4651-1c26-4d30-832b-f942fabcb145@postgrespro.ru Backpatch-through: 15
1 parent e457312 commit ef81db9

File tree

3 files changed

+244
-86
lines changed

3 files changed

+244
-86
lines changed

src/backend/commands/event_trigger.c

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "catalog/pg_opclass.h"
3131
#include "catalog/pg_opfamily.h"
3232
#include "catalog/pg_parameter_acl.h"
33+
#include "catalog/pg_policy.h"
3334
#include "catalog/pg_proc.h"
3435
#include "catalog/pg_tablespace.h"
3536
#include "catalog/pg_trigger.h"
@@ -1302,6 +1303,7 @@ EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool no
13021303
MemoryContextSwitchTo(oldcxt);
13031304
return;
13041305
}
1306+
obj->objname = get_namespace_name(object->objectId);
13051307
}
13061308
else if (object->classId == AttrDefaultRelationId)
13071309
{
@@ -1311,7 +1313,6 @@ EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool no
13111313
colobject = GetAttrDefaultColumnAddress(object->objectId);
13121314
if (OidIsValid(colobject.objectId))
13131315
{
1314-
colobject.objectSubId = 0; /* convert to table reference */
13151316
if (!obtain_object_name_namespace(&colobject, obj))
13161317
{
13171318
pfree(obj);
@@ -1320,6 +1321,90 @@ EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool no
13201321
}
13211322
}
13221323
}
1324+
else if (object->classId == TriggerRelationId)
1325+
{
1326+
/* Similarly, a trigger is temp if its table is temp */
1327+
/* Sadly, there's no lsyscache.c support for trigger objects */
1328+
Relation pg_trigger_rel;
1329+
ScanKeyData skey[1];
1330+
SysScanDesc sscan;
1331+
HeapTuple tuple;
1332+
Oid relid;
1333+
1334+
/* Fetch the trigger's table OID the hard way */
1335+
pg_trigger_rel = table_open(TriggerRelationId, AccessShareLock);
1336+
ScanKeyInit(&skey[0],
1337+
Anum_pg_trigger_oid,
1338+
BTEqualStrategyNumber, F_OIDEQ,
1339+
ObjectIdGetDatum(object->objectId));
1340+
sscan = systable_beginscan(pg_trigger_rel, TriggerOidIndexId, true,
1341+
NULL, 1, skey);
1342+
tuple = systable_getnext(sscan);
1343+
if (HeapTupleIsValid(tuple))
1344+
relid = ((Form_pg_trigger) GETSTRUCT(tuple))->tgrelid;
1345+
else
1346+
relid = InvalidOid; /* shouldn't happen */
1347+
systable_endscan(sscan);
1348+
table_close(pg_trigger_rel, AccessShareLock);
1349+
/* Do nothing if we didn't find the trigger */
1350+
if (OidIsValid(relid))
1351+
{
1352+
ObjectAddress relobject;
1353+
1354+
relobject.classId = RelationRelationId;
1355+
relobject.objectId = relid;
1356+
/* Arbitrarily set objectSubId nonzero so as not to fill objname */
1357+
relobject.objectSubId = 1;
1358+
if (!obtain_object_name_namespace(&relobject, obj))
1359+
{
1360+
pfree(obj);
1361+
MemoryContextSwitchTo(oldcxt);
1362+
return;
1363+
}
1364+
}
1365+
}
1366+
else if (object->classId == PolicyRelationId)
1367+
{
1368+
/* Similarly, a policy is temp if its table is temp */
1369+
/* Sadly, there's no lsyscache.c support for policy objects */
1370+
Relation pg_policy_rel;
1371+
ScanKeyData skey[1];
1372+
SysScanDesc sscan;
1373+
HeapTuple tuple;
1374+
Oid relid;
1375+
1376+
/* Fetch the policy's table OID the hard way */
1377+
pg_policy_rel = table_open(PolicyRelationId, AccessShareLock);
1378+
ScanKeyInit(&skey[0],
1379+
Anum_pg_policy_oid,
1380+
BTEqualStrategyNumber, F_OIDEQ,
1381+
ObjectIdGetDatum(object->objectId));
1382+
sscan = systable_beginscan(pg_policy_rel, PolicyOidIndexId, true,
1383+
NULL, 1, skey);
1384+
tuple = systable_getnext(sscan);
1385+
if (HeapTupleIsValid(tuple))
1386+
relid = ((Form_pg_policy) GETSTRUCT(tuple))->polrelid;
1387+
else
1388+
relid = InvalidOid; /* shouldn't happen */
1389+
systable_endscan(sscan);
1390+
table_close(pg_policy_rel, AccessShareLock);
1391+
/* Do nothing if we didn't find the policy */
1392+
if (OidIsValid(relid))
1393+
{
1394+
ObjectAddress relobject;
1395+
1396+
relobject.classId = RelationRelationId;
1397+
relobject.objectId = relid;
1398+
/* Arbitrarily set objectSubId nonzero so as not to fill objname */
1399+
relobject.objectSubId = 1;
1400+
if (!obtain_object_name_namespace(&relobject, obj))
1401+
{
1402+
pfree(obj);
1403+
MemoryContextSwitchTo(oldcxt);
1404+
return;
1405+
}
1406+
}
1407+
}
13231408
else
13241409
{
13251410
/* Generic handling for all other object classes */

0 commit comments

Comments
 (0)