postgresql/src/backend
Tom Lane 32c893c8d1 Avoid returning stale attribute bitmaps in RelationGetIndexAttrBitmap().
The problem with the original coding here is that we might receive (and
clear) a relcache invalidation signal for the target relation down inside
one of the index_open calls we're doing.  Since the target is open, we
would not drop the relcache entry, just reset its rd_indexvalid and
rd_indexlist fields.  But RelationGetIndexAttrBitmap() kept going, and
would eventually cache and return potentially-obsolete attribute bitmaps.

The case where this matters is where the inval signal was from a CREATE
INDEX CONCURRENTLY telling us about a new index on a formerly-unindexed
column.  (In all other cases, the lock we hold on the target rel should
prevent any concurrent change in index state.)  Even just returning the
stale attribute bitmap is not such a problem, because it shouldn't matter
during the transaction in which we receive the signal.  What hurts is
caching the stale data, because it can survive into later transactions,
breaking CREATE INDEX CONCURRENTLY's expectation that later transactions
will not create new broken HOT chains.  The upshot is that there's a window
for building corrupted indexes during CREATE INDEX CONCURRENTLY.

This patch fixes the problem by rechecking that the set of index OIDs
is still the same at the end of RelationGetIndexAttrBitmap() as it was
at the start.  If not, we loop back and try again.  That's a little
more than is strictly necessary to fix the bug --- in principle, we
could return the stale data but not cache it --- but it seems like a
bad idea on general principles for relcache to return data it knows
is stale.

There might be more hazards of the same ilk, or there might be a better
way to fix this one, but this patch definitely improves matters and seems
unlikely to make anything worse.  So let's push it into today's releases
even as we continue to study the problem.

Pavan Deolasee and myself

Discussion: https://postgr.es/m/CABOikdM2MUq9cyZJi1KyLmmkCereyGp5JQ4fuwKoyKEde_mzkQ@mail.gmail.com
2017-02-06 13:20:24 -05:00
..
access Fix typos in comments. 2017-02-06 11:34:28 +02:00
bootstrap Protect against multixact members wraparound 2015-04-28 11:32:53 -03:00
catalog Log the creation of an init fork unconditionally. 2016-12-08 14:16:47 -05:00
commands Fix typos in comments. 2017-02-06 11:34:28 +02:00
executor Throw suitable error for COPY TO STDOUT/FROM STDIN in a SQL function. 2017-01-14 13:27:47 -05:00
foreign Arrange to cache FdwRoutine structs in foreign tables' relcache entries. 2013-03-06 23:48:09 -05:00
lib Misc comment typo fixes. 2014-12-16 16:39:33 +02:00
libpq Fix typos in comments. 2017-02-06 11:34:28 +02:00
main Make fallback implementation of pg_memory_barrier() work in 9.2 and 9.3. 2016-04-16 10:42:07 -04:00
nodes Fix improper repetition of previous results from a hashed aggregate. 2016-08-24 14:37:51 -04:00
optimizer Fix typos in comments. 2017-02-06 11:34:28 +02:00
parser Fix typos in comments. 2017-02-06 11:34:28 +02:00
po Translation updates 2017-02-06 12:35:49 -05:00
port Improve TranslateSocketError() to handle more Windows error codes. 2016-04-21 16:59:08 -04:00
postmaster Fix typos in comments. 2017-02-06 11:34:28 +02:00
regex Suppress compiler warnings about useless comparison of unsigned to zero. 2016-02-15 17:11:52 -05:00
replication Reset hot standby xmin after restart 2017-01-26 20:15:23 +00:00
rewrite Improve error message for rejecting RETURNING clauses with dropped columns. 2016-02-29 19:11:53 -05:00
snowball Fix ancient encoding error in hungarian.stop. 2014-06-10 22:48:39 -04:00
storage Fix typos in comments. 2017-02-06 11:34:28 +02:00
tcop Add castNode(type, ptr) for safe casting between NodeTag based types. 2017-01-26 16:47:04 -08:00
tsearch Fix typos in comments. 2017-02-06 11:34:28 +02:00
utils Avoid returning stale attribute bitmaps in RelationGetIndexAttrBitmap(). 2017-02-06 13:20:24 -05:00
.gitignore Add gitignore for mingw/cygwin build outputs 2011-06-09 18:11:47 +02:00
common.mk Call check_keywords.pl in maintainer-check 2012-02-27 13:53:12 +02:00
Makefile AIX: Link the postgres executable with -Wl,-brtllib. 2015-07-15 21:00:30 -04:00
nls.mk xlogreader.c: Fix report_invalid_record translatability flag 2015-01-09 12:34:24 -03:00