* Parse XLOG_HEAP_INSERT (not MULTI_INSERT!) records into tuplebufs. * * Deletes can contain the new tuple. */
| 845 | * Deletes can contain the new tuple. |
| 846 | */ |
| 847 | static void |
| 848 | DecodeInsert(LogicalDecodingContext *ctx, XLogRecordBuffer *buf) |
| 849 | { |
| 850 | Size datalen; |
| 851 | char *tupledata; |
| 852 | Size tuplelen; |
| 853 | XLogReaderState *r = buf->record; |
| 854 | xl_heap_insert *xlrec; |
| 855 | ReorderBufferChange *change; |
| 856 | RelFileNode target_node; |
| 857 | |
| 858 | xlrec = (xl_heap_insert *) XLogRecGetData(r); |
| 859 | |
| 860 | /* |
| 861 | * Ignore insert records without new tuples (this does happen when |
| 862 | * raw_heap_insert marks the TOAST record as HEAP_INSERT_NO_LOGICAL). |
| 863 | */ |
| 864 | if (!(xlrec->flags & XLH_INSERT_CONTAINS_NEW_TUPLE)) |
| 865 | return; |
| 866 | |
| 867 | /* only interested in our database */ |
| 868 | XLogRecGetBlockTag(r, 0, &target_node, NULL, NULL); |
| 869 | if (target_node.dbNode != ctx->slot->data.database) |
| 870 | return; |
| 871 | |
| 872 | /* output plugin doesn't look for this origin, no need to queue */ |
| 873 | if (FilterByOrigin(ctx, XLogRecGetOrigin(r))) |
| 874 | return; |
| 875 | |
| 876 | change = ReorderBufferGetChange(ctx->reorder); |
| 877 | if (!(xlrec->flags & XLH_INSERT_IS_SPECULATIVE)) |
| 878 | change->action = REORDER_BUFFER_CHANGE_INSERT; |
| 879 | else |
| 880 | change->action = REORDER_BUFFER_CHANGE_INTERNAL_SPEC_INSERT; |
| 881 | change->origin_id = XLogRecGetOrigin(r); |
| 882 | |
| 883 | memcpy(&change->data.tp.relnode, &target_node, sizeof(RelFileNode)); |
| 884 | |
| 885 | tupledata = XLogRecGetBlockData(r, 0, &datalen); |
| 886 | tuplelen = datalen - SizeOfHeapHeader; |
| 887 | |
| 888 | change->data.tp.newtuple = |
| 889 | ReorderBufferGetTupleBuf(ctx->reorder, tuplelen); |
| 890 | |
| 891 | DecodeXLogTuple(tupledata, datalen, change->data.tp.newtuple); |
| 892 | |
| 893 | change->data.tp.clear_toast_afterwards = true; |
| 894 | |
| 895 | ReorderBufferQueueChange(ctx->reorder, XLogRecGetXid(r), buf->origptr, |
| 896 | change, |
| 897 | xlrec->flags & XLH_INSERT_ON_TOAST_RELATION); |
| 898 | } |
| 899 | |
| 900 | /* |
| 901 | * Parse XLOG_HEAP_UPDATE and XLOG_HEAP_HOT_UPDATE, which have the same layout |
no test coverage detected