mirror of
https://github.com/postgres/postgres.git
synced 2025-11-22 12:22:45 +03:00
Add support for REINDEX in event triggers
This commit adds support for REINDEX in event triggers, making this command react for the events ddl_command_start and ddl_command_end. The indexes rebuilt are collected with the ReindexStmt emitted by the caller, for the concurrent and non-concurrent paths. Thanks to that, it is possible to know a full list of the indexes that a single REINDEX command has worked on. Author: Garrett Thornburg, Jian He Reviewed-by: Jim Jones, Michael Paquier Discussion: https://postgr.es/m/CAEEqfk5bm32G7sbhzHbES9WejD8O8DCEOaLkxoBP7HNWxjPpvg@mail.gmail.com
This commit is contained in:
@@ -3558,7 +3558,8 @@ IndexGetRelation(Oid indexId, bool missing_ok)
|
||||
* reindex_index - This routine is used to recreate a single index
|
||||
*/
|
||||
void
|
||||
reindex_index(Oid indexId, bool skip_constraint_checks, char persistence,
|
||||
reindex_index(const ReindexStmt *stmt, Oid indexId,
|
||||
bool skip_constraint_checks, char persistence,
|
||||
const ReindexParams *params)
|
||||
{
|
||||
Relation iRel,
|
||||
@@ -3630,6 +3631,20 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence,
|
||||
pgstat_progress_update_param(PROGRESS_CREATEIDX_ACCESS_METHOD_OID,
|
||||
iRel->rd_rel->relam);
|
||||
|
||||
/*
|
||||
* If a statement is available, telling that this comes from a REINDEX
|
||||
* command, collect the index for event triggers.
|
||||
*/
|
||||
if (stmt)
|
||||
{
|
||||
ObjectAddress address;
|
||||
|
||||
ObjectAddressSet(address, RelationRelationId, indexId);
|
||||
EventTriggerCollectSimpleCommand(address,
|
||||
InvalidObjectAddress,
|
||||
(Node *) stmt);
|
||||
}
|
||||
|
||||
/*
|
||||
* Partitioned indexes should never get processed here, as they have no
|
||||
* physical storage.
|
||||
@@ -3865,7 +3880,8 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence,
|
||||
* index rebuild.
|
||||
*/
|
||||
bool
|
||||
reindex_relation(Oid relid, int flags, const ReindexParams *params)
|
||||
reindex_relation(const ReindexStmt *stmt, Oid relid, int flags,
|
||||
const ReindexParams *params)
|
||||
{
|
||||
Relation rel;
|
||||
Oid toast_relid;
|
||||
@@ -3953,7 +3969,7 @@ reindex_relation(Oid relid, int flags, const ReindexParams *params)
|
||||
continue;
|
||||
}
|
||||
|
||||
reindex_index(indexOid, !(flags & REINDEX_REL_CHECK_CONSTRAINTS),
|
||||
reindex_index(stmt, indexOid, !(flags & REINDEX_REL_CHECK_CONSTRAINTS),
|
||||
persistence, params);
|
||||
|
||||
CommandCounterIncrement();
|
||||
@@ -3990,7 +4006,7 @@ reindex_relation(Oid relid, int flags, const ReindexParams *params)
|
||||
|
||||
newparams.options &= ~(REINDEXOPT_MISSING_OK);
|
||||
newparams.tablespaceOid = InvalidOid;
|
||||
result |= reindex_relation(toast_relid, flags, &newparams);
|
||||
result |= reindex_relation(stmt, toast_relid, flags, &newparams);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user