@@ -451,7 +451,7 @@ logicalrep_rel_close(LogicalRepRelMapEntry *rel, LOCKMODE lockmode)
451
451
static void
452
452
logicalrep_partmap_invalidate_cb (Datum arg , Oid reloid )
453
453
{
454
- LogicalRepRelMapEntry * entry ;
454
+ LogicalRepPartMapEntry * entry ;
455
455
456
456
/* Just to be sure. */
457
457
if (LogicalRepPartMap == NULL )
@@ -464,11 +464,11 @@ logicalrep_partmap_invalidate_cb(Datum arg, Oid reloid)
464
464
hash_seq_init (& status , LogicalRepPartMap );
465
465
466
466
/* TODO, use inverse lookup hashtable? */
467
- while ((entry = (LogicalRepRelMapEntry * ) hash_seq_search (& status )) != NULL )
467
+ while ((entry = (LogicalRepPartMapEntry * ) hash_seq_search (& status )) != NULL )
468
468
{
469
- if (entry -> localreloid == reloid )
469
+ if (entry -> relmapentry . localreloid == reloid )
470
470
{
471
- entry -> localrelvalid = false;
471
+ entry -> relmapentry . localrelvalid = false;
472
472
hash_seq_term (& status );
473
473
break ;
474
474
}
@@ -481,8 +481,8 @@ logicalrep_partmap_invalidate_cb(Datum arg, Oid reloid)
481
481
482
482
hash_seq_init (& status , LogicalRepPartMap );
483
483
484
- while ((entry = (LogicalRepRelMapEntry * ) hash_seq_search (& status )) != NULL )
485
- entry -> localrelvalid = false;
484
+ while ((entry = (LogicalRepPartMapEntry * ) hash_seq_search (& status )) != NULL )
485
+ entry -> relmapentry . localrelvalid = false;
486
486
}
487
487
}
488
488
@@ -534,7 +534,6 @@ logicalrep_partition_open(LogicalRepRelMapEntry *root,
534
534
Oid partOid = RelationGetRelid (partrel );
535
535
AttrMap * attrmap = root -> attrmap ;
536
536
bool found ;
537
- int i ;
538
537
MemoryContext oldctx ;
539
538
540
539
if (LogicalRepPartMap == NULL )
@@ -545,31 +544,40 @@ logicalrep_partition_open(LogicalRepRelMapEntry *root,
545
544
(void * ) & partOid ,
546
545
HASH_ENTER , & found );
547
546
548
- if (found )
549
- return & part_entry -> relmapentry ;
547
+ entry = & part_entry -> relmapentry ;
550
548
551
- memset (part_entry , 0 , sizeof (LogicalRepPartMapEntry ));
549
+ if (found && entry -> localrelvalid )
550
+ return entry ;
552
551
553
552
/* Switch to longer-lived context. */
554
553
oldctx = MemoryContextSwitchTo (LogicalRepPartMapContext );
555
554
556
- part_entry -> partoid = partOid ;
555
+ if (!found )
556
+ {
557
+ memset (part_entry , 0 , sizeof (LogicalRepPartMapEntry ));
558
+ part_entry -> partoid = partOid ;
559
+ }
557
560
558
- /* Remote relation is copied as-is from the root entry. */
559
- entry = & part_entry -> relmapentry ;
560
- entry -> remoterel .remoteid = remoterel -> remoteid ;
561
- entry -> remoterel .nspname = pstrdup (remoterel -> nspname );
562
- entry -> remoterel .relname = pstrdup (remoterel -> relname );
563
- entry -> remoterel .natts = remoterel -> natts ;
564
- entry -> remoterel .attnames = palloc (remoterel -> natts * sizeof (char * ));
565
- entry -> remoterel .atttyps = palloc (remoterel -> natts * sizeof (Oid ));
566
- for (i = 0 ; i < remoterel -> natts ; i ++ )
561
+ if (!entry -> remoterel .remoteid )
567
562
{
568
- entry -> remoterel .attnames [i ] = pstrdup (remoterel -> attnames [i ]);
569
- entry -> remoterel .atttyps [i ] = remoterel -> atttyps [i ];
563
+ int i ;
564
+
565
+ /* Remote relation is copied as-is from the root entry. */
566
+ entry = & part_entry -> relmapentry ;
567
+ entry -> remoterel .remoteid = remoterel -> remoteid ;
568
+ entry -> remoterel .nspname = pstrdup (remoterel -> nspname );
569
+ entry -> remoterel .relname = pstrdup (remoterel -> relname );
570
+ entry -> remoterel .natts = remoterel -> natts ;
571
+ entry -> remoterel .attnames = palloc (remoterel -> natts * sizeof (char * ));
572
+ entry -> remoterel .atttyps = palloc (remoterel -> natts * sizeof (Oid ));
573
+ for (i = 0 ; i < remoterel -> natts ; i ++ )
574
+ {
575
+ entry -> remoterel .attnames [i ] = pstrdup (remoterel -> attnames [i ]);
576
+ entry -> remoterel .atttyps [i ] = remoterel -> atttyps [i ];
577
+ }
578
+ entry -> remoterel .replident = remoterel -> replident ;
579
+ entry -> remoterel .attkeys = bms_copy (remoterel -> attkeys );
570
580
}
571
- entry -> remoterel .replident = remoterel -> replident ;
572
- entry -> remoterel .attkeys = bms_copy (remoterel -> attkeys );
573
581
574
582
entry -> localrel = partrel ;
575
583
entry -> localreloid = partOid ;
@@ -594,7 +602,11 @@ logicalrep_partition_open(LogicalRepRelMapEntry *root,
594
602
{
595
603
AttrNumber root_attno = map -> attnums [attno ];
596
604
597
- entry -> attrmap -> attnums [attno ] = attrmap -> attnums [root_attno - 1 ];
605
+ /* 0 means it's a dropped attribute. See comments atop AttrMap. */
606
+ if (root_attno == 0 )
607
+ entry -> attrmap -> attnums [attno ] = -1 ;
608
+ else
609
+ entry -> attrmap -> attnums [attno ] = attrmap -> attnums [root_attno - 1 ];
598
610
}
599
611
}
600
612
else
0 commit comments