Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-17-2020 03:32 AM
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.
03-17-2020 03:55 AM
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.
All the sessions of the conference are now available online