Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 08e6344

Browse files
Remove ReorderBufferTupleBuf structure.
Since commit a4ccc1c, the 'node' and 'alloc_tuple_size' fields of the ReorderBufferTupleBuf structure are no longer used. This leaves only the 'tuple' field in the structure. Since keeping a single-field structure makes little sense, the ReorderBufferTupleBuf is removed entirely. The code is refactored accordingly. No back-patching since these are ABI changes in an exposed structure and functions, and there would be some risk of breaking extensions. Author: Aleksander Alekseev Reviewed-by: Amit Kapila, Masahiko Sawada, Reid Thompson Discussion: https://postgr.es/m/CAD21AoCvnuxiXXfRecp7g9+CeC35POQfhuQeJFr7_9u_Q5jc_Q@mail.gmail.com
1 parent 50b797d commit 08e6344

File tree

6 files changed

+68
-91
lines changed

6 files changed

+68
-91
lines changed

contrib/test_decoding/test_decoding.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ pg_decode_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
640640
appendStringInfoString(ctx->out, " (no-tuple-data)");
641641
else
642642
tuple_to_stringinfo(ctx->out, tupdesc,
643-
&change->data.tp.newtuple->tuple,
643+
change->data.tp.newtuple,
644644
false);
645645
break;
646646
case REORDER_BUFFER_CHANGE_UPDATE:
@@ -649,7 +649,7 @@ pg_decode_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
649649
{
650650
appendStringInfoString(ctx->out, " old-key:");
651651
tuple_to_stringinfo(ctx->out, tupdesc,
652-
&change->data.tp.oldtuple->tuple,
652+
change->data.tp.oldtuple,
653653
true);
654654
appendStringInfoString(ctx->out, " new-tuple:");
655655
}
@@ -658,7 +658,7 @@ pg_decode_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
658658
appendStringInfoString(ctx->out, " (no-tuple-data)");
659659
else
660660
tuple_to_stringinfo(ctx->out, tupdesc,
661-
&change->data.tp.newtuple->tuple,
661+
change->data.tp.newtuple,
662662
false);
663663
break;
664664
case REORDER_BUFFER_CHANGE_DELETE:
@@ -670,7 +670,7 @@ pg_decode_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
670670
/* In DELETE, only the replica identity is present; display that */
671671
else
672672
tuple_to_stringinfo(ctx->out, tupdesc,
673-
&change->data.tp.oldtuple->tuple,
673+
change->data.tp.oldtuple,
674674
true);
675675
break;
676676
default:

src/backend/replication/logical/decode.c

+13-13
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static void DecodePrepare(LogicalDecodingContext *ctx, XLogRecordBuffer *buf,
6262

6363

6464
/* common function to decode tuples */
65-
static void DecodeXLogTuple(char *data, Size len, ReorderBufferTupleBuf *tuple);
65+
static void DecodeXLogTuple(char *data, Size len, HeapTuple tuple);
6666

6767
/* helper functions for decoding transactions */
6868
static inline bool FilterPrepare(LogicalDecodingContext *ctx,
@@ -1152,7 +1152,7 @@ DecodeMultiInsert(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
11521152
ReorderBufferChange *change;
11531153
xl_multi_insert_tuple *xlhdr;
11541154
int datalen;
1155-
ReorderBufferTupleBuf *tuple;
1155+
HeapTuple tuple;
11561156
HeapTupleHeader header;
11571157

11581158
change = ReorderBufferGetChange(ctx->reorder);
@@ -1169,21 +1169,21 @@ DecodeMultiInsert(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
11691169
ReorderBufferGetTupleBuf(ctx->reorder, datalen);
11701170

11711171
tuple = change->data.tp.newtuple;
1172-
header = tuple->tuple.t_data;
1172+
header = tuple->t_data;
11731173

11741174
/* not a disk based tuple */
1175-
ItemPointerSetInvalid(&tuple->tuple.t_self);
1175+
ItemPointerSetInvalid(&tuple->t_self);
11761176

11771177
/*
11781178
* We can only figure this out after reassembling the transactions.
11791179
*/
1180-
tuple->tuple.t_tableOid = InvalidOid;
1180+
tuple->t_tableOid = InvalidOid;
11811181

1182-
tuple->tuple.t_len = datalen + SizeofHeapTupleHeader;
1182+
tuple->t_len = datalen + SizeofHeapTupleHeader;
11831183

11841184
memset(header, 0, SizeofHeapTupleHeader);
11851185

1186-
memcpy((char *) tuple->tuple.t_data + SizeofHeapTupleHeader,
1186+
memcpy((char *) tuple->t_data + SizeofHeapTupleHeader,
11871187
(char *) data,
11881188
datalen);
11891189
header->t_infomask = xlhdr->t_infomask;
@@ -1253,22 +1253,22 @@ DecodeSpecConfirm(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
12531253
* computed outside as they are record specific.
12541254
*/
12551255
static void
1256-
DecodeXLogTuple(char *data, Size len, ReorderBufferTupleBuf *tuple)
1256+
DecodeXLogTuple(char *data, Size len, HeapTuple tuple)
12571257
{
12581258
xl_heap_header xlhdr;
12591259
int datalen = len - SizeOfHeapHeader;
12601260
HeapTupleHeader header;
12611261

12621262
Assert(datalen >= 0);
12631263

1264-
tuple->tuple.t_len = datalen + SizeofHeapTupleHeader;
1265-
header = tuple->tuple.t_data;
1264+
tuple->t_len = datalen + SizeofHeapTupleHeader;
1265+
header = tuple->t_data;
12661266

12671267
/* not a disk based tuple */
1268-
ItemPointerSetInvalid(&tuple->tuple.t_self);
1268+
ItemPointerSetInvalid(&tuple->t_self);
12691269

12701270
/* we can only figure this out after reassembling the transactions */
1271-
tuple->tuple.t_tableOid = InvalidOid;
1271+
tuple->t_tableOid = InvalidOid;
12721272

12731273
/* data is not stored aligned, copy to aligned storage */
12741274
memcpy((char *) &xlhdr,
@@ -1277,7 +1277,7 @@ DecodeXLogTuple(char *data, Size len, ReorderBufferTupleBuf *tuple)
12771277

12781278
memset(header, 0, SizeofHeapTupleHeader);
12791279

1280-
memcpy(((char *) tuple->tuple.t_data) + SizeofHeapTupleHeader,
1280+
memcpy(((char *) tuple->t_data) + SizeofHeapTupleHeader,
12811281
data + SizeOfHeapHeader,
12821282
datalen);
12831283

src/backend/replication/logical/reorderbuffer.c

+43-46
Original file line numberDiff line numberDiff line change
@@ -498,13 +498,13 @@ ReorderBufferReturnChange(ReorderBuffer *rb, ReorderBufferChange *change,
498498
case REORDER_BUFFER_CHANGE_INTERNAL_SPEC_INSERT:
499499
if (change->data.tp.newtuple)
500500
{
501-
ReorderBufferReturnTupleBuf(rb, change->data.tp.newtuple);
501+
ReorderBufferReturnTupleBuf(change->data.tp.newtuple);
502502
change->data.tp.newtuple = NULL;
503503
}
504504

505505
if (change->data.tp.oldtuple)
506506
{
507-
ReorderBufferReturnTupleBuf(rb, change->data.tp.oldtuple);
507+
ReorderBufferReturnTupleBuf(change->data.tp.oldtuple);
508508
change->data.tp.oldtuple = NULL;
509509
}
510510
break;
@@ -547,32 +547,29 @@ ReorderBufferReturnChange(ReorderBuffer *rb, ReorderBufferChange *change,
547547
}
548548

549549
/*
550-
* Get a fresh ReorderBufferTupleBuf fitting at least a tuple of size
551-
* tuple_len (excluding header overhead).
550+
* Get a fresh HeapTuple fitting a tuple of size tuple_len (excluding header
551+
* overhead).
552552
*/
553-
ReorderBufferTupleBuf *
553+
HeapTuple
554554
ReorderBufferGetTupleBuf(ReorderBuffer *rb, Size tuple_len)
555555
{
556-
ReorderBufferTupleBuf *tuple;
556+
HeapTuple tuple;
557557
Size alloc_len;
558558

559559
alloc_len = tuple_len + SizeofHeapTupleHeader;
560560

561-
tuple = (ReorderBufferTupleBuf *)
562-
MemoryContextAlloc(rb->tup_context,
563-
sizeof(ReorderBufferTupleBuf) +
564-
MAXIMUM_ALIGNOF + alloc_len);
565-
tuple->alloc_tuple_size = alloc_len;
566-
tuple->tuple.t_data = ReorderBufferTupleBufData(tuple);
561+
tuple = (HeapTuple) MemoryContextAlloc(rb->tup_context,
562+
HEAPTUPLESIZE + alloc_len);
563+
tuple->t_data = (HeapTupleHeader) ((char *) tuple + HEAPTUPLESIZE);
567564

568565
return tuple;
569566
}
570567

571568
/*
572-
* Free a ReorderBufferTupleBuf.
569+
* Free a HeapTuple returned by ReorderBufferGetTupleBuf().
573570
*/
574571
void
575-
ReorderBufferReturnTupleBuf(ReorderBuffer *rb, ReorderBufferTupleBuf *tuple)
572+
ReorderBufferReturnTupleBuf(HeapTuple tuple)
576573
{
577574
pfree(tuple);
578575
}
@@ -3759,8 +3756,8 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
37593756
case REORDER_BUFFER_CHANGE_INTERNAL_SPEC_INSERT:
37603757
{
37613758
char *data;
3762-
ReorderBufferTupleBuf *oldtup,
3763-
*newtup;
3759+
HeapTuple oldtup,
3760+
newtup;
37643761
Size oldlen = 0;
37653762
Size newlen = 0;
37663763

@@ -3770,14 +3767,14 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
37703767
if (oldtup)
37713768
{
37723769
sz += sizeof(HeapTupleData);
3773-
oldlen = oldtup->tuple.t_len;
3770+
oldlen = oldtup->t_len;
37743771
sz += oldlen;
37753772
}
37763773

37773774
if (newtup)
37783775
{
37793776
sz += sizeof(HeapTupleData);
3780-
newlen = newtup->tuple.t_len;
3777+
newlen = newtup->t_len;
37813778
sz += newlen;
37823779
}
37833780

@@ -3790,19 +3787,19 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
37903787

37913788
if (oldlen)
37923789
{
3793-
memcpy(data, &oldtup->tuple, sizeof(HeapTupleData));
3790+
memcpy(data, oldtup, sizeof(HeapTupleData));
37943791
data += sizeof(HeapTupleData);
37953792

3796-
memcpy(data, oldtup->tuple.t_data, oldlen);
3793+
memcpy(data, oldtup->t_data, oldlen);
37973794
data += oldlen;
37983795
}
37993796

38003797
if (newlen)
38013798
{
3802-
memcpy(data, &newtup->tuple, sizeof(HeapTupleData));
3799+
memcpy(data, newtup, sizeof(HeapTupleData));
38033800
data += sizeof(HeapTupleData);
38043801

3805-
memcpy(data, newtup->tuple.t_data, newlen);
3802+
memcpy(data, newtup->t_data, newlen);
38063803
data += newlen;
38073804
}
38083805
break;
@@ -4118,8 +4115,8 @@ ReorderBufferChangeSize(ReorderBufferChange *change)
41184115
case REORDER_BUFFER_CHANGE_DELETE:
41194116
case REORDER_BUFFER_CHANGE_INTERNAL_SPEC_INSERT:
41204117
{
4121-
ReorderBufferTupleBuf *oldtup,
4122-
*newtup;
4118+
HeapTuple oldtup,
4119+
newtup;
41234120
Size oldlen = 0;
41244121
Size newlen = 0;
41254122

@@ -4129,14 +4126,14 @@ ReorderBufferChangeSize(ReorderBufferChange *change)
41294126
if (oldtup)
41304127
{
41314128
sz += sizeof(HeapTupleData);
4132-
oldlen = oldtup->tuple.t_len;
4129+
oldlen = oldtup->t_len;
41334130
sz += oldlen;
41344131
}
41354132

41364133
if (newtup)
41374134
{
41384135
sz += sizeof(HeapTupleData);
4139-
newlen = newtup->tuple.t_len;
4136+
newlen = newtup->t_len;
41404137
sz += newlen;
41414138
}
41424139

@@ -4365,16 +4362,16 @@ ReorderBufferRestoreChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
43654362
ReorderBufferGetTupleBuf(rb, tuplelen - SizeofHeapTupleHeader);
43664363

43674364
/* restore ->tuple */
4368-
memcpy(&change->data.tp.oldtuple->tuple, data,
4365+
memcpy(change->data.tp.oldtuple, data,
43694366
sizeof(HeapTupleData));
43704367
data += sizeof(HeapTupleData);
43714368

43724369
/* reset t_data pointer into the new tuplebuf */
4373-
change->data.tp.oldtuple->tuple.t_data =
4374-
ReorderBufferTupleBufData(change->data.tp.oldtuple);
4370+
change->data.tp.oldtuple->t_data =
4371+
(HeapTupleHeader) ((char *) change->data.tp.oldtuple + HEAPTUPLESIZE);
43754372

43764373
/* restore tuple data itself */
4377-
memcpy(change->data.tp.oldtuple->tuple.t_data, data, tuplelen);
4374+
memcpy(change->data.tp.oldtuple->t_data, data, tuplelen);
43784375
data += tuplelen;
43794376
}
43804377

@@ -4390,16 +4387,16 @@ ReorderBufferRestoreChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
43904387
ReorderBufferGetTupleBuf(rb, tuplelen - SizeofHeapTupleHeader);
43914388

43924389
/* restore ->tuple */
4393-
memcpy(&change->data.tp.newtuple->tuple, data,
4390+
memcpy(change->data.tp.newtuple, data,
43944391
sizeof(HeapTupleData));
43954392
data += sizeof(HeapTupleData);
43964393

43974394
/* reset t_data pointer into the new tuplebuf */
4398-
change->data.tp.newtuple->tuple.t_data =
4399-
ReorderBufferTupleBufData(change->data.tp.newtuple);
4395+
change->data.tp.newtuple->t_data =
4396+
(HeapTupleHeader) ((char *) change->data.tp.newtuple + HEAPTUPLESIZE);
44004397

44014398
/* restore tuple data itself */
4402-
memcpy(change->data.tp.newtuple->tuple.t_data, data, tuplelen);
4399+
memcpy(change->data.tp.newtuple->t_data, data, tuplelen);
44034400
data += tuplelen;
44044401
}
44054402

@@ -4646,7 +4643,7 @@ ReorderBufferToastAppendChunk(ReorderBuffer *rb, ReorderBufferTXN *txn,
46464643
Relation relation, ReorderBufferChange *change)
46474644
{
46484645
ReorderBufferToastEnt *ent;
4649-
ReorderBufferTupleBuf *newtup;
4646+
HeapTuple newtup;
46504647
bool found;
46514648
int32 chunksize;
46524649
bool isnull;
@@ -4661,9 +4658,9 @@ ReorderBufferToastAppendChunk(ReorderBuffer *rb, ReorderBufferTXN *txn,
46614658
Assert(IsToastRelation(relation));
46624659

46634660
newtup = change->data.tp.newtuple;
4664-
chunk_id = DatumGetObjectId(fastgetattr(&newtup->tuple, 1, desc, &isnull));
4661+
chunk_id = DatumGetObjectId(fastgetattr(newtup, 1, desc, &isnull));
46654662
Assert(!isnull);
4666-
chunk_seq = DatumGetInt32(fastgetattr(&newtup->tuple, 2, desc, &isnull));
4663+
chunk_seq = DatumGetInt32(fastgetattr(newtup, 2, desc, &isnull));
46674664
Assert(!isnull);
46684665

46694666
ent = (ReorderBufferToastEnt *)
@@ -4686,7 +4683,7 @@ ReorderBufferToastAppendChunk(ReorderBuffer *rb, ReorderBufferTXN *txn,
46864683
elog(ERROR, "got sequence entry %d for toast chunk %u instead of seq %d",
46874684
chunk_seq, chunk_id, ent->last_chunk_seq + 1);
46884685

4689-
chunk = DatumGetPointer(fastgetattr(&newtup->tuple, 3, desc, &isnull));
4686+
chunk = DatumGetPointer(fastgetattr(newtup, 3, desc, &isnull));
46904687
Assert(!isnull);
46914688

46924689
/* calculate size so we can allocate the right size at once later */
@@ -4737,7 +4734,7 @@ ReorderBufferToastReplace(ReorderBuffer *rb, ReorderBufferTXN *txn,
47374734
Relation toast_rel;
47384735
TupleDesc toast_desc;
47394736
MemoryContext oldcontext;
4740-
ReorderBufferTupleBuf *newtup;
4737+
HeapTuple newtup;
47414738
Size old_size;
47424739

47434740
/* no toast tuples changed */
@@ -4777,7 +4774,7 @@ ReorderBufferToastReplace(ReorderBuffer *rb, ReorderBufferTXN *txn,
47774774

47784775
newtup = change->data.tp.newtuple;
47794776

4780-
heap_deform_tuple(&newtup->tuple, desc, attrs, isnull);
4777+
heap_deform_tuple(newtup, desc, attrs, isnull);
47814778

47824779
for (natt = 0; natt < desc->natts; natt++)
47834780
{
@@ -4842,12 +4839,12 @@ ReorderBufferToastReplace(ReorderBuffer *rb, ReorderBufferTXN *txn,
48424839
{
48434840
bool cisnull;
48444841
ReorderBufferChange *cchange;
4845-
ReorderBufferTupleBuf *ctup;
4842+
HeapTuple ctup;
48464843
Pointer chunk;
48474844

48484845
cchange = dlist_container(ReorderBufferChange, node, it.cur);
48494846
ctup = cchange->data.tp.newtuple;
4850-
chunk = DatumGetPointer(fastgetattr(&ctup->tuple, 3, toast_desc, &cisnull));
4847+
chunk = DatumGetPointer(fastgetattr(ctup, 3, toast_desc, &cisnull));
48514848

48524849
Assert(!cisnull);
48534850
Assert(!VARATT_IS_EXTERNAL(chunk));
@@ -4882,11 +4879,11 @@ ReorderBufferToastReplace(ReorderBuffer *rb, ReorderBufferTXN *txn,
48824879
* the tuplebuf because attrs[] will point back into the current content.
48834880
*/
48844881
tmphtup = heap_form_tuple(desc, attrs, isnull);
4885-
Assert(newtup->tuple.t_len <= MaxHeapTupleSize);
4886-
Assert(ReorderBufferTupleBufData(newtup) == newtup->tuple.t_data);
4882+
Assert(newtup->t_len <= MaxHeapTupleSize);
4883+
Assert(newtup->t_data == (HeapTupleHeader) ((char *) newtup + HEAPTUPLESIZE));
48874884

4888-
memcpy(newtup->tuple.t_data, tmphtup->t_data, tmphtup->t_len);
4889-
newtup->tuple.t_len = tmphtup->t_len;
4885+
memcpy(newtup->t_data, tmphtup->t_data, tmphtup->t_len);
4886+
newtup->t_len = tmphtup->t_len;
48904887

48914888
/*
48924889
* free resources we won't further need, more persistent stuff will be

src/backend/replication/pgoutput/pgoutput.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
14731473
if (change->data.tp.oldtuple)
14741474
{
14751475
old_slot = relentry->old_slot;
1476-
ExecStoreHeapTuple(&change->data.tp.oldtuple->tuple, old_slot, false);
1476+
ExecStoreHeapTuple(change->data.tp.oldtuple, old_slot, false);
14771477

14781478
/* Convert tuple if needed. */
14791479
if (relentry->attrmap)
@@ -1488,7 +1488,7 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
14881488
if (change->data.tp.newtuple)
14891489
{
14901490
new_slot = relentry->new_slot;
1491-
ExecStoreHeapTuple(&change->data.tp.newtuple->tuple, new_slot, false);
1491+
ExecStoreHeapTuple(change->data.tp.newtuple, new_slot, false);
14921492

14931493
/* Convert tuple if needed. */
14941494
if (relentry->attrmap)

0 commit comments

Comments
 (0)