improve the query performance to collect the node ids