<entry><type>int32</type></entry>
<entry>Object sub-id (e.g. attribute number for columns)</entry>
</row>
+ <row>
+ <entry><literal>original</literal></entry>
+ <entry><type>bool</type></entry>
+ <entry>Flag used to identify the root object(s) of the deletion</entry>
+ </row>
+ <row>
+ <entry><literal>normal</literal></entry>
+ <entry><type>bool</type></entry>
+ <entry>
+ Flag indicating that there's a normal dependency relationship
+ in the dependency graph leading to this object
+ </entry>
+ </row>
<row>
<entry><literal>object_type</literal></entry>
<entry><type>text</type></entry>
/*
* Keep track of objects for event triggers, if necessary.
*/
- if (trackDroppedObjectsNeeded())
+ if (trackDroppedObjectsNeeded() && !(flags & PERFORM_DELETION_INTERNAL))
{
for (i = 0; i < targetObjects->numrefs; i++)
{
- ObjectAddress *thisobj = targetObjects->refs + i;
-
- if ((!(flags & PERFORM_DELETION_INTERNAL)) &&
- EventTriggerSupportsObjectClass(getObjectClass(thisobj)))
+ const ObjectAddress *thisobj = &targetObjects->refs[i];
+ const ObjectAddressExtra *extra = &targetObjects->extras[i];
+ bool original = false;
+ bool normal = false;
+
+ if (extra->flags & DEPFLAG_ORIGINAL)
+ original = true;
+ if (extra->flags & DEPFLAG_NORMAL)
+ normal = true;
+ if (extra->flags & DEPFLAG_REVERSE)
+ normal = true;
+
+ if (EventTriggerSupportsObjectClass(getObjectClass(thisobj)))
{
- EventTriggerSQLDropAddObject(thisobj);
+ EventTriggerSQLDropAddObject(thisobj, original, normal);
}
}
}
const char *objname;
const char *objidentity;
const char *objecttype;
+ bool original;
+ bool normal;
slist_node next;
} SQLDropObject;
* Register one object as being dropped by the current command.
*/
void
-EventTriggerSQLDropAddObject(ObjectAddress *object)
+EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool normal)
{
SQLDropObject *obj;
MemoryContext oldcxt;
obj = palloc0(sizeof(SQLDropObject));
obj->address = *object;
+ obj->original = original;
+ obj->normal = normal;
/*
* Obtain schema names from the object's catalog tuple, if one exists;
{
SQLDropObject *obj;
int i = 0;
- Datum values[7];
- bool nulls[7];
+ Datum values[9];
+ bool nulls[9];
obj = slist_container(SQLDropObject, next, iter.cur);
/* objsubid */
values[i++] = Int32GetDatum(obj->address.objectSubId);
+ /* original */
+ values[i++] = BoolGetDatum(obj->original);
+
+ /* normal */
+ values[i++] = BoolGetDatum(obj->normal);
+
/* object_type */
values[i++] = CStringGetTextDatum(obj->objecttype);
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 201412122
+#define CATALOG_VERSION_NO 201412191
#endif
DESCR("peek at binary changes from replication slot");
/* event triggers */
-DATA(insert OID = 3566 ( pg_event_trigger_dropped_objects PGNSP PGUID 12 10 100 0 0 f f f f t t s 0 0 2249 "" "{26,26,23,25,25,25,25}" "{o,o,o,o,o,o,o}" "{classid, objid, objsubid, object_type, schema_name, object_name, object_identity}" _null_ pg_event_trigger_dropped_objects _null_ _null_ _null_ ));
+DATA(insert OID = 3566 ( pg_event_trigger_dropped_objects PGNSP PGUID 12 10 100 0 0 f f f f t t s 0 0 2249 "" "{26,26,23,16,16,25,25,25,25}" "{o,o,o,o,o,o,o,o,o}" "{classid, objid, objsubid, original, normal, object_type, schema_name, object_name, object_identity}" _null_ pg_event_trigger_dropped_objects _null_ _null_ _null_ ));
DESCR("list objects dropped by the current command");
DATA(insert OID = 4566 ( pg_event_trigger_table_rewrite_oid PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 26 "" "{26}" "{o}" "{oid}" _null_ pg_event_trigger_table_rewrite_oid _null_ _null_ _null_ ));
DESCR("return Oid of the table getting rewritten");
extern bool EventTriggerBeginCompleteQuery(void);
extern void EventTriggerEndCompleteQuery(void);
extern bool trackDroppedObjectsNeeded(void);
-extern void EventTriggerSQLDropAddObject(ObjectAddress *object);
+extern void EventTriggerSQLDropAddObject(const ObjectAddress *object,
+ bool original, bool normal);
#endif /* EVENT_TRIGGER_H */
DROP ROLE regression_bob;
DROP EVENT TRIGGER regress_event_trigger_drop_objects;
DROP EVENT TRIGGER undroppable;
+CREATE OR REPLACE FUNCTION event_trigger_report_dropped()
+ RETURNS event_trigger
+ LANGUAGE plpgsql
+AS $$
+DECLARE r record;
+BEGIN
+ FOR r IN SELECT * from pg_event_trigger_dropped_objects()
+ LOOP
+ IF NOT r.normal AND NOT r.original THEN
+ CONTINUE;
+ END IF;
+ RAISE NOTICE 'NORMAL: orig=% normal=% type=% identity=%',
+ r.original, r.normal, r.object_type, r.object_identity;
+ END LOOP;
+END; $$;
+CREATE EVENT TRIGGER regress_event_trigger_report_dropped ON sql_drop
+ EXECUTE PROCEDURE event_trigger_report_dropped();
+CREATE SCHEMA evttrig
+ CREATE TABLE one (col_a SERIAL PRIMARY KEY, col_b text DEFAULT 'forty two')
+ CREATE INDEX one_idx ON one (col_b)
+ CREATE TABLE two (col_c INTEGER CHECK (col_c > 0) REFERENCES one DEFAULT 42);
+ALTER TABLE evttrig.two DROP COLUMN col_c;
+NOTICE: NORMAL: orig=t normal=f type=table column identity=evttrig.two.col_c
+NOTICE: NORMAL: orig=f normal=t type=table constraint identity=two_col_c_check on evttrig.two
+ALTER TABLE evttrig.one ALTER COLUMN col_b DROP DEFAULT;
+NOTICE: NORMAL: orig=t normal=f type=default value identity=for evttrig.one.col_b
+ALTER TABLE evttrig.one DROP CONSTRAINT one_pkey;
+NOTICE: NORMAL: orig=t normal=f type=table constraint identity=one_pkey on evttrig.one
+DROP INDEX evttrig.one_idx;
+NOTICE: NORMAL: orig=t normal=f type=index identity=evttrig.one_idx
+DROP SCHEMA evttrig CASCADE;
+NOTICE: drop cascades to 2 other objects
+DETAIL: drop cascades to table evttrig.one
+drop cascades to table evttrig.two
+NOTICE: NORMAL: orig=t normal=f type=schema identity=evttrig
+NOTICE: NORMAL: orig=f normal=t type=table identity=evttrig.one
+NOTICE: NORMAL: orig=f normal=t type=sequence identity=evttrig.one_col_a_seq
+NOTICE: NORMAL: orig=f normal=t type=default value identity=for evttrig.one.col_a
+NOTICE: NORMAL: orig=f normal=t type=table identity=evttrig.two
+DROP EVENT TRIGGER regress_event_trigger_report_dropped;
-- only allowed from within an event trigger function, should fail
select pg_event_trigger_table_rewrite_oid();
ERROR: pg_event_trigger_table_rewrite_oid() can only be called in a table_rewrite event trigger function
DROP EVENT TRIGGER regress_event_trigger_drop_objects;
DROP EVENT TRIGGER undroppable;
+CREATE OR REPLACE FUNCTION event_trigger_report_dropped()
+ RETURNS event_trigger
+ LANGUAGE plpgsql
+AS $$
+DECLARE r record;
+BEGIN
+ FOR r IN SELECT * from pg_event_trigger_dropped_objects()
+ LOOP
+ IF NOT r.normal AND NOT r.original THEN
+ CONTINUE;
+ END IF;
+ RAISE NOTICE 'NORMAL: orig=% normal=% type=% identity=%',
+ r.original, r.normal, r.object_type, r.object_identity;
+ END LOOP;
+END; $$;
+CREATE EVENT TRIGGER regress_event_trigger_report_dropped ON sql_drop
+ EXECUTE PROCEDURE event_trigger_report_dropped();
+CREATE SCHEMA evttrig
+ CREATE TABLE one (col_a SERIAL PRIMARY KEY, col_b text DEFAULT 'forty two')
+ CREATE INDEX one_idx ON one (col_b)
+ CREATE TABLE two (col_c INTEGER CHECK (col_c > 0) REFERENCES one DEFAULT 42);
+
+ALTER TABLE evttrig.two DROP COLUMN col_c;
+ALTER TABLE evttrig.one ALTER COLUMN col_b DROP DEFAULT;
+ALTER TABLE evttrig.one DROP CONSTRAINT one_pkey;
+DROP INDEX evttrig.one_idx;
+DROP SCHEMA evttrig CASCADE;
+
+DROP EVENT TRIGGER regress_event_trigger_report_dropped;
+
-- only allowed from within an event trigger function, should fail
select pg_event_trigger_table_rewrite_oid();