]> granicus.if.org Git - postgresql/commitdiff
Restore REINDEX constraint validation.
authorNoah Misch <noah@leadboat.com>
Tue, 30 Jul 2013 22:36:52 +0000 (18:36 -0400)
committerNoah Misch <noah@leadboat.com>
Wed, 31 Jul 2013 00:00:31 +0000 (20:00 -0400)
Refactoring as part of commit 8ceb24568054232696dddc1166a8563bc78c900a
had the unintended effect of making REINDEX TABLE and REINDEX DATABASE
no longer validate constraints enforced by the indexes in question;
REINDEX INDEX still did so.  Indexes marked invalid remained so, and
constraint violations arising from data corruption went undetected.
Back-patch to 9.0, like the causative commit.

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

index 441b99fa24333c95b81349d61b37b7336d510c41..09c8d62f5da815c3c91945d228fe03dfa01b7b9a 100644 (file)
@@ -1606,7 +1606,7 @@ ReindexTable(RangeVar *relation)
 
        ReleaseSysCache(tuple);
 
-       if (!reindex_relation(heapOid, true, 0))
+       if (!reindex_relation(heapOid, true, REINDEX_CHECK_CONSTRAINTS))
                ereport(NOTICE,
                                (errmsg("table \"%s\" has no indexes",
                                                relation->relname)));
@@ -1719,7 +1719,7 @@ ReindexDatabase(const char *databaseName, bool do_system, bool do_user)
                StartTransactionCommand();
                /* functions in indexes may want a snapshot set */
                PushActiveSnapshot(GetTransactionSnapshot());
-               if (reindex_relation(relid, true, 0))
+               if (reindex_relation(relid, true, REINDEX_CHECK_CONSTRAINTS))
                        ereport(NOTICE,
                                        (errmsg("table \"%s.%s\" was reindexed",
                                                        get_namespace_name(get_rel_namespace(relid)),
index f2c0923730393b4d8d0556d6bf69798445a55c4e..b361201f4b896bb29665d3be5e952a97472c8495 100644 (file)
@@ -890,9 +890,13 @@ COMMIT;
 BEGIN;
 CREATE INDEX std_index on concur_heap(f2);
 COMMIT;
--- check to make sure that the failed indexes were cleaned up properly and the
--- successful indexes are created properly. Notably that they do NOT have the
--- "invalid" flag set.
+-- Failed builds are left invalid by VACUUM FULL, fixed by REINDEX
+VACUUM FULL concur_heap;
+REINDEX TABLE concur_heap;
+ERROR:  could not create unique index "concur_index3"
+DETAIL:  Key (f2)=(b) is duplicated.
+DELETE FROM concur_heap WHERE f1 = 'b';
+VACUUM FULL concur_heap;
 \d concur_heap
 Table "public.concur_heap"
  Column | Type | Modifiers 
@@ -908,6 +912,22 @@ Indexes:
     "concur_index5" btree (f2) WHERE f1 = 'x'::text
     "std_index" btree (f2)
 
+REINDEX TABLE concur_heap;
+\d concur_heap
+Table "public.concur_heap"
+ Column | Type | Modifiers 
+--------+------+-----------
+ f1     | text | 
+ f2     | text | 
+Indexes:
+    "concur_index2" UNIQUE, btree (f1)
+    "concur_index3" UNIQUE, btree (f2)
+    "concur_heap_expr_idx" btree ((f2 || f1))
+    "concur_index1" btree (f2, f1)
+    "concur_index4" btree (f2) WHERE f1 = 'a'::text
+    "concur_index5" btree (f2) WHERE f1 = 'x'::text
+    "std_index" btree (f2)
+
 DROP TABLE concur_heap;
 --
 -- Tests for IS NULL/IS NOT NULL with b-tree indexes
index 62f439c3f0f76c6488e7165377d79dca73189140..9d9b2406ed1ff0a8a2a0ee93b5d74c1ab9d98a79 100644 (file)
@@ -369,10 +369,13 @@ BEGIN;
 CREATE INDEX std_index on concur_heap(f2);
 COMMIT;
 
--- check to make sure that the failed indexes were cleaned up properly and the
--- successful indexes are created properly. Notably that they do NOT have the
--- "invalid" flag set.
-
+-- Failed builds are left invalid by VACUUM FULL, fixed by REINDEX
+VACUUM FULL concur_heap;
+REINDEX TABLE concur_heap;
+DELETE FROM concur_heap WHERE f1 = 'b';
+VACUUM FULL concur_heap;
+\d concur_heap
+REINDEX TABLE concur_heap;
 \d concur_heap
 
 DROP TABLE concur_heap;