@@ -363,6 +363,7 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
363363 PGOutputData * data = (PGOutputData * ) ctx -> output_plugin_private ;
364364 MemoryContext old ;
365365 RelationSyncEntry * relentry ;
366+ Relation ancestor = NULL ;
366367
367368 if (!is_publishable_relation (relation ))
368369 return ;
@@ -404,7 +405,8 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
404405 if (relentry -> publish_as_relid != RelationGetRelid (relation ))
405406 {
406407 Assert (relation -> rd_rel -> relispartition );
407- relation = RelationIdGetRelation (relentry -> publish_as_relid );
408+ ancestor = RelationIdGetRelation (relentry -> publish_as_relid );
409+ relation = ancestor ;
408410 /* Convert tuple if needed. */
409411 if (relentry -> map )
410412 tuple = execute_attr_map_tuple (tuple , relentry -> map );
@@ -425,7 +427,8 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
425427 if (relentry -> publish_as_relid != RelationGetRelid (relation ))
426428 {
427429 Assert (relation -> rd_rel -> relispartition );
428- relation = RelationIdGetRelation (relentry -> publish_as_relid );
430+ ancestor = RelationIdGetRelation (relentry -> publish_as_relid );
431+ relation = ancestor ;
429432 /* Convert tuples if needed. */
430433 if (relentry -> map )
431434 {
@@ -448,7 +451,8 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
448451 if (relentry -> publish_as_relid != RelationGetRelid (relation ))
449452 {
450453 Assert (relation -> rd_rel -> relispartition );
451- relation = RelationIdGetRelation (relentry -> publish_as_relid );
454+ ancestor = RelationIdGetRelation (relentry -> publish_as_relid );
455+ relation = ancestor ;
452456 /* Convert tuple if needed. */
453457 if (relentry -> map )
454458 oldtuple = execute_attr_map_tuple (oldtuple , relentry -> map );
@@ -465,6 +469,12 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
465469 Assert (false);
466470 }
467471
472+ if (RelationIsValid (ancestor ))
473+ {
474+ RelationClose (ancestor );
475+ ancestor = NULL ;
476+ }
477+
468478 /* Cleanup */
469479 MemoryContextSwitchTo (old );
470480 MemoryContextReset (data -> context );
0 commit comments