Logical decoding for operations on zheap tables - Mailing list pgsql-hackers

From Amit Kapila
Subject Logical decoding for operations on zheap tables
Date
Msg-id CAA4eK1JeGWBKR6nRMMUXQhSMsEQHUPHm3XVLHfUrDvrceN+WFg@mail.gmail.com
Whole thread Raw
Responses Re: Logical decoding for operations on zheap tables  (Amit Kapila <amit.kapila16@gmail.com>)
Re: Logical decoding for operations on zheap tables  (Andres Freund <andres@anarazel.de>)
List 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

pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: add_partial_path() may remove dominated path but still in use
Next
From: Rajib Deb
Date:
Subject: Error while executing initdb...