Skip to content

Commit 0ae3b46

Browse files
committed
Improve handling of dropped partitioned indexes for REINDEX INDEX
A REINDEX INDEX done on a partitioned index builds a list of the indexes to work on before processing its partitions in individual transactions. When combined with a DROP of the partitioned index, there was a window where it was possible to see some unexpected "could not open relation with OID", synonym of relation lookup error. The code was robust enough to handle the case where the parent relation is missing, but not the case where an index would be gone missing. This is similar to 1d65416. Support for REINDEX on partitioned relations has been introduced in a6642b3, so backpatch down to 14. Author: Fei Changhong Discussion: https://postgr.es/m/tencent_6A52106095ACDE55333E3AD33F304C0C3909@qq.com Backpatch-through: 14
1 parent 8013850 commit 0ae3b46

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/backend/catalog/index.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3634,7 +3634,24 @@ reindex_index(const ReindexStmt *stmt, Oid indexId,
36343634
* Open the target index relation and get an exclusive lock on it, to
36353635
* ensure that no one else is touching this particular index.
36363636
*/
3637-
iRel = index_open(indexId, AccessExclusiveLock);
3637+
if ((params->options & REINDEXOPT_MISSING_OK) != 0)
3638+
iRel = try_index_open(indexId, AccessExclusiveLock);
3639+
else
3640+
iRel = index_open(indexId, AccessExclusiveLock);
3641+
3642+
/* if index relation is gone, leave */
3643+
if (!iRel)
3644+
{
3645+
/* Roll back any GUC changes */
3646+
AtEOXact_GUC(false, save_nestlevel);
3647+
3648+
/* Restore userid and security context */
3649+
SetUserIdAndSecContext(save_userid, save_sec_context);
3650+
3651+
/* Close parent heap relation, but keep locks */
3652+
table_close(heapRelation, NoLock);
3653+
return;
3654+
}
36383655

36393656
if (progress)
36403657
pgstat_progress_update_param(PROGRESS_CREATEIDX_ACCESS_METHOD_OID,

0 commit comments

Comments
 (0)