postgresql/src/backend/utils/cache
Peter Eisentraut dfa774ff9a 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 08:49:54 +01:00
..
attoptcache.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
catcache.c Remove superfluous tqual.h includes. 2019-01-21 12:15:02 -08:00
evtcache.c Replace heapam.h includes with {table, relation}.h where applicable. 2019-01-21 10:51:37 -08:00
inval.c Fix misc typos in comments. 2019-01-23 13:39:00 +02:00
lsyscache.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
Makefile Reorganize partitioning code 2018-04-14 21:12:14 -03:00
partcache.c Refactor planner's header files. 2019-01-29 15:48:51 -05:00
plancache.c Refactor planner's header files. 2019-01-29 15:48:51 -05:00
relcache.c Fix a crash in logical replication 2019-01-30 08:49:54 +01:00
relfilenodemap.c Replace uses of heap_open et al with the corresponding table_* function. 2019-01-21 10:51:37 -08:00
relmapper.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
spccache.c Refactor planner's header files. 2019-01-29 15:48:51 -05:00
syscache.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
ts_cache.c Remove superfluous tqual.h includes. 2019-01-21 12:15:02 -08:00
typcache.c Refactor planner's header files. 2019-01-29 15:48:51 -05:00