> Hi everyone, > I found one bug, when you delete temporary table with DEFAULT VALUE. The > row about this VALUE in the pg_event_trigger_dropped_objects() contains > “False” in the column “is_temporary”. But if you look at column “name_obj”, > you see “for pg_temp.table_name”. So PostgreSQL know, that it is temporary. > > Cheers > > Antoine Violin\ > Hi everyone, I made patch for this problem, I changed event_trigger, for definitions of temporality DEFAULT VALUE
Cheers Antoine Violin
From aefa629be36f74b3067317ed67874f6eeeeafc73 Mon Sep 17 00:00:00 2001 From: Antoine Violin <a.vio...@postgrespro.ru> Date: Mon, 30 Jun 2025 10:20:52 +0700 Subject: [PATCH] Changed event_trigger for DEFAULT VALUE --- src/backend/commands/event_trigger.c | 137 ++++++++++++++++----------- 1 file changed, 80 insertions(+), 57 deletions(-) diff --git a/src/backend/commands/event_trigger.c b/src/backend/commands/event_trigger.c index 31b2f51b589..e3aa1d36c26 100644 --- a/src/backend/commands/event_trigger.c +++ b/src/backend/commands/event_trigger.c @@ -21,6 +21,7 @@ #include "catalog/dependency.h" #include "catalog/indexing.h" #include "catalog/objectaccess.h" +#include "catalog/pg_attrdef.h" #include "catalog/pg_authid.h" #include "catalog/pg_auth_members.h" #include "catalog/pg_database.h" @@ -1276,6 +1277,69 @@ trackDroppedObjectsNeeded(void) * objects "reentrantly". */ +static bool +process_catalog_object(Oid classId, Oid objectId, SQLDropObject *obj) +{ + Relation catalog; + HeapTuple tuple; + + catalog = table_open(classId, AccessShareLock); + tuple = get_catalog_object_by_oid(catalog, + get_object_attnum_oid(classId), + objectId); + + if (tuple) + { + AttrNumber attnum; + Datum datum; + bool isnull; + + attnum = get_object_attnum_namespace(classId); + if (attnum != InvalidAttrNumber) + { + datum = heap_getattr(tuple, attnum, + RelationGetDescr(catalog), &isnull); + if (!isnull) + { + Oid namespaceId; + + namespaceId = DatumGetObjectId(datum); + /* temp objects are only reported if they are my own */ + if (isTempNamespace(namespaceId)) + { + obj->schemaname = "pg_temp"; + obj->istemp = true; + } + else if (isAnyTempNamespace(namespaceId)) + { + table_close(catalog, AccessShareLock); + return false; + } + else + { + obj->schemaname = get_namespace_name(namespaceId); + obj->istemp = false; + } + } + } + + if (get_object_namensp_unique(classId) && + obj->address.objectSubId == 0) + { + attnum = get_object_attnum_name(classId); + if (attnum != InvalidAttrNumber) + { + datum = heap_getattr(tuple, attnum, + RelationGetDescr(catalog), &isnull); + if (!isnull) + obj->objname = pstrdup(NameStr(*DatumGetName(datum))); + } + } + } + + table_close(catalog, AccessShareLock); + return true; +} /* * Register one object as being dropped by the current command. */ @@ -1302,7 +1366,6 @@ EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool no obj->address = *object; obj->original = original; obj->normal = normal; - /* * Obtain schema names from the object's catalog tuple, if one exists; * this lets us skip objects in temp schemas. We trust that @@ -1311,66 +1374,26 @@ EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool no */ if (is_objectclass_supported(object->classId)) { - Relation catalog; - HeapTuple tuple; - - catalog = table_open(obj->address.classId, AccessShareLock); - tuple = get_catalog_object_by_oid(catalog, - get_object_attnum_oid(object->classId), - obj->address.objectId); - - if (tuple) + if (!process_catalog_object(object->classId, object->objectId, obj)) { - AttrNumber attnum; - Datum datum; - bool isnull; - - attnum = get_object_attnum_namespace(obj->address.classId); - if (attnum != InvalidAttrNumber) - { - datum = heap_getattr(tuple, attnum, - RelationGetDescr(catalog), &isnull); - if (!isnull) - { - Oid namespaceId; - - namespaceId = DatumGetObjectId(datum); - /* temp objects are only reported if they are my own */ - if (isTempNamespace(namespaceId)) - { - obj->schemaname = "pg_temp"; - obj->istemp = true; - } - else if (isAnyTempNamespace(namespaceId)) - { - pfree(obj); - table_close(catalog, AccessShareLock); - MemoryContextSwitchTo(oldcxt); - return; - } - else - { - obj->schemaname = get_namespace_name(namespaceId); - obj->istemp = false; - } - } - } - - if (get_object_namensp_unique(obj->address.classId) && - obj->address.objectSubId == 0) + pfree(obj); + MemoryContextSwitchTo(oldcxt); + return; + } + } + else if (object->classId == AttrDefaultRelationId) + { + ObjectAddress relAddress; + relAddress = GetAttrDefaultColumnAddress(object->objectId); + if (OidIsValid(relAddress.objectId)) + { + if(!process_catalog_object(relAddress.classId, relAddress.objectId, obj)) { - attnum = get_object_attnum_name(obj->address.classId); - if (attnum != InvalidAttrNumber) - { - datum = heap_getattr(tuple, attnum, - RelationGetDescr(catalog), &isnull); - if (!isnull) - obj->objname = pstrdup(NameStr(*DatumGetName(datum))); - } + pfree(obj); + MemoryContextSwitchTo(oldcxt); + return; } } - - table_close(catalog, AccessShareLock); } else { -- 2.43.0