@@ -363,6 +363,7 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
363
363
PGOutputData * data = (PGOutputData * ) ctx -> output_plugin_private ;
364
364
MemoryContext old ;
365
365
RelationSyncEntry * relentry ;
366
+ Relation ancestor = NULL ;
366
367
367
368
if (!is_publishable_relation (relation ))
368
369
return ;
@@ -404,7 +405,8 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
404
405
if (relentry -> publish_as_relid != RelationGetRelid (relation ))
405
406
{
406
407
Assert (relation -> rd_rel -> relispartition );
407
- relation = RelationIdGetRelation (relentry -> publish_as_relid );
408
+ ancestor = RelationIdGetRelation (relentry -> publish_as_relid );
409
+ relation = ancestor ;
408
410
/* Convert tuple if needed. */
409
411
if (relentry -> map )
410
412
tuple = execute_attr_map_tuple (tuple , relentry -> map );
@@ -425,7 +427,8 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
425
427
if (relentry -> publish_as_relid != RelationGetRelid (relation ))
426
428
{
427
429
Assert (relation -> rd_rel -> relispartition );
428
- relation = RelationIdGetRelation (relentry -> publish_as_relid );
430
+ ancestor = RelationIdGetRelation (relentry -> publish_as_relid );
431
+ relation = ancestor ;
429
432
/* Convert tuples if needed. */
430
433
if (relentry -> map )
431
434
{
@@ -448,7 +451,8 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
448
451
if (relentry -> publish_as_relid != RelationGetRelid (relation ))
449
452
{
450
453
Assert (relation -> rd_rel -> relispartition );
451
- relation = RelationIdGetRelation (relentry -> publish_as_relid );
454
+ ancestor = RelationIdGetRelation (relentry -> publish_as_relid );
455
+ relation = ancestor ;
452
456
/* Convert tuple if needed. */
453
457
if (relentry -> map )
454
458
oldtuple = execute_attr_map_tuple (oldtuple , relentry -> map );
@@ -465,6 +469,12 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
465
469
Assert (false);
466
470
}
467
471
472
+ if (RelationIsValid (ancestor ))
473
+ {
474
+ RelationClose (ancestor );
475
+ ancestor = NULL ;
476
+ }
477
+
468
478
/* Cleanup */
469
479
MemoryContextSwitchTo (old );
470
480
MemoryContextReset (data -> context );
0 commit comments