Subject: [PATCH] review changes --- Index: src/backend/commands/cluster.c IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c --- a/src/backend/commands/cluster.c (revision 5936ff16dfe4765ef0dd6e18be401aefcf120d36) +++ b/src/backend/commands/cluster.c (date 1772889987377) @@ -2971,9 +2971,6 @@ /* * Update indexes. - * - * In case functions in the index need the active snapshot and caller - * hasn't set one. */ ExecStoreHeapTuple(tup, index_slot, false); recheck = ExecInsertIndexTuples(iistate->rri, @@ -2988,6 +2985,7 @@ * committed.) */ list_free(recheck); + ResetPerTupleExprContext(iistate->estate); pgstat_progress_incr_param(PROGRESS_REPACK_HEAP_TUPLES_INSERTED, 1); } @@ -3032,6 +3030,7 @@ index_slot, NIL, NULL); list_free(recheck); + ResetPerTupleExprContext(iistate->estate); } pgstat_progress_incr_param(PROGRESS_REPACK_HEAP_TUPLES_UPDATED, 1); @@ -3260,25 +3259,24 @@ scan = index_beginscan(rel, ident_index, GetActiveSnapshot(), NULL, dest->ident_key_nentries, 0); - /* - * Scan key is passed by caller, so it does not have to be constructed - * multiple times. Key entries have all fields initialized, except for - * sk_argument. - */ - index_rescan(scan, dest->ident_key, dest->ident_key_nentries, NULL, 0); - /* Info needed to retrieve key values from heap tuple. */ ident_form = ident_index->rd_index; ident_indkey = &ident_form->indkey; - /* Use the incoming tuple to finalize the scan key. */ - for (int i = 0; i < scan->numberOfKeys; i++) + /* + * Scan key is passed by caller, so it does not have to be constructed + * multiple times. Key entries have all fields initialized, except for + * sk_argument. + * + * Use the incoming tuple to finalize the scan key. + */ + for (int i = 0; i < dest->ident_key_nentries; i++) { ScanKey entry; bool isnull; int16 attno_heap; - entry = &scan->keyData[i]; + entry = &dest->ident_key[i]; attno_heap = ident_indkey->values[i]; entry->sk_argument = heap_getattr(tup_key, attno_heap, @@ -3286,6 +3284,8 @@ &isnull); Assert(!isnull); } + + index_rescan(scan, dest->ident_key, dest->ident_key_nentries, NULL, 0); if (index_getnext_slot(scan, ForwardScanDirection, ident_slot)) { bool shouldFree;