@@ -342,6 +342,7 @@ DefineIndex(Oid relationId,
342
342
Oid tablespaceId ;
343
343
Oid createdConstraintId = InvalidOid ;
344
344
List * indexColNames ;
345
+ List * allIndexParams ;
345
346
Relation rel ;
346
347
Relation indexRelation ;
347
348
HeapTuple tuple ;
@@ -378,16 +379,16 @@ DefineIndex(Oid relationId,
378
379
numberOfKeyAttributes = list_length (stmt -> indexParams );
379
380
380
381
/*
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.
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.
387
388
*/
388
- stmt -> indexParams = list_concat (stmt -> indexParams ,
389
- stmt -> indexIncludingParams );
390
- numberOfAttributes = list_length (stmt -> indexParams );
389
+ allIndexParams = list_concat (list_copy ( stmt -> indexParams ) ,
390
+ list_copy ( stmt -> indexIncludingParams ) );
391
+ numberOfAttributes = list_length (allIndexParams );
391
392
392
393
if (numberOfAttributes <= 0 )
393
394
ereport (ERROR ,
@@ -544,7 +545,7 @@ DefineIndex(Oid relationId,
544
545
/*
545
546
* Choose the index column names.
546
547
*/
547
- indexColNames = ChooseIndexColumnNames (stmt -> indexParams );
548
+ indexColNames = ChooseIndexColumnNames (allIndexParams );
548
549
549
550
/*
550
551
* Select name for index if caller didn't specify
@@ -658,7 +659,7 @@ DefineIndex(Oid relationId,
658
659
coloptions = (int16 * ) palloc (numberOfAttributes * sizeof (int16 ));
659
660
ComputeIndexAttrs (indexInfo ,
660
661
typeObjectId , collationObjectId , classObjectId ,
661
- coloptions , stmt -> indexParams ,
662
+ coloptions , allIndexParams ,
662
663
stmt -> excludeOpNames , relationId ,
663
664
accessMethodName , accessMethodId ,
664
665
amcanorder , stmt -> isconstraint );
@@ -886,8 +887,8 @@ DefineIndex(Oid relationId,
886
887
memcpy (part_oids , partdesc -> oids , sizeof (Oid ) * nparts );
887
888
888
889
parentDesc = CreateTupleDescCopy (RelationGetDescr (rel ));
889
- opfamOids = palloc (sizeof (Oid ) * numberOfAttributes );
890
- for (i = 0 ; i < numberOfAttributes ; i ++ )
890
+ opfamOids = palloc (sizeof (Oid ) * numberOfKeyAttributes );
891
+ for (i = 0 ; i < numberOfKeyAttributes ; i ++ )
891
892
opfamOids [i ] = get_opclass_family (classObjectId [i ]);
892
893
893
894
heap_close (rel , NoLock );
0 commit comments