@ -451,7 +451,7 @@ logicalrep_rel_close(LogicalRepRelMapEntry *rel, LOCKMODE lockmode)
static void
static void
logicalrep_partmap_invalidate_cb ( Datum arg , Oid reloid )
logicalrep_partmap_invalidate_cb ( Datum arg , Oid reloid )
{
{
LogicalRepRel MapEntry * entry ;
LogicalRepPart MapEntry * entry ;
/* Just to be sure. */
/* Just to be sure. */
if ( LogicalRepPartMap = = NULL )
if ( LogicalRepPartMap = = NULL )
@ -464,11 +464,11 @@ logicalrep_partmap_invalidate_cb(Datum arg, Oid reloid)
hash_seq_init ( & status , LogicalRepPartMap ) ;
hash_seq_init ( & status , LogicalRepPartMap ) ;
/* TODO, use inverse lookup hashtable? */
/* TODO, use inverse lookup hashtable? */
while ( ( entry = ( LogicalRepRel MapEntry * ) hash_seq_search ( & status ) ) ! = NULL )
while ( ( entry = ( LogicalRepPart MapEntry * ) hash_seq_search ( & status ) ) ! = NULL )
{
{
if ( entry - > localreloid = = reloid )
if ( entry - > relmapentry . localreloid = = reloid )
{
{
entry - > localrelvalid = false ;
entry - > relmapentry . localrelvalid = false ;
hash_seq_term ( & status ) ;
hash_seq_term ( & status ) ;
break ;
break ;
}
}
@ -481,8 +481,8 @@ logicalrep_partmap_invalidate_cb(Datum arg, Oid reloid)
hash_seq_init ( & status , LogicalRepPartMap ) ;
hash_seq_init ( & status , LogicalRepPartMap ) ;
while ( ( entry = ( LogicalRepRel MapEntry * ) hash_seq_search ( & status ) ) ! = NULL )
while ( ( entry = ( LogicalRepPart MapEntry * ) hash_seq_search ( & status ) ) ! = NULL )
entry - > localrelvalid = false ;
entry - > relmapentry . localrelvalid = false ;
}
}
}
}
@ -534,7 +534,6 @@ logicalrep_partition_open(LogicalRepRelMapEntry *root,
Oid partOid = RelationGetRelid ( partrel ) ;
Oid partOid = RelationGetRelid ( partrel ) ;
AttrMap * attrmap = root - > attrmap ;
AttrMap * attrmap = root - > attrmap ;
bool found ;
bool found ;
int i ;
MemoryContext oldctx ;
MemoryContext oldctx ;
if ( LogicalRepPartMap = = NULL )
if ( LogicalRepPartMap = = NULL )
@ -545,15 +544,23 @@ logicalrep_partition_open(LogicalRepRelMapEntry *root,
( void * ) & partOid ,
( void * ) & partOid ,
HASH_ENTER , & found ) ;
HASH_ENTER , & found ) ;
if ( found )
entry = & part_entry - > relmapentry ;
return & part_entry - > relmapentry ;
memset ( part_entry , 0 , sizeof ( LogicalRepPartMapEntry ) ) ;
if ( found & & entry - > localrelvalid )
return entry ;
/* Switch to longer-lived context. */
/* Switch to longer-lived context. */
oldctx = MemoryContextSwitchTo ( LogicalRepPartMapContext ) ;
oldctx = MemoryContextSwitchTo ( LogicalRepPartMapContext ) ;
if ( ! found )
{
memset ( part_entry , 0 , sizeof ( LogicalRepPartMapEntry ) ) ;
part_entry - > partoid = partOid ;
part_entry - > partoid = partOid ;
}
if ( ! entry - > remoterel . remoteid )
{
int i ;
/* Remote relation is copied as-is from the root entry. */
/* Remote relation is copied as-is from the root entry. */
entry = & part_entry - > relmapentry ;
entry = & part_entry - > relmapentry ;
@ -570,6 +577,7 @@ logicalrep_partition_open(LogicalRepRelMapEntry *root,
}
}
entry - > remoterel . replident = remoterel - > replident ;
entry - > remoterel . replident = remoterel - > replident ;
entry - > remoterel . attkeys = bms_copy ( remoterel - > attkeys ) ;
entry - > remoterel . attkeys = bms_copy ( remoterel - > attkeys ) ;
}
entry - > localrel = partrel ;
entry - > localrel = partrel ;
entry - > localreloid = partOid ;
entry - > localreloid = partOid ;
@ -594,6 +602,10 @@ logicalrep_partition_open(LogicalRepRelMapEntry *root,
{
{
AttrNumber root_attno = map - > attnums [ attno ] ;
AttrNumber root_attno = map - > attnums [ attno ] ;
/* 0 means it's a dropped attribute. See comments atop AttrMap. */
if ( root_attno = = 0 )
entry - > attrmap - > attnums [ attno ] = - 1 ;
else
entry - > attrmap - > attnums [ attno ] = attrmap - > attnums [ root_attno - 1 ] ;
entry - > attrmap - > attnums [ attno ] = attrmap - > attnums [ root_attno - 1 ] ;
}
}
}
}