Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0ee98d1

Browse files
committed
pg_event_trigger_dropped_objects: add behavior flags
Add "normal" and "original" flags as output columns to thepg_event_trigger_dropped_objects() function. With this it's possible todistinguish which objects, among those listed, need to be explicitelyreferenced when trying to replicate a deletion.This is necessary so that the list of objects can be pruned to theminimum necessary to replicate the DROP command in a remote server thatmight have slightly different schema (for instance, TOAST tables andconstraints with different names and such.)Catalog version bumped due to change of function definition.Reviewed by: Abhijit Menon-Sen, Stephen Frost, Heikki Linnakangas,Robert Haas.
1 parent5c805d0 commit0ee98d1

File tree

8 files changed

+115
-12
lines changed

8 files changed

+115
-12
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17729,6 +17729,19 @@ FOR EACH ROW EXECUTE PROCEDURE suppress_redundant_updates_trigger();
1772917729
<entry><type>int32</type></entry>
1773017730
<entry>Object sub-id (e.g. attribute number for columns)</entry>
1773117731
</row>
17732+
<row>
17733+
<entry><literal>original</literal></entry>
17734+
<entry><type>bool</type></entry>
17735+
<entry>Flag used to identify the root object(s) of the deletion</entry>
17736+
</row>
17737+
<row>
17738+
<entry><literal>normal</literal></entry>
17739+
<entry><type>bool</type></entry>
17740+
<entry>
17741+
Flag indicating that there's a normal dependency relationship
17742+
in the dependency graph leading to this object
17743+
</entry>
17744+
</row>
1773217745
<row>
1773317746
<entry><literal>object_type</literal></entry>
1773417747
<entry><type>text</type></entry>

‎src/backend/catalog/dependency.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,25 @@ deleteObjectsInList(ObjectAddresses *targetObjects, Relation *depRel,
206206
/*
207207
* Keep track of objects for event triggers, if necessary.
208208
*/
209-
if (trackDroppedObjectsNeeded())
209+
if (trackDroppedObjectsNeeded()&& !(flags&PERFORM_DELETION_INTERNAL))
210210
{
211211
for (i=0;i<targetObjects->numrefs;i++)
212212
{
213-
ObjectAddress*thisobj=targetObjects->refs+i;
214-
215-
if ((!(flags&PERFORM_DELETION_INTERNAL))&&
216-
EventTriggerSupportsObjectClass(getObjectClass(thisobj)))
213+
constObjectAddress*thisobj=&targetObjects->refs[i];
214+
constObjectAddressExtra*extra=&targetObjects->extras[i];
215+
booloriginal= false;
216+
boolnormal= false;
217+
218+
if (extra->flags&DEPFLAG_ORIGINAL)
219+
original= true;
220+
if (extra->flags&DEPFLAG_NORMAL)
221+
normal= true;
222+
if (extra->flags&DEPFLAG_REVERSE)
223+
normal= true;
224+
225+
if (EventTriggerSupportsObjectClass(getObjectClass(thisobj)))
217226
{
218-
EventTriggerSQLDropAddObject(thisobj);
227+
EventTriggerSQLDropAddObject(thisobj,original,normal);
219228
}
220229
}
221230
}

‎src/backend/commands/event_trigger.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ typedef struct SQLDropObject
117117
constchar*objname;
118118
constchar*objidentity;
119119
constchar*objecttype;
120+
booloriginal;
121+
boolnormal;
120122
slist_nodenext;
121123
}SQLDropObject;
122124

@@ -1238,7 +1240,7 @@ trackDroppedObjectsNeeded(void)
12381240
* Register one object as being dropped by the current command.
12391241
*/
12401242
void
1241-
EventTriggerSQLDropAddObject(ObjectAddress*object)
1243+
EventTriggerSQLDropAddObject(constObjectAddress*object,booloriginal,boolnormal)
12421244
{
12431245
SQLDropObject*obj;
12441246
MemoryContextoldcxt;
@@ -1257,6 +1259,8 @@ EventTriggerSQLDropAddObject(ObjectAddress *object)
12571259

12581260
obj=palloc0(sizeof(SQLDropObject));
12591261
obj->address=*object;
1262+
obj->original=original;
1263+
obj->normal=normal;
12601264

12611265
/*
12621266
* Obtain schema names from the object's catalog tuple, if one exists;
@@ -1384,8 +1388,8 @@ pg_event_trigger_dropped_objects(PG_FUNCTION_ARGS)
13841388
{
13851389
SQLDropObject*obj;
13861390
inti=0;
1387-
Datumvalues[7];
1388-
boolnulls[7];
1391+
Datumvalues[9];
1392+
boolnulls[9];
13891393

13901394
obj=slist_container(SQLDropObject,next,iter.cur);
13911395

@@ -1401,6 +1405,12 @@ pg_event_trigger_dropped_objects(PG_FUNCTION_ARGS)
14011405
/* objsubid */
14021406
values[i++]=Int32GetDatum(obj->address.objectSubId);
14031407

1408+
/* original */
1409+
values[i++]=BoolGetDatum(obj->original);
1410+
1411+
/* normal */
1412+
values[i++]=BoolGetDatum(obj->normal);
1413+
14041414
/* object_type */
14051415
values[i++]=CStringGetTextDatum(obj->objecttype);
14061416

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO201412122
56+
#defineCATALOG_VERSION_NO201412191
5757

5858
#endif

‎src/include/catalog/pg_proc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5075,7 +5075,7 @@ DATA(insert OID = 3785 ( pg_logical_slot_peek_binary_changes PGNSP PGUID 12 100
50755075
DESCR("peek at binary changes from replication slot");
50765076

50775077
/* event triggers */
5078-
DATA(insert OID = 3566 ( pg_event_trigger_dropped_objectsPGNSP 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_ ));
5078+
DATA(insert OID = 3566 ( pg_event_trigger_dropped_objectsPGNSP 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_ ));
50795079
DESCR("list objects dropped by the current command");
50805080
DATA(insert OID = 4566 ( pg_event_trigger_table_rewrite_oidPGNSP 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_ ));
50815081
DESCR("return Oid of the table getting rewritten");

‎src/include/commands/event_trigger.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ extern void EventTriggerTableRewrite(Node *parsetree, Oid tableOid, int reason);
5656
externboolEventTriggerBeginCompleteQuery(void);
5757
externvoidEventTriggerEndCompleteQuery(void);
5858
externbooltrackDroppedObjectsNeeded(void);
59-
externvoidEventTriggerSQLDropAddObject(ObjectAddress*object);
59+
externvoidEventTriggerSQLDropAddObject(constObjectAddress*object,
60+
booloriginal,boolnormal);
6061

6162
#endif/* EVENT_TRIGGER_H */

‎src/test/regress/expected/event_trigger.out

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,46 @@ SELECT * FROM dropped_objects WHERE type = 'schema';
294294
DROP ROLE regression_bob;
295295
DROP EVENT TRIGGER regress_event_trigger_drop_objects;
296296
DROP EVENT TRIGGER undroppable;
297+
CREATE OR REPLACE FUNCTION event_trigger_report_dropped()
298+
RETURNS event_trigger
299+
LANGUAGE plpgsql
300+
AS $$
301+
DECLARE r record;
302+
BEGIN
303+
FOR r IN SELECT * from pg_event_trigger_dropped_objects()
304+
LOOP
305+
IF NOT r.normal AND NOT r.original THEN
306+
CONTINUE;
307+
END IF;
308+
RAISE NOTICE 'NORMAL: orig=% normal=% type=% identity=%',
309+
r.original, r.normal, r.object_type, r.object_identity;
310+
END LOOP;
311+
END; $$;
312+
CREATE EVENT TRIGGER regress_event_trigger_report_dropped ON sql_drop
313+
EXECUTE PROCEDURE event_trigger_report_dropped();
314+
CREATE SCHEMA evttrig
315+
CREATE TABLE one (col_a SERIAL PRIMARY KEY, col_b text DEFAULT 'forty two')
316+
CREATE INDEX one_idx ON one (col_b)
317+
CREATE TABLE two (col_c INTEGER CHECK (col_c > 0) REFERENCES one DEFAULT 42);
318+
ALTER TABLE evttrig.two DROP COLUMN col_c;
319+
NOTICE: NORMAL: orig=t normal=f type=table column identity=evttrig.two.col_c
320+
NOTICE: NORMAL: orig=f normal=t type=table constraint identity=two_col_c_check on evttrig.two
321+
ALTER TABLE evttrig.one ALTER COLUMN col_b DROP DEFAULT;
322+
NOTICE: NORMAL: orig=t normal=f type=default value identity=for evttrig.one.col_b
323+
ALTER TABLE evttrig.one DROP CONSTRAINT one_pkey;
324+
NOTICE: NORMAL: orig=t normal=f type=table constraint identity=one_pkey on evttrig.one
325+
DROP INDEX evttrig.one_idx;
326+
NOTICE: NORMAL: orig=t normal=f type=index identity=evttrig.one_idx
327+
DROP SCHEMA evttrig CASCADE;
328+
NOTICE: drop cascades to 2 other objects
329+
DETAIL: drop cascades to table evttrig.one
330+
drop cascades to table evttrig.two
331+
NOTICE: NORMAL: orig=t normal=f type=schema identity=evttrig
332+
NOTICE: NORMAL: orig=f normal=t type=table identity=evttrig.one
333+
NOTICE: NORMAL: orig=f normal=t type=sequence identity=evttrig.one_col_a_seq
334+
NOTICE: NORMAL: orig=f normal=t type=default value identity=for evttrig.one.col_a
335+
NOTICE: NORMAL: orig=f normal=t type=table identity=evttrig.two
336+
DROP EVENT TRIGGER regress_event_trigger_report_dropped;
297337
-- only allowed from within an event trigger function, should fail
298338
select pg_event_trigger_table_rewrite_oid();
299339
ERROR: pg_event_trigger_table_rewrite_oid() can only be called in a table_rewrite event trigger function

‎src/test/regress/sql/event_trigger.sql

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,36 @@ DROP ROLE regression_bob;
207207
DROP EVENT TRIGGER regress_event_trigger_drop_objects;
208208
DROP EVENT TRIGGER undroppable;
209209

210+
CREATE OR REPLACEFUNCTIONevent_trigger_report_dropped()
211+
RETURNS event_trigger
212+
LANGUAGE plpgsql
213+
AS $$
214+
DECLARE r record;
215+
BEGIN
216+
FOR rINSELECT*from pg_event_trigger_dropped_objects()
217+
LOOP
218+
IF NOTr.normalAND NOTr.original THEN
219+
CONTINUE;
220+
END IF;
221+
RAISE NOTICE'NORMAL: orig=% normal=% type=% identity=%',
222+
r.original,r.normal,r.object_type,r.object_identity;
223+
END LOOP;
224+
END; $$;
225+
CREATE EVENT TRIGGER regress_event_trigger_report_droppedON sql_drop
226+
EXECUTE PROCEDURE event_trigger_report_dropped();
227+
CREATESCHEMAevttrig
228+
CREATETABLEone (col_aSERIALPRIMARY KEY, col_btext DEFAULT'forty two')
229+
CREATEINDEXone_idxON one (col_b)
230+
CREATETABLEtwo (col_cINTEGERCHECK (col_c>0)REFERENCES one DEFAULT42);
231+
232+
ALTERTABLEevttrig.two DROP COLUMN col_c;
233+
ALTERTABLEevttrig.one ALTER COLUMN col_b DROP DEFAULT;
234+
ALTERTABLEevttrig.one DROPCONSTRAINT one_pkey;
235+
DROPINDEXevttrig.one_idx;
236+
DROPSCHEMA evttrig CASCADE;
237+
238+
DROP EVENT TRIGGER regress_event_trigger_report_dropped;
239+
210240
-- only allowed from within an event trigger function, should fail
211241
select pg_event_trigger_table_rewrite_oid();
212242

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp