summaryrefslogtreecommitdiff
path: root/src/backend/catalog/index.c
diff options
context:
space:
mode:
authorMichael Paquier2023-12-04 00:53:49 +0000
committerMichael Paquier2023-12-04 00:53:49 +0000
commitf21848de20130146bc8039504af40bd24add54cd (patch)
treeb2c95265c2ee21f151e0d5a38778adef649d451b /src/backend/catalog/index.c
parentd78b6cbb602f5c36db3e267e2713b3aa22c815a5 (diff)
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
Diffstat (limited to 'src/backend/catalog/index.c')
-rw-r--r--src/backend/catalog/index.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 143fae01ebd..b8c7945322e 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -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,
@@ -3631,6 +3632,20 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence,
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;