mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
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
This commit is contained in:
@ -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)
|
||||
@ -1283,6 +1290,15 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
|
||||
CacheInvalidateRelcacheByTuple(reltup2);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user