From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Andres Freund <andres@anarazel.de>
Cc: Петър Славов <pet.slavov@gmail.com>
Cc: Petr Jelinek <petr@2ndquadrant.com>
Cc: pgsql-bugs@lists.postgresql.org, Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Subject: Re: BUG #15114: logical decoding Segmentation fault
Date: Mon, 16 Apr 2018 14:59:01 -0300
Message-ID: <20180416175901.mdevawuuhvwo3yk6@alvherre.pgsql> (raw)
In-Reply-To: <20180326160801.ja4j43hwrc35iuhb@alvherre.pgsql>
Alvaro Herrera wrote:
> I agree -- I think logicalrep_write_attrs() should not use
> RelationGetIndexAttrBitmap at all but instead use some lower-level way
> to obtain columns of the replica identity. I don't know whether there
> are historical-snapshot-related considerations to care about, in this
> code, though.
Here's a patch. There is a disadvantage: one additional syscache lookup
each time logicalrep_write_attrs() is called. I think that's all right,
since that's done once for each relation being replicated (not, say,
once per tuple or once per transaction). Even so, I tried to move this
code as a special "quick-path" case in RelationGetIndexAttrBitmap, so
that it could be cached separately without processing the other indexes.
That turned out a bit too messy for my taste.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachments:proto.patch (text/plain, 1.8K) downloaddiff --git a/src/backend/replication/logical/proto.c b/src/backend/replication/logical/proto.cindex edc97a7662..06fa5c5647 100644--- a/src/backend/replication/logical/proto.c+++ b/src/backend/replication/logical/proto.c@@ -582,8 +582,47 @@ logicalrep_write_attrs(StringInfo out, Relation rel)
/* fetch bitmap of REPLICATION IDENTITY attributes */
replidentfull = (rel->rd_rel->relreplident == REPLICA_IDENTITY_FULL);
if (!replidentfull)
- idattrs = RelationGetIndexAttrBitmap(rel,- INDEX_ATTR_BITMAP_IDENTITY_KEY);+ {+ Oid idindex = rel->rd_replidindex;++ /*+ * Building the index list determines the replica index OID as a side+ * effect, so do so now unless we already have it.+ */+ if (rel->rd_replidindex == InvalidOid)+ {+ list_free(RelationGetIndexList(rel));+ idindex = rel->rd_replidindex;+ }++ /*+ * Now build the bitmap. We cannot use RelationGetIndexAttrBitmap+ * here: it would try to build IndexInfo for all the relation's+ * indexes, which would be a problem, as the right authorization+ * environment for that has not been set up yet (a problem+ * particularly if there are any SQL-language functions.)+ *+ * It would be nice to cache this somewhere, but it's not clear how to+ * invalidate it when the time comes.+ */+ if (OidIsValid(idindex))+ {+ HeapTuple tuple;+ Form_pg_index index;+ int natts;++ tuple = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(idindex));+ if (!tuple)+ elog(ERROR, "cache lookup failed for index %u", idindex);+ index = (Form_pg_index) GETSTRUCT(tuple);+ natts = index->indnkeyatts;++ for (i = 0; i < natts; i++)+ idattrs = bms_add_member(idattrs, index->indkey.values[i] -+ FirstLowInvalidHeapAttributeNumber);+ ReleaseSysCache(tuple);+ }+ }
/* send the attributes */
for (i = 0; i < desc->natts; i++)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: alvherre@alvh.no-ip.org, andres@anarazel.de, pet.slavov@gmail.com, petr@2ndquadrant.com, peter.eisentraut@2ndquadrant.com
Subject: Re: BUG #15114: logical decoding Segmentation fault
In-Reply-To: <20180416175901.mdevawuuhvwo3yk6@alvherre.pgsql>
References: <20180326160801.ja4j43hwrc35iuhb@alvherre.pgsql> <20180416175901.mdevawuuhvwo3yk6@alvherre.pgsql>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox