Probably this duplication is necessary to rename partition correctly ...
The second CommandCounterIncrement() is needed to make the renamed relation visible within our transaction. Why do we need the first one? I see tests pass without it.
Also, I doubt this is correct in the partitions_listdatum_intersection() function.
foreach_node(Const, val1, list1) { if (val1->constisnull) { if (isnull2) { result = lappend(result, val1); return result; } isnull1 = true; continue; }
The branch handling null value in the outer loop, uses null2 flag from the inner loop. I think for the null value of the outer loop we still need to run inner loop to search for the matching null value.