@@ -3891,25 +3891,15 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence,
38913891 * index rebuild.
38923892 */
38933893bool
3894- reindex_relation (Oid relid , int flags , ReindexParams * params )
3894+ reindex_relation (Relation rel , int flags , ReindexParams * params )
38953895{
3896- Relation rel ;
38973896 Oid toast_relid ;
38983897 List * indexIds ;
38993898 char persistence ;
39003899 bool result ;
39013900 ListCell * indexId ;
39023901 int i ;
39033902
3904- /*
3905- * Open and lock the relation. ShareLock is sufficient since we only need
3906- * to prevent schema and data changes in it. The lock level used here
3907- * should match ReindexTable().
3908- */
3909- if ((params -> options & REINDEXOPT_MISSING_OK ) != 0 )
3910- rel = try_table_open (relid , ShareLock );
3911- else
3912- rel = table_open (relid , ShareLock );
39133903
39143904 /* if relation is gone, leave */
39153905 if (!rel )
@@ -4001,11 +3991,6 @@ reindex_relation(Oid relid, int flags, ReindexParams *params)
40013991 i ++ ;
40023992 }
40033993
4004- /*
4005- * Close rel, but continue to hold the lock.
4006- */
4007- table_close (rel , NoLock );
4008-
40093994 result = (indexIds != NIL );
40103995
40113996 /*
@@ -4021,10 +4006,20 @@ reindex_relation(Oid relid, int flags, ReindexParams *params)
40214006 * This rule is enforced by setting tablespaceOid to InvalidOid.
40224007 */
40234008 ReindexParams newparams = * params ;
4009+ /*
4010+ * Open and lock the relation. ShareLock is sufficient since we only need
4011+ * to prevent schema and data changes in it. The lock level used here
4012+ * should match ReindexTable().
4013+ */
4014+ Relation toast_rel = table_open (toast_relid , ShareLock );
40244015
40254016 newparams .options &= ~(REINDEXOPT_MISSING_OK );
40264017 newparams .tablespaceOid = InvalidOid ;
4027- result |= reindex_relation (toast_relid , flags , & newparams );
4018+ result |= reindex_relation (toast_rel , flags , & newparams );
4019+ /*
4020+ * Close rel, but continue to hold the lock.
4021+ */
4022+ table_close (toast_rel , NoLock );
40284023 }
40294024
40304025 return result ;
0 commit comments