Logical decoding for operations on zheap tables

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Logical decoding for operations on zheap tables
Date: 2018-12-31 04:26:48
Message-ID: CAA4eK1JeGWBKR6nRMMUXQhSMsEQHUPHm3XVLHfUrDvrceN+WFg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

To support logical decoding for zheap operations, we need a way to
ensure zheap tuples can be registered as change streams. One idea
could be that we make ReorderBufferChange aware of another kind of
tuples as well, something like this:

@@ -100,6 +123,20 @@ typedef struct ReorderBufferChange
ReorderBufferTupleBuf *newtuple;
} tp;
+ struct
+ {
+ /* relation that has been changed */
+ RelFileNode relnode;
+
+ /* no previously reassembled toast chunks are necessary anymore */
+ bool clear_toast_afterwards;
+
+ /* valid for DELETE || UPDATE */
+ ReorderBufferZTupleBuf *oldtuple;
+ /* valid for INSERT || UPDATE */
+ ReorderBufferZTupleBuf *newtuple;
+ } ztp;
+

+/* an individual zheap tuple, stored in one chunk of memory */
+typedef struct ReorderBufferZTupleBuf
+{
..
+ /* tuple header, the interesting bit for users of logical decoding */
+ ZHeapTupleData tuple;
..
+} ReorderBufferZTupleBuf;

Apart from this, we need to define different decode functions for
zheap operations as the WAL data is different for heap and zheap, so
same functions can't be used to decode.

I have written a very hacky version to support zheap Insert operation
based on the above idea. If we want to go with this approach, we
might need a better way to represent a different type of tuple in
ReorderBufferChange.

The yet another approach could be that in the decode functions after
forming zheap tuples from WAL, we can convert them to heap tuples. I
have not tried that, so not sure if it can work, but it seems to me if
we can avoid tuple conversion overhead, it will be good.

This email is primarily to discuss about how the logical decoding for
basic DML operations (Insert/Update/Delete) will work in zheap. We
might need some special mechanism to deal with sub-transactions as
zheap doesn't generate a transaction id for sub-transactions, but we
can discuss that separately.

Thoughts?

Note - This patch is based on pluggable_zheap branch
(https://github.com/anarazel/postgres-pluggable-storage)

--
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com

Attachment Content-Type Size
decode_zinsert_1.patch application/octet-stream 17.4 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Rajib Deb 2018-12-31 04:43:01 Error while executing initdb...
Previous Message Amit Kapila 2018-12-31 04:09:56 Re: add_partial_path() may remove dominated path but still in use