]> granicus.if.org Git - postgresql/commitdiff
Fix crash when ALTER TABLE recreates indexes on partitions
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 29 Jun 2018 15:27:57 +0000 (11:27 -0400)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 29 Jun 2018 15:49:30 +0000 (11:49 -0400)
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

src/backend/commands/indexcmds.c
src/test/regress/expected/indexing.out
src/test/regress/sql/indexing.sql

index 3b82876c909ad04e4ff2d9934eeb2920ae7a0ddf..576c85f732d77f23426594c13e0204524839b543 100644 (file)
@@ -1033,7 +1033,7 @@ DefineIndex(Oid relationId,
                                                                indexRelationId,        /* this is our child */
                                                                createdConstraintId,
                                                                is_alter_table, check_rights, check_not_in_use,
-                                                               false, quiet);
+                                                               skip_build, quiet);
                                }
 
                                pfree(attmap);
index f183317fbe8179e7c54c20e50281a71702175369..b9297c98d2932eea953a22e19d8dac479afc9b5c 100644 (file)
@@ -40,6 +40,14 @@ SELECT col2 FROM idxpart_two fk LEFT OUTER JOIN idxpart pk ON (col1 = col2);
 (0 rows)
 
 DROP table idxpart, idxpart_two;
+-- Verify bugfix with index rewrite on ALTER TABLE / SET DATA TYPE
+-- https://postgr.es/m/CAKcux6mxNCGsgATwf5CGMF8g4WSupCXicCVMeKUTuWbyxHOMsQ@mail.gmail.com
+CREATE TABLE idxpart (a INT, b TEXT, c INT) PARTITION BY RANGE(a);
+CREATE TABLE idxpart1 PARTITION OF idxpart FOR VALUES FROM (MINVALUE) TO (MAXVALUE);
+CREATE INDEX partidx_abc_idx ON idxpart (a, b, c);
+INSERT INTO idxpart (a, b, c) SELECT i, i, i FROM generate_series(1, 50) i;
+ALTER TABLE idxpart ALTER COLUMN c TYPE numeric;
+DROP TABLE idxpart;
 -- If a table without index is attached as partition to a table with
 -- an index, the index is automatically created
 create table idxpart (a int, b int, c text) partition by range (a);
index 1731fb4d5c39999297b5ff2aeb4676031faff726..2091a87ff5928cd8e3606feb0bd2fa9deb167773 100644 (file)
@@ -26,6 +26,15 @@ CREATE TABLE idxpart_two (col2 INT);
 SELECT col2 FROM idxpart_two fk LEFT OUTER JOIN idxpart pk ON (col1 = col2);
 DROP table idxpart, idxpart_two;
 
+-- Verify bugfix with index rewrite on ALTER TABLE / SET DATA TYPE
+-- https://postgr.es/m/CAKcux6mxNCGsgATwf5CGMF8g4WSupCXicCVMeKUTuWbyxHOMsQ@mail.gmail.com
+CREATE TABLE idxpart (a INT, b TEXT, c INT) PARTITION BY RANGE(a);
+CREATE TABLE idxpart1 PARTITION OF idxpart FOR VALUES FROM (MINVALUE) TO (MAXVALUE);
+CREATE INDEX partidx_abc_idx ON idxpart (a, b, c);
+INSERT INTO idxpart (a, b, c) SELECT i, i, i FROM generate_series(1, 50) i;
+ALTER TABLE idxpart ALTER COLUMN c TYPE numeric;
+DROP TABLE idxpart;
+
 -- If a table without index is attached as partition to a table with
 -- an index, the index is automatically created
 create table idxpart (a int, b int, c text) partition by range (a);