@@ -502,6 +502,7 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
502
502
MemoryContext old ;
503
503
RelationSyncEntry * relentry ;
504
504
TransactionId xid = InvalidTransactionId ;
505
+ Relation ancestor = NULL ;
505
506
506
507
if (!is_publishable_relation (relation ))
507
508
return ;
@@ -552,7 +553,8 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
552
553
if (relentry -> publish_as_relid != RelationGetRelid (relation ))
553
554
{
554
555
Assert (relation -> rd_rel -> relispartition );
555
- relation = RelationIdGetRelation (relentry -> publish_as_relid );
556
+ ancestor = RelationIdGetRelation (relentry -> publish_as_relid );
557
+ relation = ancestor ;
556
558
/* Convert tuple if needed. */
557
559
if (relentry -> map )
558
560
tuple = execute_attr_map_tuple (tuple , relentry -> map );
@@ -574,7 +576,8 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
574
576
if (relentry -> publish_as_relid != RelationGetRelid (relation ))
575
577
{
576
578
Assert (relation -> rd_rel -> relispartition );
577
- relation = RelationIdGetRelation (relentry -> publish_as_relid );
579
+ ancestor = RelationIdGetRelation (relentry -> publish_as_relid );
580
+ relation = ancestor ;
578
581
/* Convert tuples if needed. */
579
582
if (relentry -> map )
580
583
{
@@ -598,7 +601,8 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
598
601
if (relentry -> publish_as_relid != RelationGetRelid (relation ))
599
602
{
600
603
Assert (relation -> rd_rel -> relispartition );
601
- relation = RelationIdGetRelation (relentry -> publish_as_relid );
604
+ ancestor = RelationIdGetRelation (relentry -> publish_as_relid );
605
+ relation = ancestor ;
602
606
/* Convert tuple if needed. */
603
607
if (relentry -> map )
604
608
oldtuple = execute_attr_map_tuple (oldtuple , relentry -> map );
@@ -616,6 +620,12 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
616
620
Assert (false);
617
621
}
618
622
623
+ if (RelationIsValid (ancestor ))
624
+ {
625
+ RelationClose (ancestor );
626
+ ancestor = NULL ;
627
+ }
628
+
619
629
/* Cleanup */
620
630
MemoryContextSwitchTo (old );
621
631
MemoryContextReset (data -> context );
0 commit comments