Fix assorted bugs in CREATE INDEX CONCURRENTLY.
This patch changes CREATE INDEX CONCURRENTLY so that the pg_index
flag changes it makes without exclusive lock on the index are made via
heap_inplace_update() rather than a normal transactional update. The
latter is not very safe because moving the pg_index tuple could result in
concurrent SnapshotNow scans finding it twice or not at all, thus possibly
resulting in index corruption.
In addition, fix various places in the code that ought to check to make
sure that the indexes they are manipulating are valid and/or ready as
appropriate. These represent bugs that have existed since 8.2, since
a failed CREATE INDEX CONCURRENTLY could leave a corrupt or invalid
index behind, and we ought not try to do anything that might fail with
such an index.
Also fix RelationReloadIndexInfo to ensure it copies all the pg_index
columns that are allowed to change after initial creation. Previously we
could have been left with stale values of some fields in an index relcache
entry. It's not clear whether this actually had any user-visible
consequences, but it's at least a bug waiting to happen.
This is a subset of a patch already applied in 9.2 and HEAD. Back-patch
into all earlier supported branches.
Tom Lane and Andres Freund
src/backend/access/heap/README.HOT | 6 ++
src/backend/catalog/index.c | 94 ++++++++++++++++++++++++++++++++--
src/backend/commands/cluster.c | 10 +++-
src/backend/commands/indexcmds.c | 43 +--------------
src/backend/commands/tablecmds.c | 10 +++-
src/backend/commands/vacuum.c | 30 ++++++++---
src/backend/executor/execUtils.c | 3 +
src/backend/optimizer/util/plancat.c | 5 +-
src/backend/utils/cache/relcache.c | 19 +++++++-
src/include/catalog/index.h | 9 +++
src/include/catalog/pg_index.h | 8 +++
11 files changed, 178 insertions(+), 59 deletions(-)
pgsql-committers by date
|Next:||From: Tom Lane||Date: 2012-11-29 20:33:59|
|Subject: Re: Overlength socket paths (was Re: [COMMITTERS] pgsql: Refactor flex and bison make rules)|
|Previous:||From: Tom Lane||Date: 2012-11-29 16:31:30|
|Subject: Overlength socket paths (was Re: [COMMITTERS] pgsql: Refactor flex and bison make rules)|