Skip to content

Commit 4137207

Browse files
committed
Fix crash when ALTER TABLE recreates indexes on partitions
The skip_build flag was not being passed correctly when recursing to indexes on partitions, leading to attempts to rebuild indexes when they were not yet ready to be rebuilt. Reported-by: Rajkumar Raghuwanshi Discussion: https://postgr.es/m/CAKcux6mxNCGsgATwf5CGMF8g4WSupCXicCVMeKUTuWbyxHOMsQ@mail.gmail.com
1 parent dad335b commit 4137207

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/backend/commands/indexcmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ DefineIndex(Oid relationId,
10331033
indexRelationId, /* this is our child */
10341034
createdConstraintId,
10351035
is_alter_table, check_rights, check_not_in_use,
1036-
false, quiet);
1036+
skip_build, quiet);
10371037
}
10381038

10391039
pfree(attmap);

src/test/regress/expected/indexing.out

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ SELECT col2 FROM idxpart_two fk LEFT OUTER JOIN idxpart pk ON (col1 = col2);
4040
(0 rows)
4141

4242
DROP table idxpart, idxpart_two;
43+
-- Verify bugfix with index rewrite on ALTER TABLE / SET DATA TYPE
44+
-- https://postgr.es/m/CAKcux6mxNCGsgATwf5CGMF8g4WSupCXicCVMeKUTuWbyxHOMsQ@mail.gmail.com
45+
CREATE TABLE idxpart (a INT, b TEXT, c INT) PARTITION BY RANGE(a);
46+
CREATE TABLE idxpart1 PARTITION OF idxpart FOR VALUES FROM (MINVALUE) TO (MAXVALUE);
47+
CREATE INDEX partidx_abc_idx ON idxpart (a, b, c);
48+
INSERT INTO idxpart (a, b, c) SELECT i, i, i FROM generate_series(1, 50) i;
49+
ALTER TABLE idxpart ALTER COLUMN c TYPE numeric;
50+
DROP TABLE idxpart;
4351
-- If a table without index is attached as partition to a table with
4452
-- an index, the index is automatically created
4553
create table idxpart (a int, b int, c text) partition by range (a);

src/test/regress/sql/indexing.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ CREATE TABLE idxpart_two (col2 INT);
2626
SELECT col2 FROM idxpart_two fk LEFT OUTER JOIN idxpart pk ON (col1 = col2);
2727
DROP table idxpart, idxpart_two;
2828

29+
-- Verify bugfix with index rewrite on ALTER TABLE / SET DATA TYPE
30+
-- https://postgr.es/m/CAKcux6mxNCGsgATwf5CGMF8g4WSupCXicCVMeKUTuWbyxHOMsQ@mail.gmail.com
31+
CREATE TABLE idxpart (a INT, b TEXT, c INT) PARTITION BY RANGE(a);
32+
CREATE TABLE idxpart1 PARTITION OF idxpart FOR VALUES FROM (MINVALUE) TO (MAXVALUE);
33+
CREATE INDEX partidx_abc_idx ON idxpart (a, b, c);
34+
INSERT INTO idxpart (a, b, c) SELECT i, i, i FROM generate_series(1, 50) i;
35+
ALTER TABLE idxpart ALTER COLUMN c TYPE numeric;
36+
DROP TABLE idxpart;
37+
2938
-- If a table without index is attached as partition to a table with
3039
-- an index, the index is automatically created
3140
create table idxpart (a int, b int, c text) partition by range (a);

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