diff --git a/src/backend/executor/execPartition.c b/src/backend/executor/execPartition.c index dac789d414..b5f796f5ed 100644 --- a/src/backend/executor/execPartition.c +++ b/src/backend/executor/execPartition.c @@ -1669,6 +1669,19 @@ ExecFindInitialMatchingSubPlans(PartitionPruneState *prunestate, int nsubplans) new_subplan_indexes[i] = newidx++; else new_subplan_indexes[i] = -1; /* Newly pruned */ + + /* + * If a subplan in other_subplans got its index updated, update + * other_subplans too. + */ + if (bms_is_member(i, prunestate->other_subplans)) + { + prunestate->other_subplans = + bms_del_member(prunestate->other_subplans, i); + prunestate->other_subplans = + bms_add_member(prunestate->other_subplans, + new_subplan_indexes[i]); + } } /*