Skip to content

Commit 5127fe6

Browse files
Antoine ViolinCommitfest Bot
authored andcommitted
Changed event_trigger for DEFAULT VALUE
1 parent 35baa60 commit 5127fe6

File tree

1 file changed

+80
-57
lines changed

1 file changed

+80
-57
lines changed

src/backend/commands/event_trigger.c

Lines changed: 80 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "catalog/dependency.h"
2222
#include "catalog/indexing.h"
2323
#include "catalog/objectaccess.h"
24+
#include "catalog/pg_attrdef.h"
2425
#include "catalog/pg_authid.h"
2526
#include "catalog/pg_auth_members.h"
2627
#include "catalog/pg_database.h"
@@ -1266,6 +1267,69 @@ trackDroppedObjectsNeeded(void)
12661267
* objects "reentrantly".
12671268
*/
12681269

1270+
static bool
1271+
process_catalog_object(Oid classId, Oid objectId, SQLDropObject *obj)
1272+
{
1273+
Relation catalog;
1274+
HeapTuple tuple;
1275+
1276+
catalog = table_open(classId, AccessShareLock);
1277+
tuple = get_catalog_object_by_oid(catalog,
1278+
get_object_attnum_oid(classId),
1279+
objectId);
1280+
1281+
if (tuple)
1282+
{
1283+
AttrNumber attnum;
1284+
Datum datum;
1285+
bool isnull;
1286+
1287+
attnum = get_object_attnum_namespace(classId);
1288+
if (attnum != InvalidAttrNumber)
1289+
{
1290+
datum = heap_getattr(tuple, attnum,
1291+
RelationGetDescr(catalog), &isnull);
1292+
if (!isnull)
1293+
{
1294+
Oid namespaceId;
1295+
1296+
namespaceId = DatumGetObjectId(datum);
1297+
/* temp objects are only reported if they are my own */
1298+
if (isTempNamespace(namespaceId))
1299+
{
1300+
obj->schemaname = "pg_temp";
1301+
obj->istemp = true;
1302+
}
1303+
else if (isAnyTempNamespace(namespaceId))
1304+
{
1305+
table_close(catalog, AccessShareLock);
1306+
return false;
1307+
}
1308+
else
1309+
{
1310+
obj->schemaname = get_namespace_name(namespaceId);
1311+
obj->istemp = false;
1312+
}
1313+
}
1314+
}
1315+
1316+
if (get_object_namensp_unique(classId) &&
1317+
obj->address.objectSubId == 0)
1318+
{
1319+
attnum = get_object_attnum_name(classId);
1320+
if (attnum != InvalidAttrNumber)
1321+
{
1322+
datum = heap_getattr(tuple, attnum,
1323+
RelationGetDescr(catalog), &isnull);
1324+
if (!isnull)
1325+
obj->objname = pstrdup(NameStr(*DatumGetName(datum)));
1326+
}
1327+
}
1328+
}
1329+
1330+
table_close(catalog, AccessShareLock);
1331+
return true;
1332+
}
12691333
/*
12701334
* Register one object as being dropped by the current command.
12711335
*/
@@ -1292,7 +1356,6 @@ EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool no
12921356
obj->address = *object;
12931357
obj->original = original;
12941358
obj->normal = normal;
1295-
12961359
/*
12971360
* Obtain schema names from the object's catalog tuple, if one exists;
12981361
* this lets us skip objects in temp schemas. We trust that
@@ -1301,66 +1364,26 @@ EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool no
13011364
*/
13021365
if (is_objectclass_supported(object->classId))
13031366
{
1304-
Relation catalog;
1305-
HeapTuple tuple;
1306-
1307-
catalog = table_open(obj->address.classId, AccessShareLock);
1308-
tuple = get_catalog_object_by_oid(catalog,
1309-
get_object_attnum_oid(object->classId),
1310-
obj->address.objectId);
1311-
1312-
if (tuple)
1367+
if (!process_catalog_object(object->classId, object->objectId, obj))
13131368
{
1314-
AttrNumber attnum;
1315-
Datum datum;
1316-
bool isnull;
1317-
1318-
attnum = get_object_attnum_namespace(obj->address.classId);
1319-
if (attnum != InvalidAttrNumber)
1320-
{
1321-
datum = heap_getattr(tuple, attnum,
1322-
RelationGetDescr(catalog), &isnull);
1323-
if (!isnull)
1324-
{
1325-
Oid namespaceId;
1326-
1327-
namespaceId = DatumGetObjectId(datum);
1328-
/* temp objects are only reported if they are my own */
1329-
if (isTempNamespace(namespaceId))
1330-
{
1331-
obj->schemaname = "pg_temp";
1332-
obj->istemp = true;
1333-
}
1334-
else if (isAnyTempNamespace(namespaceId))
1335-
{
1336-
pfree(obj);
1337-
table_close(catalog, AccessShareLock);
1338-
MemoryContextSwitchTo(oldcxt);
1339-
return;
1340-
}
1341-
else
1342-
{
1343-
obj->schemaname = get_namespace_name(namespaceId);
1344-
obj->istemp = false;
1345-
}
1346-
}
1347-
}
1348-
1349-
if (get_object_namensp_unique(obj->address.classId) &&
1350-
obj->address.objectSubId == 0)
1369+
pfree(obj);
1370+
MemoryContextSwitchTo(oldcxt);
1371+
return;
1372+
}
1373+
}
1374+
else if (object->classId == AttrDefaultRelationId)
1375+
{
1376+
ObjectAddress relAddress;
1377+
relAddress = GetAttrDefaultColumnAddress(object->objectId);
1378+
if (OidIsValid(relAddress.objectId))
1379+
{
1380+
if(!process_catalog_object(relAddress.classId, relAddress.objectId, obj))
13511381
{
1352-
attnum = get_object_attnum_name(obj->address.classId);
1353-
if (attnum != InvalidAttrNumber)
1354-
{
1355-
datum = heap_getattr(tuple, attnum,
1356-
RelationGetDescr(catalog), &isnull);
1357-
if (!isnull)
1358-
obj->objname = pstrdup(NameStr(*DatumGetName(datum)));
1359-
}
1382+
pfree(obj);
1383+
MemoryContextSwitchTo(oldcxt);
1384+
return;
13601385
}
13611386
}
1362-
1363-
table_close(catalog, AccessShareLock);
13641387
}
13651388
else
13661389
{

0 commit comments

Comments
 (0)