Backport relation merger updates from 9675c7d to 4-0-stable

Fixes #10995.