@@ -625,13 +625,15 @@ DecodeInsert(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
625
625
626
626
if (xlrec -> flags & XLOG_HEAP_CONTAINS_NEW_TUPLE )
627
627
{
628
+ Size tuplelen = r -> xl_len - SizeOfHeapInsert ;
629
+
628
630
Assert (r -> xl_len > (SizeOfHeapInsert + SizeOfHeapHeader ));
629
631
630
- change -> data .tp .newtuple = ReorderBufferGetTupleBuf (ctx -> reorder );
632
+ change -> data .tp .newtuple =
633
+ ReorderBufferGetTupleBuf (ctx -> reorder , tuplelen );
631
634
632
635
DecodeXLogTuple ((char * ) xlrec + SizeOfHeapInsert ,
633
- r -> xl_len - SizeOfHeapInsert ,
634
- change -> data .tp .newtuple );
636
+ tuplelen , change -> data .tp .newtuple );
635
637
}
636
638
637
639
change -> data .tp .clear_toast_afterwards = true;
@@ -650,7 +652,6 @@ DecodeUpdate(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
650
652
{
651
653
XLogRecord * r = & buf -> record ;
652
654
xl_heap_update * xlrec ;
653
- xl_heap_header_len xlhdr ;
654
655
ReorderBufferChange * change ;
655
656
char * data ;
656
657
@@ -669,16 +670,20 @@ DecodeUpdate(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
669
670
670
671
if (xlrec -> flags & XLOG_HEAP_CONTAINS_NEW_TUPLE )
671
672
{
673
+ Size tuplelen ;
674
+ xl_heap_header_len xlhdr ;
675
+
672
676
Assert (r -> xl_len > (SizeOfHeapUpdate + SizeOfHeapHeaderLen ));
673
677
674
678
memcpy (& xlhdr , data , sizeof (xlhdr ));
675
679
data += offsetof(xl_heap_header_len , header );
676
680
677
- change -> data . tp . newtuple = ReorderBufferGetTupleBuf ( ctx -> reorder ) ;
681
+ tuplelen = xlhdr . t_len + SizeOfHeapHeader ;
678
682
679
- DecodeXLogTuple (data ,
680
- xlhdr .t_len + SizeOfHeapHeader ,
681
- change -> data .tp .newtuple );
683
+ change -> data .tp .newtuple =
684
+ ReorderBufferGetTupleBuf (ctx -> reorder , tuplelen );
685
+
686
+ DecodeXLogTuple (data , tuplelen , change -> data .tp .newtuple );
682
687
/* skip over the rest of the tuple header */
683
688
data += SizeOfHeapHeader ;
684
689
/* skip over the tuple data */
@@ -687,14 +692,18 @@ DecodeUpdate(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
687
692
688
693
if (xlrec -> flags & XLOG_HEAP_CONTAINS_OLD )
689
694
{
695
+ Size tuplelen ;
696
+ xl_heap_header_len xlhdr ;
697
+
690
698
memcpy (& xlhdr , data , sizeof (xlhdr ));
691
699
data += offsetof(xl_heap_header_len , header );
692
700
693
- change -> data . tp . oldtuple = ReorderBufferGetTupleBuf ( ctx -> reorder ) ;
701
+ tuplelen = xlhdr . t_len + SizeOfHeapHeader ;
694
702
695
- DecodeXLogTuple (data ,
696
- xlhdr .t_len + SizeOfHeapHeader ,
697
- change -> data .tp .oldtuple );
703
+ change -> data .tp .oldtuple =
704
+ ReorderBufferGetTupleBuf (ctx -> reorder , tuplelen );
705
+
706
+ DecodeXLogTuple (data , tuplelen , change -> data .tp .oldtuple );
698
707
#ifdef NOT_USED
699
708
data += SizeOfHeapHeader ;
700
709
data += xlhdr .t_len ;
@@ -732,13 +741,15 @@ DecodeDelete(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
732
741
/* old primary key stored */
733
742
if (xlrec -> flags & XLOG_HEAP_CONTAINS_OLD )
734
743
{
744
+ Size len = r -> xl_len - SizeOfHeapDelete ;
745
+
735
746
Assert (r -> xl_len > (SizeOfHeapDelete + SizeOfHeapHeader ));
736
747
737
- change -> data .tp .oldtuple = ReorderBufferGetTupleBuf (ctx -> reorder );
748
+ change -> data .tp .oldtuple =
749
+ ReorderBufferGetTupleBuf (ctx -> reorder , len );
738
750
739
751
DecodeXLogTuple ((char * ) xlrec + SizeOfHeapDelete ,
740
- r -> xl_len - SizeOfHeapDelete ,
741
- change -> data .tp .oldtuple );
752
+ len , change -> data .tp .oldtuple );
742
753
}
743
754
744
755
change -> data .tp .clear_toast_afterwards = true;
@@ -795,37 +806,40 @@ DecodeMultiInsert(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
795
806
*/
796
807
if (xlrec -> flags & XLOG_HEAP_CONTAINS_NEW_TUPLE )
797
808
{
798
- change -> data .tp .newtuple = ReorderBufferGetTupleBuf (ctx -> reorder );
809
+ HeapTupleHeader header ;
810
+
811
+ xlhdr = (xl_multi_insert_tuple * ) SHORTALIGN (data );
812
+ data = ((char * ) xlhdr ) + SizeOfMultiInsertTuple ;
813
+ datalen = xlhdr -> datalen ;
814
+
815
+ change -> data .tp .newtuple =
816
+ ReorderBufferGetTupleBuf (ctx -> reorder , datalen );
799
817
800
818
tuple = change -> data .tp .newtuple ;
819
+ header = tuple -> tuple .t_data ;
801
820
802
821
/* not a disk based tuple */
803
822
ItemPointerSetInvalid (& tuple -> tuple .t_self );
804
823
805
- xlhdr = (xl_multi_insert_tuple * ) SHORTALIGN (data );
806
- data = ((char * ) xlhdr ) + SizeOfMultiInsertTuple ;
807
- datalen = xlhdr -> datalen ;
808
-
809
824
/*
810
825
* We can only figure this out after reassembling the
811
826
* transactions.
812
827
*/
813
828
tuple -> tuple .t_tableOid = InvalidOid ;
814
- tuple -> tuple . t_data = & tuple -> header ;
829
+
815
830
tuple -> tuple .t_len = datalen
816
831
+ offsetof(HeapTupleHeaderData , t_bits );
817
832
818
- memset (& tuple -> header , 0 , sizeof (HeapTupleHeaderData ));
833
+ memset (header , 0 , offsetof (HeapTupleHeaderData , t_bits ));
819
834
820
- memcpy ((char * ) & tuple -> header
821
- + offsetof(HeapTupleHeaderData , t_bits ),
835
+ memcpy ((char * ) tuple -> tuple .t_data + offsetof(HeapTupleHeaderData , t_bits ),
822
836
(char * ) data ,
823
837
datalen );
824
838
data += datalen ;
825
839
826
- tuple -> header . t_infomask = xlhdr -> t_infomask ;
827
- tuple -> header . t_infomask2 = xlhdr -> t_infomask2 ;
828
- tuple -> header . t_hoff = xlhdr -> t_hoff ;
840
+ header -> t_infomask = xlhdr -> t_infomask ;
841
+ header -> t_infomask2 = xlhdr -> t_infomask2 ;
842
+ header -> t_hoff = xlhdr -> t_hoff ;
829
843
}
830
844
831
845
/*
@@ -856,31 +870,31 @@ DecodeXLogTuple(char *data, Size len, ReorderBufferTupleBuf *tuple)
856
870
{
857
871
xl_heap_header xlhdr ;
858
872
int datalen = len - SizeOfHeapHeader ;
873
+ HeapTupleHeader header ;
859
874
860
875
Assert (datalen >= 0 );
861
- Assert (datalen <= MaxHeapTupleSize );
862
876
863
877
tuple -> tuple .t_len = datalen + offsetof(HeapTupleHeaderData , t_bits );
878
+ header = tuple -> tuple .t_data ;
864
879
865
880
/* not a disk based tuple */
866
881
ItemPointerSetInvalid (& tuple -> tuple .t_self );
867
882
868
883
/* we can only figure this out after reassembling the transactions */
869
884
tuple -> tuple .t_tableOid = InvalidOid ;
870
- tuple -> tuple .t_data = & tuple -> header ;
871
885
872
886
/* data is not stored aligned, copy to aligned storage */
873
887
memcpy ((char * ) & xlhdr ,
874
888
data ,
875
889
SizeOfHeapHeader );
876
890
877
- memset (& tuple -> header , 0 , sizeof (HeapTupleHeaderData ));
891
+ memset (header , 0 , offsetof (HeapTupleHeaderData , t_bits ));
878
892
879
- memcpy ((char * ) & tuple -> header + offsetof(HeapTupleHeaderData , t_bits ),
893
+ memcpy ((( char * ) tuple -> tuple . t_data ) + offsetof(HeapTupleHeaderData , t_bits ),
880
894
data + SizeOfHeapHeader ,
881
895
datalen );
882
896
883
- tuple -> header . t_infomask = xlhdr .t_infomask ;
884
- tuple -> header . t_infomask2 = xlhdr .t_infomask2 ;
885
- tuple -> header . t_hoff = xlhdr .t_hoff ;
897
+ header -> t_infomask = xlhdr .t_infomask ;
898
+ header -> t_infomask2 = xlhdr .t_infomask2 ;
899
+ header -> t_hoff = xlhdr .t_hoff ;
886
900
}
0 commit comments