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.

Why does using query parameter improve speed?

I am reading through this brilliant articles https://neo4j.com/blog/cypher-write-fast-furious/ and one of the recommendation is to use query parameters e.g. MERGE (p:Person {name:{name} }).
From my understanding, the exact query is hashed and stored as a cache along with its corresponding result and therefore it's quicker the second time you call it.
My confusion is that if the query MERGE (p:Person {name:{name} }) is hashed, then the result corresponding to this hash is useless since name is a variable, but if you interpolate the name (e.g. name='Billy') first before hashing it, then it would be no different to just writing it as MERGE (p:Person {name:"Billy"}).
Based on these confusion, I don't quite get why query parameters is recommended for improving query plan so I think I must have some fundamental misunderstanding about how the caching works.
Would be glad if someone could clarify. Thanks.

1 REPLY 1

anthapu
Graph Fellow

Query caching is fundamentally same as in RDBMS.

The way query caching works is for a given string, it saves the query execution plan. It does not parse the query first before determining if it has query plan. That would take too much time and would not be effective at all.

Think of it as a hash map, with query string as the key and query execution plan as the value.

That's why parameterized queries are always recommended even in RDBMS world, for better performance.