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

Commited33ad3

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 parentaa49821 commited33ad3

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
@@ -1553,7 +1553,9 @@ ReindexTable(RangeVar *relation)
15531553

15541554
ReleaseSysCache(tuple);
15551555

1556-
if (!reindex_relation(heapOid,REINDEX_REL_PROCESS_TOAST))
1556+
if (!reindex_relation(heapOid,
1557+
REINDEX_REL_PROCESS_TOAST |
1558+
REINDEX_REL_CHECK_CONSTRAINTS))
15571559
ereport(NOTICE,
15581560
(errmsg("table \"%s\" has no indexes",
15591561
relation->relname)));
@@ -1666,7 +1668,9 @@ ReindexDatabase(const char *databaseName, bool do_system, bool do_user)
16661668
StartTransactionCommand();
16671669
/* functions in indexes may want a snapshot set */
16681670
PushActiveSnapshot(GetTransactionSnapshot());
1669-
if (reindex_relation(relid,REINDEX_REL_PROCESS_TOAST))
1671+
if (reindex_relation(relid,
1672+
REINDEX_REL_PROCESS_TOAST |
1673+
REINDEX_REL_CHECK_CONSTRAINTS))
16701674
ereport(NOTICE,
16711675
(errmsg("table \"%s.%s\" was reindexed",
16721676
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
@@ -1190,9 +1190,13 @@ COMMIT;
11901190
BEGIN;
11911191
CREATE INDEX std_index on concur_heap(f2);
11921192
COMMIT;
1193-
-- check to make sure that the failed indexes were cleaned up properly and the
1194-
-- successful indexes are created properly. Notably that they do NOT have the
1195-
-- "invalid" flag set.
1193+
-- Failed builds are left invalid by VACUUM FULL, fixed by REINDEX
1194+
VACUUM FULL concur_heap;
1195+
REINDEX TABLE concur_heap;
1196+
ERROR: could not create unique index "concur_index3"
1197+
DETAIL: Key (f2)=(b) is duplicated.
1198+
DELETE FROM concur_heap WHERE f1 = 'b';
1199+
VACUUM FULL concur_heap;
11961200
\d concur_heap
11971201
Table "public.concur_heap"
11981202
Column | Type | Modifiers
@@ -1208,6 +1212,22 @@ Indexes:
12081212
"concur_index5" btree (f2) WHERE f1 = 'x'::text
12091213
"std_index" btree (f2)
12101214

1215+
REINDEX TABLE concur_heap;
1216+
\d concur_heap
1217+
Table "public.concur_heap"
1218+
Column | Type | Modifiers
1219+
--------+------+-----------
1220+
f1 | text |
1221+
f2 | text |
1222+
Indexes:
1223+
"concur_index2" UNIQUE, btree (f1)
1224+
"concur_index3" UNIQUE, btree (f2)
1225+
"concur_heap_expr_idx" btree ((f2 || f1))
1226+
"concur_index1" btree (f2, f1)
1227+
"concur_index4" btree (f2) WHERE f1 = 'a'::text
1228+
"concur_index5" btree (f2) WHERE f1 = 'x'::text
1229+
"std_index" btree (f2)
1230+
12111231
DROP TABLE concur_heap;
12121232
--
12131233
-- Test ADD CONSTRAINT USING INDEX

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,13 @@ BEGIN;
401401
CREATEINDEXstd_indexon concur_heap(f2);
402402
COMMIT;
403403

404-
-- check to make sure that the failed indexes were cleaned up properly and the
405-
-- successful indexes are created properly. Notably that they do NOT have the
406-
-- "invalid" flag set.
407-
404+
-- Failed builds are left invalid by VACUUM FULL, fixed by REINDEX
405+
VACUUM FULL concur_heap;
406+
REINDEX TABLE concur_heap;
407+
DELETEFROM concur_heapWHERE f1='b';
408+
VACUUM FULL concur_heap;
409+
\d concur_heap
410+
REINDEX TABLE concur_heap;
408411
\d concur_heap
409412

410413
DROPTABLE concur_heap;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp