MATCH (m)
WHERE m._type = 'Product' and m._name = 'iPhone'
RETURN properties(m) as properties LIMIT 3
And the 2nd one:
MATCH (m:Product)
WHERE m._name = 'iPhone'
RETURN properties(m) as properties LIMIT 3
They are functionally equivalent, but the first one take 130 ms to complete, and the 2nd one takes only 1ms. I have indexes on both '_type' and '_name'. Why isn't the index of '_type' (Product) the same fast as the usage of node label 'Product'?
find a node, that node has a label of :Prodiuct and it meets the where clause.
Because the 2nd statement is for a specific label and one can create an index for a given label then that index may be used to speed up the query.
Since the 1st statement can find any node with any label an index would not be used.
I just profiled and it seems it's right. When no label is specified, index is useless. I don't know about this. 'index' is effective only when a node label is used. Right?
correct.
But I wouldnt say when no label is specified, index is useless or maybe its simply semantics
Lets say I had a 10million nodes and 9 million had a label of :Person and 1 million had a label of :Companies. And all nodes had a property named 'status'. But for whatever reason we only indexed :Companies(status);
And then your query was
match (n)
where n.status='active'
return n;
in the above if we were to use the :Companies index, since there is an index on the property name 'status' but note its only indexed on :Companies, then the above would only report nodes with a label named :Companies and said nodes had a property named status and its value was 'active'. But what about all the :Person nodes which also had a property named status.
In my case, all nodes have a '_type' property, which is actual the node label name and I built an index on that. I had thought query by label and query by that _type filter is almost the same, and learnt that it is not.