Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit16f38f7

Browse files
committed
Restore REINDEX constraint validation.
Refactoring as part of commit8ceb245had the unintended effect of making REINDEX TABLE and REINDEX DATABASEno longer validate constraints enforced by the indexes in question;REINDEX INDEX still did so. Indexes marked invalid remained so, andconstraint violations arising from data corruption went undetected.Back-patch to 9.0, like the causative commit.
1 parent000b65f commit16f38f7

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

‎src/backend/commands/indexcmds.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,7 +1768,9 @@ ReindexTable(RangeVar *relation)
17681768
heapOid=RangeVarGetRelidExtended(relation,ShareLock, false, false,
17691769
RangeVarCallbackOwnsTable,NULL);
17701770

1771-
if (!reindex_relation(heapOid,REINDEX_REL_PROCESS_TOAST))
1771+
if (!reindex_relation(heapOid,
1772+
REINDEX_REL_PROCESS_TOAST |
1773+
REINDEX_REL_CHECK_CONSTRAINTS))
17721774
ereport(NOTICE,
17731775
(errmsg("table \"%s\" has no indexes",
17741776
relation->relname)));
@@ -1884,7 +1886,9 @@ ReindexDatabase(const char *databaseName, bool do_system, bool do_user)
18841886
StartTransactionCommand();
18851887
/* functions in indexes may want a snapshot set */
18861888
PushActiveSnapshot(GetTransactionSnapshot());
1887-
if (reindex_relation(relid,REINDEX_REL_PROCESS_TOAST))
1889+
if (reindex_relation(relid,
1890+
REINDEX_REL_PROCESS_TOAST |
1891+
REINDEX_REL_CHECK_CONSTRAINTS))
18881892
ereport(NOTICE,
18891893
(errmsg("table \"%s.%s\" was reindexed",
18901894
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
@@ -2298,9 +2298,13 @@ COMMIT;
22982298
BEGIN;
22992299
CREATE INDEX std_index on concur_heap(f2);
23002300
COMMIT;
2301-
-- check to make sure that the failed indexes were cleaned up properly and the
2302-
-- successful indexes are created properly. Notably that they do NOT have the
2303-
-- "invalid" flag set.
2301+
-- Failed builds are left invalid by VACUUM FULL, fixed by REINDEX
2302+
VACUUM FULL concur_heap;
2303+
REINDEX TABLE concur_heap;
2304+
ERROR: could not create unique index "concur_index3"
2305+
DETAIL: Key (f2)=(b) is duplicated.
2306+
DELETE FROM concur_heap WHERE f1 = 'b';
2307+
VACUUM FULL concur_heap;
23042308
\d concur_heap
23052309
Table "public.concur_heap"
23062310
Column | Type | Modifiers
@@ -2316,6 +2320,22 @@ Indexes:
23162320
"concur_index5" btree (f2) WHERE f1 = 'x'::text
23172321
"std_index" btree (f2)
23182322

2323+
REINDEX TABLE concur_heap;
2324+
\d concur_heap
2325+
Table "public.concur_heap"
2326+
Column | Type | Modifiers
2327+
--------+------+-----------
2328+
f1 | text |
2329+
f2 | text |
2330+
Indexes:
2331+
"concur_index2" UNIQUE, btree (f1)
2332+
"concur_index3" UNIQUE, btree (f2)
2333+
"concur_heap_expr_idx" btree ((f2 || f1))
2334+
"concur_index1" btree (f2, f1)
2335+
"concur_index4" btree (f2) WHERE f1 = 'a'::text
2336+
"concur_index5" btree (f2) WHERE f1 = 'x'::text
2337+
"std_index" btree (f2)
2338+
23192339
--
23202340
-- Try some concurrent index drops
23212341
--

‎src/test/regress/sql/create_index.sql

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -721,10 +721,13 @@ BEGIN;
721721
CREATEINDEXstd_indexon concur_heap(f2);
722722
COMMIT;
723723

724-
-- check to make sure that the failed indexes were cleaned up properly and the
725-
-- successful indexes are created properly. Notably that they do NOT have the
726-
-- "invalid" flag set.
727-
724+
-- Failed builds are left invalid by VACUUM FULL, fixed by REINDEX
725+
VACUUM FULL concur_heap;
726+
REINDEX TABLE concur_heap;
727+
DELETEFROM concur_heapWHERE f1='b';
728+
VACUUM FULL concur_heap;
729+
\d concur_heap
730+
REINDEX TABLE concur_heap;
728731
\d concur_heap
729732

730733
--

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp