cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Difference in performance between inline and where clause

Please help me understand how these two queries are different as one with where clause seems to be faster.

profile match (doc1:Document)-[*]->(doc2:Document)
where doc1.uid = "58ad88227faf733d28c8c4ee" and doc2.typeName = "Disease"
return doc2

and

profile match (doc1:Document {uid: "58ad88227faf733d28c8c4ee"})-[*]->(doc2:Document {typeName: "Disease"})
return doc2
1 ACCEPTED SOLUTION

These two queries should have the same query plan right?

They should also both have the same number of DB hits.

What might differ is the elapsed time for each. That would depend on whether you have warmed up the cache and also if the queries needed to be compiled. To truly measure the performance of these two queries that should be the same you can:

  1. Use parameters, rather than constants in your queries where you define a parameter for $uid and $typeName. For example:
    :params {uid: "58ad88227faf733d28c8c4ee" , typeName: "Disease"}
    match (doc1:Document)-->(doc2:Document)
    where doc1.uid = $uid and doc2.typeName = $typeName
    return doc2

  2. Make sure the page cache is sized to be the size of your graph.

  3. Warm up the cache with a statements such as:
    MATCH (n) RETURN max(id(n))
    MATCH ()-[rel]->() RETURN max(id(rel))

  4. Run both queries (without profile) to make sure they are in the query cache.

  5. Finally run each query with profile.

Elaine

View solution in original post

2 REPLIES 2

These two queries should have the same query plan right?

They should also both have the same number of DB hits.

What might differ is the elapsed time for each. That would depend on whether you have warmed up the cache and also if the queries needed to be compiled. To truly measure the performance of these two queries that should be the same you can:

  1. Use parameters, rather than constants in your queries where you define a parameter for $uid and $typeName. For example:
    :params {uid: "58ad88227faf733d28c8c4ee" , typeName: "Disease"}
    match (doc1:Document)-->(doc2:Document)
    where doc1.uid = $uid and doc2.typeName = $typeName
    return doc2

  2. Make sure the page cache is sized to be the size of your graph.

  3. Warm up the cache with a statements such as:
    MATCH (n) RETURN max(id(n))
    MATCH ()-[rel]->() RETURN max(id(rel))

  4. Run both queries (without profile) to make sure they are in the query cache.

  5. Finally run each query with profile.

Elaine

Thank you so much for the suggestions.