Query planner logic updated