One thing you could try is creating a temporary graph structure to quickly look up the nodes after foreach. It probably won't be worth it if the tag collection is small, but it's sometimes a useful strategy and until label indices handle IN collection style lookups it may be worth a shot. Basically it means maintaining some small graph structure as a transient (query-local or query-type-local) index. In this case,
- begin the query by creating (query-local) or merging (query-type-local) an index node
- relate all the merged nodes to it
- and when its time to return match from index node to the created nodes
- delete the relationships (and index node if query-local) and return.
I can't test this at the moment, but you could try something like this
CREATE (index)
FOREACH (tagName in {tags} |
MERGE (n:items {classid:tagName.pClassid} )
CREATE index-[:TRANSIENT]->n
)
WITH index
MATCH index-[t:TRANSIENT]->n
DELETE t, index
RETURN n
(This may be overkill for your type of query. If you try it, do try profiling the query in comparison with a re-fetch from label index and post back.)