fix plan of non distributed group by queries

and separate the planning process into two methods to reduce if/else shizzle