optimize queries for graph selection