pgsql: Fix assorted bugs in CREATE INDEX CONCURRENTLY. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Fix assorted bugs in CREATE INDEX CONCURRENTLY.
Date
Msg-id E1TeAAH-00082b-Bp@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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

Branch
------
REL9_1_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/1da5bef3174170a6768bea6621afcbf72dd02a87

Modified Files
--------------
src/backend/access/heap/README.HOT   |    6 ++
src/backend/catalog/index.c          |  150 ++++++++++++++++++++++++++++------
src/backend/commands/cluster.c       |   10 ++-
src/backend/commands/indexcmds.c     |   41 +---------
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/parser/parse_utilcmd.c   |    8 +--
src/backend/utils/cache/relcache.c   |   21 +++++-
src/include/catalog/index.h          |    9 ++
src/include/catalog/pg_index.h       |    8 ++
12 files changed, 216 insertions(+), 85 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Fix assorted bugs in CREATE INDEX CONCURRENTLY.
Next
From: Tom Lane
Date:
Subject: pgsql: Fix assorted bugs in CREATE INDEX CONCURRENTLY.