@@ -342,7 +342,6 @@ DefineIndex(Oid relationId,
342342 Oid tablespaceId ;
343343 Oid createdConstraintId = InvalidOid ;
344344 List * indexColNames ;
345- List * allIndexParams ;
346345 Relation rel ;
347346 Relation indexRelation ;
348347 HeapTuple tuple ;
@@ -379,16 +378,16 @@ DefineIndex(Oid relationId,
379378 numberOfKeyAttributes = list_length (stmt -> indexParams );
380379
381380 /*
382- * Calculate the new list of index columns including both key columns and
383- * INCLUDE columns. Later we can determine which of these are key columns,
384- * and which are just part of the INCLUDE list by checking the list
385- * position. A list item in a position less than ii_NumIndexKeyAttrs is
386- * part of the key columns, and anything equal to and over is part of the
387- * INCLUDE columns.
381+ * We append any INCLUDE columns onto the indexParams list so that we have
382+ * one list with all columns. Later we can determine which of these are
383+ * key columns, and which are just part of the INCLUDE list by checking
384+ * the list position. A list item in a position less than
385+ * ii_NumIndexKeyAttrs is part of the key columns, and anything equal to
386+ * and over is part of the INCLUDE columns.
388387 */
389- allIndexParams = list_concat (list_copy ( stmt -> indexParams ) ,
390- list_copy ( stmt -> indexIncludingParams ) );
391- numberOfAttributes = list_length (allIndexParams );
388+ stmt -> indexParams = list_concat (stmt -> indexParams ,
389+ stmt -> indexIncludingParams );
390+ numberOfAttributes = list_length (stmt -> indexParams );
392391
393392 if (numberOfAttributes <= 0 )
394393 ereport (ERROR ,
@@ -545,7 +544,7 @@ DefineIndex(Oid relationId,
545544 /*
546545 * Choose the index column names.
547546 */
548- indexColNames = ChooseIndexColumnNames (allIndexParams );
547+ indexColNames = ChooseIndexColumnNames (stmt -> indexParams );
549548
550549 /*
551550 * Select name for index if caller didn't specify
@@ -659,7 +658,7 @@ DefineIndex(Oid relationId,
659658 coloptions = (int16 * ) palloc (numberOfAttributes * sizeof (int16 ));
660659 ComputeIndexAttrs (indexInfo ,
661660 typeObjectId , collationObjectId , classObjectId ,
662- coloptions , allIndexParams ,
661+ coloptions , stmt -> indexParams ,
663662 stmt -> excludeOpNames , relationId ,
664663 accessMethodName , accessMethodId ,
665664 amcanorder , stmt -> isconstraint );
@@ -887,8 +886,8 @@ DefineIndex(Oid relationId,
887886 memcpy (part_oids , partdesc -> oids , sizeof (Oid ) * nparts );
888887
889888 parentDesc = CreateTupleDescCopy (RelationGetDescr (rel ));
890- opfamOids = palloc (sizeof (Oid ) * numberOfKeyAttributes );
891- for (i = 0 ; i < numberOfKeyAttributes ; i ++ )
889+ opfamOids = palloc (sizeof (Oid ) * numberOfAttributes );
890+ for (i = 0 ; i < numberOfAttributes ; i ++ )
892891 opfamOids [i ] = get_opclass_family (classObjectId [i ]);
893892
894893 heap_close (rel , NoLock );
0 commit comments