diff options
author | Robert Haas <rhaas@postgresql.org> | 2013-03-17 22:55:14 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2013-03-17 22:57:26 -0400 |
commit | 05f3f9c7b2922b2a064418b5cd87b372d1b73412 (patch) | |
tree | 7532a7b338b36b659ddcfba50ebfcad22852e946 /src/backend/commands/cluster.c | |
parent | 6ac7facdd3990baf47efc124e9d7229422a06452 (diff) | |
download | postgresql-05f3f9c7b2922b2a064418b5cd87b372d1b73412.tar.gz postgresql-05f3f9c7b2922b2a064418b5cd87b372d1b73412.zip |
Extend object-access hook machinery to support post-alter events.
This also slightly widens the scope of what we support in terms of
post-create events.
KaiGai Kohei, with a few changes, mostly to the comments, by me
Diffstat (limited to 'src/backend/commands/cluster.c')
-rw-r--r-- | src/backend/commands/cluster.c | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 8ab8c175195..ef9c5f1adc7 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -27,6 +27,7 @@ #include "catalog/heap.h" #include "catalog/index.h" #include "catalog/namespace.h" +#include "catalog/objectaccess.h" #include "catalog/toasting.h" #include "commands/cluster.h" #include "commands/matview.h" @@ -481,7 +482,7 @@ check_index_is_clusterable(Relation OldHeap, Oid indexOid, bool recheck, LOCKMOD * otherwise concurrent executions of RelationGetIndexList could miss indexes. */ void -mark_index_clustered(Relation rel, Oid indexOid) +mark_index_clustered(Relation rel, Oid indexOid, bool is_internal) { HeapTuple indexTuple; Form_pg_index indexForm; @@ -541,6 +542,10 @@ mark_index_clustered(Relation rel, Oid indexOid) simple_heap_update(pg_index, &indexTuple->t_self, indexTuple); CatalogUpdateIndexes(pg_index, indexTuple); } + + InvokeObjectPostAlterHookArg(IndexRelationId, thisIndexOid, 0, + InvalidOid, is_internal); + heap_freetuple(indexTuple); } @@ -569,7 +574,7 @@ rebuild_relation(Relation OldHeap, Oid indexOid, /* Mark the correct index as clustered */ if (OidIsValid(indexOid)) - mark_index_clustered(OldHeap, indexOid); + mark_index_clustered(OldHeap, indexOid, true); /* Remember if it's a system catalog */ is_system_catalog = IsSystemRelation(OldHeap); @@ -590,7 +595,8 @@ rebuild_relation(Relation OldHeap, Oid indexOid, * rebuild the target's indexes and throw away the transient table. */ finish_heap_swap(tableOid, OIDNewHeap, is_system_catalog, - swap_toast_by_content, false, frozenXid, frozenMulti); + swap_toast_by_content, false, true, + frozenXid, frozenMulti); } @@ -1120,6 +1126,7 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, static void swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class, bool swap_toast_by_content, + bool is_internal, TransactionId frozenXid, MultiXactId frozenMulti, Oid *mapped_tables) @@ -1284,6 +1291,15 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class, } /* + * Post alter hook for modified relations. The change to r2 is always + * internal, but r1 depends on the invocation context. + */ + InvokeObjectPostAlterHookArg(RelationRelationId, r1, 0, + InvalidOid, is_internal); + InvokeObjectPostAlterHookArg(RelationRelationId, r2, 0, + InvalidOid, true); + + /* * If we have toast tables associated with the relations being swapped, * deal with them too. */ @@ -1298,6 +1314,7 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class, relform2->reltoastrelid, target_is_pg_class, swap_toast_by_content, + is_internal, frozenXid, frozenMulti, mapped_tables); @@ -1388,6 +1405,7 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class, relform2->reltoastidxid, target_is_pg_class, swap_toast_by_content, + is_internal, InvalidTransactionId, InvalidMultiXactId, mapped_tables); @@ -1427,6 +1445,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, bool is_system_catalog, bool swap_toast_by_content, bool check_constraints, + bool is_internal, TransactionId frozenXid, MultiXactId frozenMulti) { @@ -1444,8 +1463,8 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, */ swap_relation_files(OIDOldHeap, OIDNewHeap, (OIDOldHeap == RelationRelationId), - swap_toast_by_content, frozenXid, frozenMulti, - mapped_tables); + swap_toast_by_content, is_internal, + frozenXid, frozenMulti, mapped_tables); /* * If it's a system catalog, queue an sinval message to flush all @@ -1526,13 +1545,13 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, snprintf(NewToastName, NAMEDATALEN, "pg_toast_%u", OIDOldHeap); RenameRelationInternal(newrel->rd_rel->reltoastrelid, - NewToastName); + NewToastName, true); /* ... and its index too */ snprintf(NewToastName, NAMEDATALEN, "pg_toast_%u_index", OIDOldHeap); RenameRelationInternal(toastidx, - NewToastName); + NewToastName, true); } relation_close(newrel, NoLock); } |