PartitionedRelPruneInfo-relid_map-pruned-parts-zero-fix.patch

application/octet-stream

Filename: PartitionedRelPruneInfo-relid_map-pruned-parts-zero-fix.patch
Type: application/octet-stream
Part: 0
Message: Re: FailedAssertion("pd_idx == pinfo->nparts", File: "execPartition.c", Line: 1689)

Patch

Format: unified
File+
src/backend/executor/execPartition.c 6 1
diff --git a/src/backend/executor/execPartition.c b/src/backend/executor/execPartition.c
index fb6ce49..840e459 100644
--- a/src/backend/executor/execPartition.c
+++ b/src/backend/executor/execPartition.c
@@ -1673,7 +1673,12 @@ ExecCreatePartitionPruneState(PlanState *planstate,
 				pprune->subpart_map = palloc(sizeof(int) * partdesc->nparts);
 				for (pp_idx = 0; pp_idx < partdesc->nparts; ++pp_idx)
 				{
-					if (pinfo->relid_map[pd_idx] != partdesc->oids[pp_idx])
+					/*
+					 * Beware of InvalidOids in relid_map that were put in for
+					 * partitions pruned by the planner.
+					 */
+					if (OidIsValid(pinfo->relid_map[pd_idx]) &&
+						pinfo->relid_map[pd_idx] != partdesc->oids[pp_idx])
 					{
 						pprune->subplan_map[pp_idx] = -1;
 						pprune->subpart_map[pp_idx] = -1;