Search code examples
neo4jcypherpy2neo

Using Cypher with LIMIT and SKIP: Does Cypher always return data in the same order?


Does cypher always return results from the same query in the same order? (Assuming no modifications are made to the DB between queries?)

So for example:

Query 1: return n LIMIT 100 // returns from 1 to 100?
Query 2: return n SKIP 100 LIMIT 100 // does this return from 101 onwards?

Does query 2 effectively pick-up where query 1 leaves off? I don't want to apply any sorting as I am assuming that this would be counter-productive for performance.

For some background -> I am using py2neo to stream results from a query, but I find that if I return more than 10,000,000 items (with four properties returned per item) then I get an error that py2neo has run out of VM. So what I would like to do is run two separate queries so that I can return all of the information, but preferably without duplicates...hence the above question.


Solution

  • The link says there is no default ordering of how data is saved in graph. If you just do a LIMIT it will just pick first n objects from the underlying set whereas using ORDERBY LIMIT will first order every thing and then give the first n results. More info on this : here.

    So to answer your question, your queries will work until the moment that the underlying graph dataset is modified. Its quite possible the dataset gets modified and then the LIMIT will return a different set of results.