BUG-5222: Optimize SubstatementValidator