diff options
author | Teodor Sigaev <teodor@sigaev.ru> | 2018-04-12 17:25:13 +0300 |
---|---|---|
committer | Teodor Sigaev <teodor@sigaev.ru> | 2018-04-12 17:25:13 +0300 |
commit | 524054598fd300c75007f53aebd67f9ced33b7db (patch) | |
tree | 4bb2a55c591b20cc263539d1b05052243593a7e4 /src/backend/commands/indexcmds.c | |
parent | c266ed31a8a3beed3533e6a78faeca78234cbd43 (diff) | |
download | postgresql-524054598fd300c75007f53aebd67f9ced33b7db.tar.gz postgresql-524054598fd300c75007f53aebd67f9ced33b7db.zip |
Fix interference between covering indexes and partitioned tables
The bug is caused due to the original IndexStmt that DefineIndex receives
being overwritten when processing the INCLUDE columns. Use separate list of
index params to propagate to child tables. Add tests covering this case.
Amit Langote and Alexander Korotkov.
Re-commit 5c6110c6a960ad6fe1b0d0fec6ae36ef4eb913f5 because it discovered a bug
fixed in c266ed31a8a3beed3533e6a78faeca78234cbd43
Discussion: https://www.postgresql.org/message-id/CAJGNTeO%3DBguEyG8wxMpU_Vgvg3nGGzy71zUQ0RpzEn_mb0bSWA%40mail.gmail.com
Diffstat (limited to 'src/backend/commands/indexcmds.c')
-rw-r--r-- | src/backend/commands/indexcmds.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 61a4b24437b..78302544db8 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -342,6 +342,7 @@ DefineIndex(Oid relationId, Oid tablespaceId; Oid createdConstraintId = InvalidOid; List *indexColNames; + List *allIndexParams; Relation rel; Relation indexRelation; HeapTuple tuple; @@ -378,16 +379,16 @@ DefineIndex(Oid relationId, numberOfKeyAttributes = list_length(stmt->indexParams); /* - * We append any INCLUDE columns onto the indexParams list so that we have - * one list with all columns. Later we can determine which of these are - * key columns, and which are just part of the INCLUDE list by checking - * the list position. A list item in a position less than - * ii_NumIndexKeyAttrs is part of the key columns, and anything equal to - * and over is part of the INCLUDE columns. + * Calculate the new list of index columns including both key columns and + * INCLUDE columns. Later we can determine which of these are key columns, + * and which are just part of the INCLUDE list by checking the list + * position. A list item in a position less than ii_NumIndexKeyAttrs is + * part of the key columns, and anything equal to and over is part of the + * INCLUDE columns. */ - stmt->indexParams = list_concat(stmt->indexParams, - stmt->indexIncludingParams); - numberOfAttributes = list_length(stmt->indexParams); + allIndexParams = list_concat(list_copy(stmt->indexParams), + list_copy(stmt->indexIncludingParams)); + numberOfAttributes = list_length(allIndexParams); if (numberOfAttributes <= 0) ereport(ERROR, @@ -544,7 +545,7 @@ DefineIndex(Oid relationId, /* * Choose the index column names. */ - indexColNames = ChooseIndexColumnNames(stmt->indexParams); + indexColNames = ChooseIndexColumnNames(allIndexParams); /* * Select name for index if caller didn't specify @@ -658,7 +659,7 @@ DefineIndex(Oid relationId, coloptions = (int16 *) palloc(numberOfAttributes * sizeof(int16)); ComputeIndexAttrs(indexInfo, typeObjectId, collationObjectId, classObjectId, - coloptions, stmt->indexParams, + coloptions, allIndexParams, stmt->excludeOpNames, relationId, accessMethodName, accessMethodId, amcanorder, stmt->isconstraint); @@ -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); |