diff options
author | Michael Paquier <michael@paquier.xyz> | 2024-09-09 13:49:36 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2024-09-09 13:49:36 +0900 |
commit | 5bbdfa8a18dc56d3e64aa723a68e02e897cb5ec3 (patch) | |
tree | a2468c54c3f7c7c32cb84b812c44b1363a99ab7e /src/backend/commands/indexcmds.c | |
parent | dd8bea88abf4794d99270ced884a8bc1e387255d (diff) | |
download | postgresql-5bbdfa8a18dc56d3e64aa723a68e02e897cb5ec3.tar.gz postgresql-5bbdfa8a18dc56d3e64aa723a68e02e897cb5ec3.zip |
Fix waits of REINDEX CONCURRENTLY for indexes with predicates or expressions
As introduced by f9900df5f94, a REINDEX CONCURRENTLY job done for an
index with predicates or expressions would set PROC_IN_SAFE_IC in its
MyProc->statusFlags, causing it to be ignored by other concurrent
operations.
Such concurrent index rebuilds should never be ignored, as a predicate
or an expression could call a user-defined function that accesses a
different table than the table where the index is rebuilt.
A test that uses injection points is added, backpatched down to 17.
Michail has proposed a different test, but I have added something
simpler with more coverage.
Oversight in f9900df5f949.
Author: Michail Nikolaev
Discussion: https://postgr.es/m/CANtu0oj9A3kZVduFTG0vrmGnKB+DCHgEpzOp0qAyOgmks84j0w@mail.gmail.com
Backpatch-through: 14
Diffstat (limited to 'src/backend/commands/indexcmds.c')
-rw-r--r-- | src/backend/commands/indexcmds.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index c5a56c75f69..b987e023849 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -61,6 +61,7 @@ #include "utils/builtins.h" #include "utils/fmgroids.h" #include "utils/guc.h" +#include "utils/injection_point.h" #include "utils/inval.h" #include "utils/lsyscache.h" #include "utils/memutils.h" @@ -3782,8 +3783,16 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein RestrictSearchPath(); /* determine safety of this index for set_indexsafe_procflags */ - idx->safe = (indexRel->rd_indexprs == NIL && - indexRel->rd_indpred == NIL); + idx->safe = (RelationGetIndexExpressions(indexRel) == NIL && + RelationGetIndexPredicate(indexRel) == NIL); + +#ifdef USE_INJECTION_POINTS + if (idx->safe) + INJECTION_POINT("reindex-conc-index-safe"); + else + INJECTION_POINT("reindex-conc-index-not-safe"); +#endif + idx->tableId = RelationGetRelid(heapRel); idx->amId = indexRel->rd_rel->relam; |