pgsql: Fix a crash in logical replication

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix a crash in logical replication
Date: 2019-01-30 07:58:56
Message-ID: E1gokls-0007wt-0X@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(dot)slavov(at)gmail(dot)com>
Reviewed-by: Noah Misch <noah(at)leadboat(dot)com>
Reviewed-by: Michael Paquier <michael(at)paquier(dot)xyz>
Discussion: https://www.postgresql.org/message-id/flat/152110589574(dot)1223(dot)17983600132321618383(at)wrigleys(dot)postgresql(dot)org/

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/dfa774ff9ac9de33d8cb98b91906ada55a2ab1df

Modified Files
--------------
src/backend/utils/cache/relcache.c | 50 ++++++++++++++++++++--------
src/test/subscription/t/100_bugs.pl | 65 +++++++++++++++++++++++++++++++++++++
2 files changed, 101 insertions(+), 14 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Meskes 2019-01-30 09:39:44 pgsql: Make some ecpg test cases more robust against unexpected errors
Previous Message Michael Paquier 2019-01-30 00:45:25 pgsql: Do not filter by relkind in vacuumdb's catalog query if --table