query before generate