8000 Restore REINDEX constraint validation. · sqlparser/postgres@6c1fec9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6c1fec9

Browse files
committed
Restore REINDEX constraint validation.
Refactoring as part of commit 8ceb245 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.
1 parent 3587f78 commit 6c1fec9

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

src/backend/commands/indexcmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,7 @@ ReindexTable(RangeVar *relation)
16061606

16071607
ReleaseSysCache(tuple);
16081608

1609-
if (!reindex_relation(heapOid, true, 0))
1609+
if (!reindex_relation(heapOid, true, REINDEX_CHECK_CONSTRAINTS))
16101610
ereport(NOTICE,
16111611
(errmsg("table \"%s\" has no indexes",
16121612
relation->relname)));
@@ -1719,7 +1719,7 @@ ReindexDatabase(const char *databaseName, bool do_system, bool do_user)
17191719
StartTransactionCommand();
17201720
/* functions in indexes may want a snapshot set */
17211721
PushActiveSnapshot(GetTransactionSnapshot());
1722-
if (reindex_relation(relid, true, 0))
1722+
if (reindex_relation(relid, true, REINDEX_CHECK_CONSTRAINTS))
17231723
ereport(NOTICE,
17241724
(errmsg("table \"%s.%s\" was reindexed",
17251725
get_namespace_name(get_rel_namespace(relid)),

src/test/regress/expected/create_index.out

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -890,9 +890,13 @@ COMMIT;
890890
BEGIN;
891891
CREATE INDEX std_index on concur_heap(f2);
892892
COMMIT;
893-
-- check to make sure that the failed indexes were cleaned up properly and the
894-
-- successful indexes are created properly. Notably that they do NOT have the
895-
-- "invalid" flag set.
893+
-- Failed builds are left invalid by VACUUM FULL, fixed by REINDEX
894+
VACUUM FULL concur_heap;
895+
REINDEX TABLE concur_heap;
896+
ERROR: could not create unique index "concur_index3"
897+
DETAIL: Key (f2)=(b) is duplicated.
898+
DELETE FROM concur_heap WHERE f1 = 'b';
899+
VACUUM FULL concur_heap;
896900
\d concur_heap
897901
Table "public.concur_heap"
898902
Column | Type | Modifiers
@@ -908,6 +912,22 @@ Indexes:
908912
"concur_index5" btree (f2) WHERE f1 = 'x'::text
909913
"std_index" btree (f2)
910914

915+
REINDEX TABLE concur_heap;
916+
\d concur_heap
917+
Table "public.concur_heap"
918+
Column | Type | Modifiers
919+
--------+------+-----------
920+
f1 | text |
921+
f2 | text |
922+
Indexes:
923+
"concur_index2" UNIQUE, btree (f1)
924+
"concur_index3" UNIQUE, btree (f2)
925+
"concur_heap_expr_idx" btree ((f2 || f1))
926+
"concur_index1" btree (f2, f1)
927+
"concur_index4" btree (f2) WHERE f1 = 'a'::text
928+
"concur_index5" btree (f2) WHERE f1 = 'x'::text
929+
"std_index" btree (f2)
930+
911931
DROP TABLE concur_heap;
912932
--
913933
-- Tests for IS NULL/IS NOT NULL with b-tree indexes

src/test/regress/sql/create_index.sql

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,13 @@ BEGIN;
369369
CREATE INDEX std_index on concur_heap(f2);
370370
COMMIT;
371371

372-
-- check to make sure that the failed indexes were cleaned up properly and the
373-
-- successful indexes are created properly. Notably that they do NOT have the
374-
-- "invalid" flag set.
375-
372+
-- Failed builds are left invalid by VACUUM FULL, fixed by REINDEX
373+
VACUUM FULL concur_heap;
374+
REINDEX TABLE concur_heap;
375+
DELETE FROM concur_heap WHERE f1 = 'b';
376+
VACUUM FULL concur_heap;
377+
\d concur_heap
378+
REINDEX TABLE concur_heap;
376379
\d concur_heap
377380

378381
DROP TABLE concur_heap;

0 commit comments

Comments
 (0)
0