DefineIndex-fix-covering-index-partitioned-1.patch

text/plain

Filename: DefineIndex-fix-covering-index-partitioned-1.patch
Type: text/plain
Part: 0
Message: Re: Partitioned tables and covering indexes

Patch

Format: unified
File+
src/backend/commands/indexcmds.c 5 4
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index 860a60d109..109d48bb2f 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -366,6 +366,7 @@ DefineIndex(Oid relationId,
 	LOCKMODE	lockmode;
 	Snapshot	snapshot;
 	int			i;
+	IndexStmt  *orig_stmt = copyObject(stmt);
 
 	if (list_intersection(stmt->indexParams, stmt->indexIncludingParams) != NIL)
 		ereport(ERROR,
@@ -886,8 +887,8 @@ DefineIndex(Oid relationId,
 			memcpy(part_oids, partdesc->oids, sizeof(Oid) * nparts);
 
 			parentDesc = CreateTupleDescCopy(RelationGetDescr(rel));
-			opfamOids = palloc(sizeof(Oid) * numberOfAttributes);
-			for (i = 0; i < numberOfAttributes; i++)
+			opfamOids = palloc(sizeof(Oid) * numberOfKeyAttributes);
+			for (i = 0; i < numberOfKeyAttributes; i++)
 				opfamOids[i] = get_opclass_family(classObjectId[i]);
 
 			heap_close(rel, NoLock);
@@ -987,11 +988,11 @@ DefineIndex(Oid relationId,
 				 */
 				if (!found)
 				{
-					IndexStmt  *childStmt = copyObject(stmt);
+					IndexStmt  *childStmt = copyObject(orig_stmt);
 					bool		found_whole_row;
 
 					childStmt->whereClause =
-						map_variable_attnos(stmt->whereClause, 1, 0,
+						map_variable_attnos(orig_stmt->whereClause, 1, 0,
 											attmap, maplen,
 											InvalidOid, &found_whole_row);
 					if (found_whole_row)