Query is taking a long time