[1.7.x] Fixed #22960: Bad handling of relations as PKs in autodetector