@@ -320,8 +320,8 @@ DefineIndex(Oid relationId,
320320Datum reloptions ;
321321int16 * coloptions ;
322322IndexInfo * indexInfo ;
323- int numberOfAttributes ,
324- numberOfKeyAttributes ;
323+ int numberOfAttributes ;
324+ int numberOfKeyAttributes ;
325325TransactionId limitXmin ;
326326VirtualTransactionId * old_snapshots ;
327327ObjectAddress address ;
@@ -336,7 +336,6 @@ DefineIndex(Oid relationId,
336336ereport (ERROR ,
337337(errcode (ERRCODE_INVALID_OBJECT_DEFINITION ),
338338errmsg ("included columns must not intersect with key columns" )));
339-
340339/*
341340 * count attributes in index
342341 */
@@ -351,7 +350,7 @@ DefineIndex(Oid relationId,
351350 * we have one list with all columns. Later we can determine which of these
352351 * are key columns, and which are just part of the INCLUDING list by check the list
353352 * position. A list item in a position less than ii_NumIndexKeyAttrs is part of
354- * theindexed columns, and anything equal to and over is part of the
353+ * thekey columns, and anything equal to and over is part of the
355354 * INCLUDING columns.
356355 */
357356stmt -> indexParams = list_concat (stmt -> indexParams ,stmt -> indexIncludingParams );
@@ -488,7 +487,6 @@ DefineIndex(Oid relationId,
488487 * look up the access method, verify it can handle the requested features
489488 */
490489accessMethodName = stmt -> accessMethod ;
491-
492490tuple = SearchSysCache1 (AMNAME ,PointerGetDatum (accessMethodName ));
493491if (!HeapTupleIsValid (tuple ))
494492{
@@ -523,6 +521,11 @@ DefineIndex(Oid relationId,
523521(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
524522errmsg ("access method \"%s\" does not support unique indexes" ,
525523accessMethodName )));
524+ if (list_length (stmt -> indexIncludingParams )> 0 && !accessMethodForm -> amcaninclude )
525+ ereport (ERROR ,
526+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
527+ errmsg ("access method \"%s\" does not support included columns" ,
528+ accessMethodName )));
526529if (numberOfAttributes > 1 && !accessMethodForm -> amcanmulticol )
527530ereport (ERROR ,
528531(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
@@ -534,12 +537,6 @@ DefineIndex(Oid relationId,
534537errmsg ("access method \"%s\" does not support exclusion constraints" ,
535538accessMethodName )));
536539
537- if (list_length (stmt -> indexIncludingParams )> 0 && !accessMethodForm -> amcanincluding )
538- ereport (ERROR ,
539- (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
540- errmsg ("access method \"%s\" does not support included columns" ,
541- accessMethodName )));
542-
543540amcanorder = accessMethodForm -> amcanorder ;
544541amoptions = accessMethodForm -> amoptions ;
545542
@@ -988,16 +985,15 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
988985ListCell * nextExclOp ;
989986ListCell * lc ;
990987int attn ;
988+ int nkeycols = indexInfo -> ii_NumIndexKeyAttrs ;
991989
992990/* Allocate space for exclusion operator info, if needed */
993991if (exclusionOpNames )
994992{
995- int ncols = list_length (attList );
996-
997- Assert (list_length (exclusionOpNames )== ncols );
998- indexInfo -> ii_ExclusionOps = (Oid * )palloc (sizeof (Oid )* ncols );
999- indexInfo -> ii_ExclusionProcs = (Oid * )palloc (sizeof (Oid )* ncols );
1000- indexInfo -> ii_ExclusionStrats = (uint16 * )palloc (sizeof (uint16 )* ncols );
993+ Assert (list_length (exclusionOpNames )== nkeycols );
994+ indexInfo -> ii_ExclusionOps = (Oid * )palloc (sizeof (Oid )* nkeycols );
995+ indexInfo -> ii_ExclusionProcs = (Oid * )palloc (sizeof (Oid )* nkeycols );
996+ indexInfo -> ii_ExclusionStrats = (uint16 * )palloc (sizeof (uint16 )* nkeycols );
1001997nextExclOp = list_head (exclusionOpNames );
1002998}
1003999else
@@ -1050,6 +1046,11 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
10501046Node * expr = attribute -> expr ;
10511047
10521048Assert (expr != NULL );
1049+
1050+ if (attn >=nkeycols )
1051+ ereport (ERROR ,
1052+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
1053+ errmsg ("Expressions in INCLUDING clause are not supported" )));
10531054atttype = exprType (expr );
10541055attcollation = exprCollation (expr );
10551056
@@ -1130,6 +1131,11 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
11301131/*
11311132 * Identify the opclass to use.
11321133 */
1134+ if (attn >=nkeycols )
1135+ {
1136+ attn ++ ;
1137+ continue ;
1138+ }
11331139classOidP [attn ]= GetIndexOpClass (attribute -> opclass ,
11341140atttype ,
11351141accessMethodName ,