Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-21-2021 03:26 PM
Hi all,
In NODES 2021, label and type indices, available from the 4.3 server, were presented. However, I haven't clear when I should or should not use this kind of indices.
Naively, I tend to think that in most cases, there will be searches like MATCH ( n: ) - [r:] -> (...) so, I'd say it's good to have them in most cases.
But maybe I'm wrong? Maybe they benefit more certain types of queries only?
Thanks in advance for your answer.
06-22-2021 05:04 AM
Regarding relationship type index see The use of indexes - Neo4j Cypher Manual
and to which if you have properties defined in the relationship itself and provided said index exists then running
match (n)-[r:FOLLOWS]->() where r.<property>=<value> return n;
then the index will be used. Where might this be helpful? If for example a node has 20000 :FOLLOWS relationships and each relationship is has a property named status
and for example most relationships (i.e. > 95%) have a status
of active
. If I run
match (n)-[r:FOLLOWS]->() where r.status='inactive' return n;
then the index will be used and rather that interating over all 20k relationships the index will allow us to only iterate over the < 5% of :FOLLOWS relationships for the given node
06-22-2021 05:32 AM
Many thanks, @dana.canzano, now it's clearer.
Regarding the label/relation-type level indices, I infer that they can be useful when expressions involving entity types appear on the WHERE clause and select a subset of entities.
06-22-2021 05:51 AM
@marco.brandizi correct. Without a WHERE clause and restriction on said indexed property the index will not be utiilzied.
A simple
match (n)-[r:FOLLOWS]->() return n;
would not use the index (provided it existed)
All the sessions of the conference are now available online