When to use labels and relation types indexing from Neo4j 4.3?

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.

Regarding relationship type index see The use of indexes - 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

1 Like

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.

@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)

1 Like