Optimise finding of relations, partially reversing change #8443 but in