Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does profile query shows me NodeByLabelScan for a property which has a unique constraint in neo4j?

Tags:

neo4j

cypher

In my neo4j data, I have unique constraint set.

neo4j-sh (?)$ schema
Indexes 
 ON :Post(uuid)                ONLINE (for uniqueness constraint) 
Constraints
 ON (post:Post) ASSERT post.uuid IS UNIQUE

However, when i do a profile on query, it seems search is being done by NodeByLabelScan

    neo4j-sh (?)$ profile match (p:Post {uuid:"503cb957-9da0-490c-808d-48b64a1b1f64"}) return p;
    +---+
    | p | 
    +---+
    +---+
    0 row 
    12 ms

    Compiler CYPHER 2.2 

    Planner COST

    Filter
      |   
      +NodeByLabelScan

    +-----------------+---------------+------+--------+-------------+---------------------------+
    |        Operator | EstimatedRows | Rows | DbHits | Identifiers |                     Other |
    +-----------------+---------------+------+--------+-------------+---------------------------+
    |          Filter |             1 |    0 |      2 |           p | p.uuid == {  AUTOSTRING0} |
    | NodeByLabelScan |             1 |    1 |      2 |           p |                     :Post |
    +-----------------+---------------+------+--------+-------------+---------------------------+

    Total database accesses: 4

Is there something I am missing here?

My neo4j version is 2.2.3.

like image 909
Gaurav Abbi Avatar asked Nov 20 '25 09:11

Gaurav Abbi


1 Answers

Neo4j 2.2 introduced a cost based analyzer. I guess here Cypher has the opinion that a NodeByLabelScan with filtering is faster than a index query due to the small number of nodes.

like image 91
Stefan Armbruster Avatar answered Nov 21 '25 23:11

Stefan Armbruster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!