Reputation: 419
Here, by validating, I mean:
- valid: return records
- not valid: no records returned by the query
Is there a built-in function inside neo4j so that I can quickly valid the query without running it. for example, something like schema checking.
What I want to do
quickly valid lots of queries, so that I can get the queries with results. The problem with running all of the queries is that some query can take lots of time to run, which would block the running of some following queries.
Temporary solution
One way I find out is by using LIMIT 1
at the end of the query, it's could be much fast than the one without it when there is lots of records, but still the query is run inside the neo4j database
Thanks,
Upvotes: 0
Views: 683
Reputation: 66967
The only way to see if your query will return anything is to actually run it. But you do not have to run it on your actual ("main") DB.
You can run your query against a smaller test DB whose data model matches the one in your main DB. And you can also tailor the test data so that you know ahead of time what your query should return.
To make this easier, the Neo4j Desktop conveniently allows you to create multiple "projects", each with its own DB.
[EDITED]
To make this process a bit more automated, you should take a look at this example of using APOC procedures to export/import a DB subset. In your case, you would export from your main DB and import into an empty DB. That example's Cypher code randomly picks a limited number of nodes and relationships to copy, but you may want to use more sophisticated Cypher code to ensure you get the data you want.
Upvotes: 1
Reputation: 8546
One option is to prepend your queries with EXPLAIN
and execute that query. EXPLAIN
is used to generate the execution plan for a query, but will also result in metadata by comparing your query to the database statistics. For example, if your query contains a Node Label that is not found in the database a warning will be returned in the metadata. The execution plan will also include estimate rows to be returned at each operation.
You can see all of this metadata in the Neo4j Browser when prepending a query with EXPLAIN
. Using one of the Neo4j client drivers you can access this information in the ResultSummary
object (JavaScript driver doc is linked for example).
Upvotes: 0