[1.7.x] Fixed #22847: Optimizer wasn't expecting unresolved FKs