# Why are these two queries perform differently?

**URL:** <https://community.neo4j.com/t/why-are-these-two-queries-perform-differently/29308>\
**Category:** Neo4j Graph Platform\
**Created:** [November 19, 2020, 7:33pm UTC](https://community.neo4j.com/t/why-are-these-two-queries-perform-differently/29308 "2020-11-19T19:33:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lingvisa](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/lingvisa/32/8150_2.png) [@lingvisa](https://community.neo4j.com/u/lingvisa)\
**Post date:** [November 19, 2020, 7:33pm UTC](https://community.neo4j.com/t/why-are-these-two-queries-perform-differently/29308/1 "2020-11-19T19:33:58Z")

</div>

The 1st query:

```auto
MATCH (m)
WHERE m._type = 'Product' and m._name = 'iPhone' 
RETURN properties(m) as properties LIMIT 3

```

And the 2nd one:

```auto
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'?

---

<div class="post-metadata">

**Author:** ![dana\_canzano](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dana_canzano/32/27392_2.png) [@dana\_canzano](https://community.neo4j.com/u/dana_canzano)\
**Post date:** [November 19, 2020, 9:05pm UTC](https://community.neo4j.com/t/why-are-these-two-queries-perform-differently/29308/2 "2020-11-19T21:05:15Z")

</div>

the first statement says effectively

find any node which meets the where condition

whereas the 2nd statement says

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.

---

<div class="post-metadata">

**Author:** ![lingvisa](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/lingvisa/32/8150_2.png) [@lingvisa](https://community.neo4j.com/u/lingvisa)\
**Post date:** [November 19, 2020, 9:09pm UTC](https://community.neo4j.com/t/why-are-these-two-queries-perform-differently/29308/3 "2020-11-19T21:09:19Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dana\_canzano](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dana_canzano/32/27392_2.png) [@dana\_canzano](https://community.neo4j.com/u/dana_canzano)\
**Post date:** [November 19, 2020, 9:31pm UTC](https://community.neo4j.com/t/why-are-these-two-queries-perform-differently/29308/4 "2020-11-19T21:31:55Z")

</div>

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

```auto
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`.

---

<div class="post-metadata">

**Author:** ![lingvisa](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/lingvisa/32/8150_2.png) [@lingvisa](https://community.neo4j.com/u/lingvisa)\
**Post date:** [November 19, 2020, 10:30pm UTC](https://community.neo4j.com/t/why-are-these-two-queries-perform-differently/29308/5 "2020-11-19T22:30:59Z")

</div>

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.
