MCPcopy Create free account
hub / github.com/apache/cloudberry / pg_decode_change

Function pg_decode_change

contrib/test_decoding/test_decoding.c:593–678  ·  view source on GitHub ↗

* callback for individual changed tuples */

Source from the content-addressed store, hash-verified

591 * callback for individual changed tuples
592 */
593static void
594pg_decode_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
595 Relation relation, ReorderBufferChange *change)
596{
597 TestDecodingData *data;
598 TestDecodingTxnData *txndata;
599 Form_pg_class class_form;
600 TupleDesc tupdesc;
601 MemoryContext old;
602
603 data = ctx->output_plugin_private;
604 txndata = txn->output_plugin_private;
605
606 /* output BEGIN if we haven't yet */
607 if (data->skip_empty_xacts && !txndata->xact_wrote_changes)
608 {
609 pg_output_begin(ctx, data, txn, false);
610 }
611 txndata->xact_wrote_changes = true;
612
613 class_form = RelationGetForm(relation);
614 tupdesc = RelationGetDescr(relation);
615
616 /* Avoid leaking memory by using and resetting our own context */
617 old = MemoryContextSwitchTo(data->context);
618
619 OutputPluginPrepareWrite(ctx, true);
620
621 appendStringInfoString(ctx->out, "table ");
622 appendStringInfoString(ctx->out,
623 quote_qualified_identifier(get_namespace_name(get_rel_namespace(RelationGetRelid(relation))),
624 class_form->relrewrite ?
625 get_rel_name(class_form->relrewrite) :
626 NameStr(class_form->relname)));
627 appendStringInfoChar(ctx->out, ':');
628
629 switch (change->action)
630 {
631 case REORDER_BUFFER_CHANGE_INSERT:
632 appendStringInfoString(ctx->out, " INSERT:");
633 if (change->data.tp.newtuple == NULL)
634 appendStringInfoString(ctx->out, " (no-tuple-data)");
635 else
636 tuple_to_stringinfo(ctx->out, tupdesc,
637 &change->data.tp.newtuple->tuple,
638 false);
639 break;
640 case REORDER_BUFFER_CHANGE_UPDATE:
641 appendStringInfoString(ctx->out, " UPDATE:");
642 if (change->data.tp.oldtuple != NULL)
643 {
644 appendStringInfoString(ctx->out, " old-key:");
645 tuple_to_stringinfo(ctx->out, tupdesc,
646 &change->data.tp.oldtuple->tuple,
647 true);
648 appendStringInfoString(ctx->out, " new-tuple:");
649 }
650

Callers

nothing calls this directly

Calls 12

pg_output_beginFunction · 0.85
MemoryContextSwitchToFunction · 0.85
OutputPluginPrepareWriteFunction · 0.85
appendStringInfoStringFunction · 0.85
get_namespace_nameFunction · 0.85
get_rel_namespaceFunction · 0.85
get_rel_nameFunction · 0.85
appendStringInfoCharFunction · 0.85
tuple_to_stringinfoFunction · 0.85
MemoryContextResetFunction · 0.85
OutputPluginWriteFunction · 0.85

Tested by

no test coverage detected