Skip to content

Commit 80adb69

Browse files
author
Mikhail Samoylov
committed
Including indexes altertype bugfix
Tests for BUG PGPRO-818
1 parent 3aeb193 commit 80adb69

File tree

5 files changed

+12
-3
lines changed

5 files changed

+12
-3
lines changed

src/backend/commands/indexcmds.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ bool
118118
CheckIndexCompatible(Oid oldId,
119119
char *accessMethodName,
120120
List *attributeList,
121+
List *includingattributeList,
121122
List *exclusionOpNames)
122123
{
123124
bool isconstraint;
@@ -134,6 +135,7 @@ CheckIndexCompatible(Oid oldId,
134135
int16 *coloptions;
135136
IndexInfo *indexInfo;
136137
int numberOfAttributes;
138+
int numberOfKeyAttributes;
137139
int old_natts;
138140
bool isnull;
139141
bool ret = true;
@@ -153,6 +155,9 @@ CheckIndexCompatible(Oid oldId,
153155
isconstraint = false;
154156

155157
numberOfAttributes = list_length(attributeList);
158+
numberOfKeyAttributes = numberOfAttributes;
159+
if (includingattributeList != NULL)
160+
numberOfKeyAttributes = list_length(attributeList) - list_length(includingattributeList);
156161
Assert(numberOfAttributes > 0);
157162
Assert(numberOfAttributes <= INDEX_MAX_KEYS);
158163

@@ -178,6 +183,8 @@ CheckIndexCompatible(Oid oldId,
178183
* later on, and it would have failed then anyway.
179184
*/
180185
indexInfo = makeNode(IndexInfo);
186+
indexInfo->ii_NumIndexKeyAttrs = numberOfKeyAttributes;
187+
indexInfo->ii_NumIndexAttrs = numberOfAttributes;
181188
indexInfo->ii_Expressions = NIL;
182189
indexInfo->ii_ExpressionsState = NIL;
183190
indexInfo->ii_PredicateState = NIL;

src/backend/commands/tablecmds.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9009,6 +9009,7 @@ TryReuseIndex(Oid oldId, IndexStmt *stmt)
90099009
if (CheckIndexCompatible(oldId,
90109010
stmt->accessMethod,
90119011
stmt->indexParams,
9012+
stmt->indexIncludingParams,
90129013
stmt->excludeOpNames))
90139014
{
90149015
Relation irel = index_open(oldId, NoLock);

src/include/commands/defrem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ extern char *ChooseRelationName(const char *name1, const char *name2,
4040
extern bool CheckIndexCompatible(Oid oldId,
4141
char *accessMethodName,
4242
List *attributeList,
43+
List *includingattributeList,
4344
List *exclusionOpNames);
4445
extern Oid GetDefaultOpClass(Oid type_id, Oid am_id);
4546

src/test/regress/expected/alter_table.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3016,12 +3016,12 @@ Table "public.test_add_column"
30163016
c4 | integer |
30173017

30183018
DROP TABLE test_add_column;
3019-
3019+
-- test CHANGE COLUMN SIZE WITH BTREE INDEX
30203020
CREATE TABLE test (test_column CHARACTER VARYING(128));
30213021
CREATE INDEX test_index ON test USING btree(upper(test_column));
30223022
ALTER TABLE test ALTER COLUMN test_column TYPE VARCHAR(2048);
30233023
DROP TABLE test;
3024-
3024+
-- test CHANGE COLUMN SIZE WITH HASH INDEX
30253025
CREATE TABLE test (test_column CHARACTER VARYING(128));
30263026
CREATE INDEX test_index ON test USING HASH(upper(test_column));
30273027
WARNING: hash indexes are not WAL-logged and their use is discouraged

src/test/regress/sql/alter_table.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,7 @@ DROP TABLE test_add_column;
19151915

19161916
-- test CHANGE COLUMN SIZE WITH BTREE INDEX
19171917
CREATE TABLE test (test_column CHARACTER VARYING(128));
1918-
CREATE INDEX test_index ON test USING btree(upper(test_column);
1918+
CREATE INDEX test_index ON test USING btree(upper(test_column));
19191919
ALTER TABLE test ALTER COLUMN test_column TYPE VARCHAR(2048);
19201920
DROP TABLE test;
19211921

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy