postgresql/src/backend/utils/cache
Peter Eisentraut edd8278c54 Fix a crash in logical replication
The bug was that determining which columns are part of the replica
identity index using RelationGetIndexAttrBitmap() would run
eval_const_expressions() on index expressions and predicates across
all indexes of the table, which in turn might require a snapshot, but
there wasn't one set, so it crashes.  There were actually two separate
bugs, one on the publisher and one on the subscriber.

To trigger the bug, a table that is part of a publication or
subscription needs to have an index with a predicate or expression
that lends itself to constant expressions simplification.

The fix is to avoid the constant expressions simplification in
RelationGetIndexAttrBitmap(), so that it becomes safe to call in these
contexts.  The constant expressions simplification comes from the
calls to RelationGetIndexExpressions()/RelationGetIndexPredicate() via
BuildIndexInfo().  But RelationGetIndexAttrBitmap() calling
BuildIndexInfo() is overkill.  The latter just takes pg_index catalog
information, packs it into the IndexInfo structure, which former then
just unpacks again and throws away.  We can just do this directly with
less overhead and skip the troublesome calls to
eval_const_expressions().  This also removes the awkward
cross-dependency between relcache.c and index.c.

Bug: #15114
Reported-by: Петър Славов <pet.slavov@gmail.com>
Reviewed-by: Noah Misch <noah@leadboat.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://www.postgresql.org/message-id/flat/152110589574.1223.17983600132321618383@wrigleys.postgresql.org/
2019-01-30 11:16:27 +01:00
..
attoptcache.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
catcache.c Remove AtEOXact_CatCache(). 2017-08-13 16:15:14 -04:00
evtcache.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
inval.c Limit depth of forced recursion for CLOBBER_CACHE_RECURSIVELY. 2018-09-07 18:14:30 -04:00
lsyscache.c Further patch rangetypes_selfuncs.c's statistics slot management. 2017-05-08 15:02:58 -04:00
Makefile Add infrastructure for mapping relfilenodes to relation OIDs. 2013-07-22 11:09:10 -04:00
plancache.c Invalidate cached plans on FDW option changes. 2017-01-06 14:12:52 -05:00
relcache.c Fix a crash in logical replication 2019-01-30 11:16:27 +01:00
relfilenodemap.c Reduce initial size of RelfilenodeMapHash. 2017-05-12 18:30:02 -04:00
relmapper.c PANIC on fsync() failure. 2018-11-19 14:13:22 +13:00
spccache.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
syscache.c Avoid searching for callback functions in CallSyscacheCallbacks(). 2017-05-12 19:05:29 -04:00
ts_cache.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
typcache.c Fix typcache's failure to treat ranges as container types. 2017-10-20 17:12:27 -04:00