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.

Idiomatic Cypher - calculated -versus- pre-computed relationships

russ
Node Link

Hi there

I'm new to Cypher so trying hard to write idiomatic Cypher where possible.

Some of my larger queries were calculating data that, say, only changes once a day, on the fly, e.g. a person's age, and then using that age in a WHERE clause.

I've now realised I can, of course, pre-compute their age and store as a property on the node and do the same for computed relationships. It makes the original queries much smaller and easier to understand, just like refactoring code.

It strikes me this is just weighing up the relative costs of time, space and readability. But is this idiomatic Cypher? Are there other benefits or costs I am overlooking?

Thanks in advance.
Russ

2 REPLIES 2

It can be a valid strategy, when data rarely changes, to cache that as a node property, then have some script or process perform updates at some precomputed time, or a trigger when data changes. As you say this is a tradeoff, you require space for the properties across your nodes, and risk stale data and require some maintenance so the properties stay up to date, but it does make for more concise Cypher than may be more performant since it may avoid costly calculation. Usually you would make this tradeoff choice when there is a clear and significant performance gain to outweigh the maintenance costs of keeping the data up to date.

Thanks Andrew, that was very helpful.