@@ -504,7 +504,12 @@ list_member_parenthood(List *list, Oid relid)
504
504
status = (cached_parenthood_status * ) lfirst (lc );
505
505
506
506
if (status -> relid == relid )
507
+ {
508
+ /* This should NEVER happen! */
509
+ Assert (status -> parenthood_status != PARENTHOOD_NOT_SET );
510
+
507
511
return status -> parenthood_status ;
512
+ }
508
513
}
509
514
510
515
return PARENTHOOD_NOT_SET ;
@@ -562,23 +567,28 @@ assign_rel_parenthood_status(Index query_level,
562
567
/* Search for a parenthood status */
563
568
existing_status = list_member_parenthood (nth_parenthood_list , relid );
564
569
570
+ /* Append new status entry if we couldn't find it */
571
+ if (existing_status == PARENTHOOD_NOT_SET )
572
+ {
573
+ /* Append new element (relid, status) */
574
+ old_mcxt = MemoryContextSwitchTo (TopTransactionContext );
575
+ nth_parenthood_list = lappend_parenthood (nth_parenthood_list ,
576
+ relid , new_status );
577
+ MemoryContextSwitchTo (old_mcxt );
578
+
579
+ /* Update ListCell */
580
+ lfirst (nth_parenthood_cell ) = nth_parenthood_list ;
581
+ }
582
+
565
583
/* Parenthood statuses mismatched, emit an ERROR */
566
- if (existing_status != new_status && existing_status != PARENTHOOD_NOT_SET )
584
+ else if (existing_status != new_status )
567
585
{
568
586
/* Don't forget to clear all lists! */
569
587
reset_parenthood_statuses ();
570
588
571
589
elog (ERROR , "It is prohibited to apply ONLY modifier to partitioned "
572
590
"tables which have already been mentioned without ONLY" );
573
591
}
574
-
575
- /* Append new element (relid, status) */
576
- old_mcxt = MemoryContextSwitchTo (TopTransactionContext );
577
- nth_parenthood_list = lappend_parenthood (nth_parenthood_list , relid , new_status );
578
- MemoryContextSwitchTo (old_mcxt );
579
-
580
- /* Update ListCell */
581
- lfirst (nth_parenthood_cell ) = nth_parenthood_list ;
582
592
}
583
593
584
594
/* Get parenthood status (per query level) */
0 commit comments