The use of indexes
The task of tuning calls for different indexes depending on what the queries look like. Therefore, it is important to have a fundamental understanding of how the indexes operate. This section describes the query plans that result from different index scenarios.
Node indexes and relationship indexes operate in the same way. Therefore, node and relationship indexes are used interchangeably in this section.
Please refer to Indexes for search performance for instructions on how to create and maintain the indexes themselves.
Node index example
In the example below, the query uses a Person(firstname)
node index, if it exists.
MATCH (person:Person {firstname: 'Andy'}) RETURN person
Compiler CYPHER 4.3
Planner COST
Runtime PIPELINED
Runtime version 4.3
+-----------------+----------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| Operator | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Other |
+-----------------+----------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| +ProduceResults | person | 1 | 1 | 0 | | | | Fused in Pipeline 0 |
| | +----------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +NodeIndexSeek | person:Person(firstname) WHERE firstname = $autostring_0 | 1 | 1 | 2 | 72 | 2/1 | 0.976 | Fused in Pipeline 0 |
+-----------------+----------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
Total database accesses: 2, total allocated memory: 136
Relationship index example
In this example, the query uses a KNOWS(since)
relationship index, if it exists.
MATCH (person)-[relationship:KNOWS { since: 1992 } ]->(friend) RETURN person, friend
Compiler CYPHER 4.3
Planner COST
Runtime PIPELINED
Runtime version 4.3
+--------------------------------+-------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| Operator | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Other |
+--------------------------------+-------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| +ProduceResults | person, friend | 1 | 1 | 0 | | | | Fused in Pipeline 0 |
| | +-------------------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +DirectedRelationshipIndexSeek | (person)-[relationship:KNOWS(since)]->(friend) WHERE since = $autoint_0 | 1 | 1 | 3 | 72 | 2/1 | 0.473 | Fused in Pipeline 0 |
+--------------------------------+-------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
Total database accesses: 3, total allocated memory: 136
Equality check using WHERE
(single-property index)
A query containing equality comparisons of a single indexed property in the WHERE
clause is backed automatically by the index. It is also possible for a query with multiple OR
predicates to use multiple indexes, if indexes exist on the properties. For example, if indexes exist on both :Label(p1)
and :Label(p2)
, MATCH (n:Label) WHERE n.p1 = 1 OR n.p2 = 2 RETURN n
will use both indexes.
MATCH (person:Person) WHERE person.firstname = 'Andy' RETURN person
Compiler CYPHER 4.3
Planner COST
Runtime PIPELINED
Runtime version 4.3
+-----------------+----------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| Operator | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Other |
+-----------------+----------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| +ProduceResults | person | 1 | 1 | 0 | | | | Fused in Pipeline 0 |
| | +----------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +NodeIndexSeek | person:Person(firstname) WHERE firstname = $autostring_0 | 1 | 1 | 2 | 72 | 2/1 | 0.514 | Fused in Pipeline 0 |
+-----------------+----------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
Total database accesses: 2, total allocated memory: 136
Equality check using WHERE
(composite index)
A query containing equality comparisons for all the properties of a composite index will automatically be backed by the same index. However, the query does not need to have equality on all properties. It can have ranges and existence predicates as well. But in these cases rewrites might happen depending on which properties have which predicates, see composite index limitations. The following query will use the composite index defined earlier:
MATCH (n:Person) WHERE n.age = 35 AND n.country = 'UK' RETURN n
However, the query MATCH (n:Person) WHERE n.age = 35 RETURN n
will not be backed by the composite index, as the query does not contain a predicate on the country
property. It will only be backed by an index on the Person
label and age
property defined thus: :Person(age)
; i.e. a single-property index.
+-------------------------------------------------------------------------------------------+
| n |
+-------------------------------------------------------------------------------------------+
| Node[0]{country:"UK",firstname:"John",highScore:54321,surname:"Smith",name:"john",age:35} |
+-------------------------------------------------------------------------------------------+
1 row
Range comparisons using WHERE
(single-property index)
Single-property indexes are also automatically used for inequality (range) comparisons of an indexed property in the WHERE
clause.
MATCH (friend)<-[r:KNOWS]-(person) WHERE r.since < 2011 RETURN friend, person
Compiler CYPHER 4.3
Planner COST
Runtime PIPELINED
Runtime version 4.3
+---------------------------------------+--------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| Operator | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Other |
+---------------------------------------+--------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| +ProduceResults | friend, person | 1 | 1 | 0 | | | | Fused in Pipeline 0 |
| | +--------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +DirectedRelationshipIndexSeekByRange | (person)-[r:KNOWS(since)]->(friend) WHERE since < $autoint_0 | 1 | 1 | 3 | 72 | 2/1 | 0.543 | Fused in Pipeline 0 |
+---------------------------------------+--------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
Total database accesses: 3, total allocated memory: 136
Range comparisons using WHERE
(composite index)
Composite indexes are also automatically used for inequality (range) comparisons of indexed properties in the WHERE
clause. Equality or list membership check predicates may precede the range predicate. However, predicates after the range predicate may be rewritten as an existence check predicate and a filter as described in composite index limitations.
MATCH ()-[r:KNOWS]-() WHERE r.since < 2011 AND r.lastMet > 2019 RETURN r.since
Compiler CYPHER 4.3
Planner COST
Runtime PIPELINED
Runtime version 4.3
+----------------------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| Operator | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Other |
+----------------------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| +ProduceResults | `r.since` | 4 | 2 | 0 | | | | Fused in Pipeline 0 |
| | +------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +Projection | cache[r.since] AS `r.since` | 4 | 2 | 0 | | | | Fused in Pipeline 0 |
| | +------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +Filter | cache[r.lastMet] > $autoint_1 | 4 | 2 | 0 | | | | Fused in Pipeline 0 |
| | +------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +UndirectedRelationshipIndexSeek | (anon_0)-[r:KNOWS(since, lastMet)]-(anon_1) WHERE since < $autoint_0 AND lastMet IS NOT NULL, cache[ | 7 | 2 | 3 | 72 | 1/1 | 1.207 | Fused in Pipeline 0 |
| | r.since], cache[r.lastMet] | | | | | | | |
+----------------------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
Total database accesses: 3, total allocated memory: 136
Multiple range comparisons using WHERE
(single-property index)
When the WHERE
clause contains multiple inequality (range) comparisons for the same property, these can be combined in a single index range seek.
MATCH (person:Person) WHERE 10000 < person.highScore < 20000 RETURN person
Compiler CYPHER 4.3
Planner COST
Runtime PIPELINED
Runtime version 4.3
+-----------------------+----------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| Operator | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Other |
+-----------------------+----------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| +ProduceResults | person | 1 | 1 | 0 | | | | Fused in Pipeline 0 |
| | +----------------------------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +NodeIndexSeekByRange | person:Person(highScore) WHERE highScore > $autoint_0 AND highScore < $autoint_1 | 1 | 1 | 2 | 72 | 2/1 | 0.471 | Fused in Pipeline 0 |
+-----------------------+----------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
Total database accesses: 2, total allocated memory: 136
Multiple range comparisons using WHERE
(composite index)
When the WHERE
clause contains multiple inequality (range) comparisons for the same property, these can be combined in a single index range seek. That single range seek created in the following query will then use the composite index Person(highScore, name)
if it exists.
MATCH (person:Person) WHERE 10000 < person.highScore < 20000 AND person.name IS NOT NULL RETURN
person
Compiler CYPHER 4.3
Planner COST
Runtime PIPELINED
Runtime version 4.3
+-----------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| Operator | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Other |
+-----------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| +ProduceResults | person | 1 | 1 | 0 | | | | Fused in Pipeline 0 |
| | +------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +NodeIndexSeek | person:Person(highScore, name) WHERE highScore > $autoint_0 AND highScore < $autoint_1 AND name IS N | 1 | 1 | 2 | 72 | 2/1 | 13.696 | Fused in Pipeline 0 |
| | OT NULL | | | | | | | |
+-----------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
Total database accesses: 2, total allocated memory: 136
List membership check using IN
(single-property index)
The IN
predicate on r.since
in the following query will use the single-property index KNOWS(since)
if it exists.
MATCH (person)-[r:KNOWS]->(friend) WHERE r.since IN [1992, 2017] RETURN person, friend
Compiler CYPHER 4.3
Planner COST
Runtime PIPELINED
Runtime version 4.3
+--------------------------------+----------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| Operator | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Other |
+--------------------------------+----------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| +ProduceResults | person, friend | 1 | 1 | 0 | | | | Fused in Pipeline 0 |
| | +----------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +DirectedRelationshipIndexSeek | (person)-[r:KNOWS(since)]->(friend) WHERE since IN $autolist_0 | 1 | 1 | 4 | 72 | 3/1 | 1.206 | Fused in Pipeline 0 |
+--------------------------------+----------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
Total database accesses: 4, total allocated memory: 136
List membership check using IN
(composite index)
The IN
predicates on r.since
and r.lastMet
in the following query will use the composite index KNOWS(since, lastMet)
if it exists.
MATCH (person)-[r:KNOWS]->(friend) WHERE r.since IN [1992, 2017] AND r.lastMet IN [2002,
2021] RETURN person, friend
Compiler CYPHER 4.3
Planner COST
Runtime PIPELINED
Runtime version 4.3
+--------------------------------+----------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| Operator | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Other |
+--------------------------------+----------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| +ProduceResults | person, friend | 5 | 1 | 0 | | | | Fused in Pipeline 0 |
| | +----------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +DirectedRelationshipIndexSeek | (person)-[r:KNOWS(since, lastMet)]->(friend) WHERE since IN $autolist_0 AND lastMet IN $autolist_1 | 5 | 1 | 6 | 72 | 5/1 | 5.452 | Fused in Pipeline 0 |
+--------------------------------+----------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
Total database accesses: 6, total allocated memory: 136
Prefix search using STARTS WITH
(single-property index)
The STARTS WITH
predicate on person.firstname
in the following query will use the Person(firstname)
index, if it exists.
MATCH (person:Person) WHERE person.firstname STARTS WITH 'And' RETURN person
Compiler CYPHER 4.3
Planner COST
Runtime PIPELINED
Runtime version 4.3
+-----------------------+--------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| Operator | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Other |
+-----------------------+--------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| +ProduceResults | person | 2 | 1 | 0 | | | | Fused in Pipeline 0 |
| | +--------------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +NodeIndexSeekByRange | person:Person(firstname) WHERE firstname STARTS WITH $autostring_0 | 2 | 1 | 2 | 72 | 3/0 | 0.514 | Fused in Pipeline 0 |
+-----------------------+--------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
Total database accesses: 2, total allocated memory: 136
Prefix search using STARTS WITH
(composite index)
The STARTS WITH
predicate on person.firstname
in the following query will use the Person(firstname,surname)
index, if it exists. Any (non-existence check) predicate on person.surname
will be rewritten as existence check with a filter. However, if the predicate on person.firstname
is a equality check then a STARTS WITH
on person.surname
would also use the index (without rewrites). More information about how the rewriting works can be found in composite index limitations.
MATCH (person:Person) WHERE person.firstname STARTS WITH 'And' AND person.surname IS NOT NULL RETURN
person
Compiler CYPHER 4.3
Planner COST
Runtime PIPELINED
Runtime version 4.3
+-----------------+-----------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| Operator | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Other |
+-----------------+-----------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| +ProduceResults | person | 1 | 1 | 0 | | | | Fused in Pipeline 0 |
| | +-----------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +NodeIndexSeek | person:Person(firstname, surname) WHERE firstname STARTS WITH $autostring_0 AND surname IS NOT NULL | 1 | 1 | 2 | 72 | 3/0 | 2.998 | Fused in Pipeline 0 |
+-----------------+-----------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
Total database accesses: 2, total allocated memory: 136
Suffix search using ENDS WITH
(single-property index)
The ENDS WITH
predicate on r.metIn
in the following query uses the KNOWS(metIn)
index, if it exists. All values stored in the KNOWS(metIn)
index are searched, and entries ending with 'mo'
are returned. This means that although the search is not optimized to the extent of queries using =
, IN
, >
, <
or STARTS WITH
, it is still faster than not using an index in the first place.
MATCH (person)-[r:KNOWS]->(friend) WHERE r.metIn ENDS WITH 'mo' RETURN person, friend
Compiler CYPHER 4.3
Planner COST
Runtime PIPELINED
Runtime version 4.3
+----------------------------------------+-------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| Operator | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Other |
+----------------------------------------+-------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| +ProduceResults | person, friend | 0 | 1 | 0 | | | | Fused in Pipeline 0 |
| | +-------------------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +DirectedRelationshipIndexEndsWithScan | (person)-[r:KNOWS(metIn)]->(friend) WHERE metIn ENDS WITH $autostring_0 | 0 | 1 | 3 | 72 | 2/1 | 0.517 | Fused in Pipeline 0 |
+----------------------------------------+-------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
Total database accesses: 3, total allocated memory: 136
Suffix search using ENDS WITH
(composite index)
The ENDS WITH
predicate on r.metIn
in the following query uses the KNOWS(metIn,lastMetIn)
index, if it exists. However, it is rewritten as existence check and a filter due to the index not supporting actual suffix searches for composite indexes, this is still faster than not using an index in the first place. Any (non-existence check) predicate on KNOWS.lastMetIn
is also rewritten as existence check with a filter. More information about how the rewriting works can be found in composite index limitations.
MATCH (person)-[r:KNOWS]->(friend) WHERE r.metIn ENDS WITH 'mo' AND r.lastMetIn IS NOT NULL RETURN
person,
friend
Compiler CYPHER 4.3
Planner COST
Runtime PIPELINED
Runtime version 4.3
+--------------------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| Operator | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Other |
+--------------------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| +ProduceResults | person, friend | 1 | 1 | 0 | | | | Fused in Pipeline 0 |
| | +------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +Filter | cache[r.metIn] ENDS WITH $autostring_0 | 1 | 1 | 0 | | | | Fused in Pipeline 0 |
| | +------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +DirectedRelationshipIndexScan | (person)-[r:KNOWS(metIn, lastMetIn)]->(friend) WHERE metIn IS NOT NULL AND lastMetIn IS NOT NULL, ca | 6 | 1 | 3 | 72 | 2/1 | 0.490 | Fused in Pipeline 0 |
| | che[r.metIn] | | | | | | | |
+--------------------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
Total database accesses: 3, total allocated memory: 136
Substring search using CONTAINS
(single-property index)
The CONTAINS
predicate on person.firstname
in the following query will use the Person(firstname)
index, if it exists. All values stored in the Person(firstname)
index will be searched, and entries containing 'h'
will be returned. This means that although the search will not be optimized to the extent of queries using =
, IN
, >
, <
or STARTS WITH
, it is still faster than not using an index in the first place. Composite indexes are currently not able to support CONTAINS
.
MATCH (person:Person) WHERE person.firstname CONTAINS 'h' RETURN person
Compiler CYPHER 4.3
Planner COST
Runtime PIPELINED
Runtime version 4.3
+------------------------+-----------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| Operator | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Other |
+------------------------+-----------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| +ProduceResults | person | 2 | 1 | 0 | | | | Fused in Pipeline 0 |
| | +-----------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +NodeIndexContainsScan | person:Person(firstname) WHERE firstname CONTAINS $autostring_0 | 2 | 1 | 2 | 72 | 3/0 | 0.953 | Fused in Pipeline 0 |
+------------------------+-----------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
Total database accesses: 2, total allocated memory: 136
Substring search using CONTAINS
(composite index)
The CONTAINS
predicate on person.surname
in the following query will use the Person(surname,age)
index, if it exists. However, it will be rewritten as existence check and a filter due to the index not supporting actual suffix searches for composite indexes, this is still faster than not using an index in the first place. Any (non-existence check) predicate on person.age
will also be rewritten as existence check with a filter. More information about how the rewriting works can be found in composite index limitations.
MATCH (person:Person) WHERE person.surname CONTAINS '300' AND person.age IS NOT NULL RETURN person
Compiler CYPHER 4.3
Planner COST
Runtime PIPELINED
Runtime version 4.3
+-----------------+--------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| Operator | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Other |
+-----------------+--------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| +ProduceResults | person | 11 | 1 | 0 | | | | Fused in Pipeline 0 |
| | +--------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +Filter | cache[person.surname] CONTAINS $autostring_0 | 11 | 1 | 0 | | | | Fused in Pipeline 0 |
| | +--------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +NodeIndexScan | person:Person(surname, age) WHERE surname IS NOT NULL AND age IS NOT NULL, cache[person.surname] | 111 | 303 | 304 | 72 | 5/0 | 2.546 | Fused in Pipeline 0 |
+-----------------+--------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
Total database accesses: 304, total allocated memory: 136
Existence check using IS NOT NULL
(single-property index)
The r.since IS NOT NULL
predicate in the following query uses the KNOWS(since)
index, if it exists.
MATCH (person)-[r:KNOWS]->(friend) WHERE r.since IS NOT NULL RETURN person, friend
Compiler CYPHER 4.3
Planner COST
Runtime PIPELINED
Runtime version 4.3
+--------------------------------+-------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| Operator | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Other |
+--------------------------------+-------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| +ProduceResults | person, friend | 1 | 1 | 0 | | | | Fused in Pipeline 0 |
| | +-------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +DirectedRelationshipIndexScan | (person)-[r:KNOWS(since)]->(friend) WHERE since IS NOT NULL | 1 | 1 | 3 | 72 | 2/1 | 0.417 | Fused in Pipeline 0 |
+--------------------------------+-------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
Total database accesses: 3, total allocated memory: 136
Existence check using IS NOT NULL
(composite index)
The p.firstname IS NOT NULL
and p.surname IS NOT NULL
predicates in the following query will use the Person(firstname,surname)
index, if it exists. Any (non-existence check) predicate on person.surname
will be rewritten as existence check with a filter.
MATCH (p:Person) WHERE p.firstname IS NOT NULL AND p.surname IS NOT NULL RETURN p
Compiler CYPHER 4.3
Planner COST
Runtime PIPELINED
Runtime version 4.3
+-----------------+----------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| Operator | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Other |
+-----------------+----------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| +ProduceResults | p | 1 | 2 | 0 | | | | Fused in Pipeline 0 |
| | +----------------------------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +NodeIndexScan | p:Person(firstname, surname) WHERE firstname IS NOT NULL AND surname IS NOT NULL | 1 | 2 | 3 | 72 | 2/1 | 0.633 | Fused in Pipeline 0 |
+-----------------+----------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
Total database accesses: 3, total allocated memory: 136
Spatial distance searches (single-property index)
If a property with point values is indexed, the index is used for spatial distance searches as well as for range queries.
MATCH ()-[r:KNOWS]->() WHERE distance(r.lastMetPoint, point({x: 1, y: 2})) < 2 RETURN r.lastMetPoint
Compiler CYPHER 4.3
Planner COST
Runtime PIPELINED
Runtime version 4.3
+---------------------------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| Operator | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Other |
+---------------------------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| +ProduceResults | `r.lastMetPoint` | 13 | 9 | 0 | | | | Fused in Pipeline 0 |
| | +------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +Projection | cache[r.lastMetPoint] AS `r.lastMetPoint` | 13 | 9 | 0 | | | | Fused in Pipeline 0 |
| | +------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +Filter | distance(cache[r.lastMetPoint], point({x: $autoint_0, y: $autoint_1})) < $autoint_2 | 13 | 9 | 0 | | | | Fused in Pipeline 0 |
| | +------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +DirectedRelationshipIndexSeekByRange | (anon_0)-[r:KNOWS(lastMetPoint)]->(anon_1) WHERE distance(lastMetPoint, point($autoint_0, $autoint_1 | 13 | 9 | 19 | 72 | 5/3 | 1.774 | Fused in Pipeline 0 |
| | )) < $autoint_2, cache[r.lastMetPoint] | | | | | | | |
+---------------------------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
Total database accesses: 19, total allocated memory: 136
Spatial distance searches (composite index)
If a property with point values is indexed, the index is used for spatial distance searches as well as for range queries. Any following (non-existence check) predicates (here on property p.name
for index :Person(place,name)
) will be rewritten as existence check with a filter.
MATCH (p:Person) WHERE distance(p.place, point({x: 1,
y: 2})) < 2 AND p.name IS NOT NULL RETURN p.place
Compiler CYPHER 4.3
Planner COST
Runtime PIPELINED
Runtime version 4.3
+-----------------+-----------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| Operator | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Other |
+-----------------+-----------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| +ProduceResults | `p.place` | 72 | 9 | 0 | | | | Fused in Pipeline 0 |
| | +-----------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +Projection | cache[p.place] AS `p.place` | 72 | 9 | 0 | | | | Fused in Pipeline 0 |
| | +-----------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +Filter | distance(cache[p.place], point({x: $autoint_0, y: $autoint_1})) < $autoint_2 | 72 | 9 | 0 | | | | Fused in Pipeline 0 |
| | +-----------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +NodeIndexSeek | p:Person(place, name) WHERE distance(place, point($autoint_0, $autoint_1)) < $autoint_2 AND name IS | 72 | 9 | 10 | 72 | 6/0 | 2.964 | Fused in Pipeline 0 |
| | NOT NULL, cache[p.place] | | | | | | | |
+-----------------+-----------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
Total database accesses: 10, total allocated memory: 136
Spatial bounding box searches (single-property index)
The ability to do index seeks on bounded ranges works even with the 2D and 3D spatial Point
types.
MATCH (person:Person) WHERE point({x: 1, y: 5}) < person.location < point({x: 2, y: 6}) RETURN person
Compiler CYPHER 4.3
Planner COST
Runtime PIPELINED
Runtime version 4.3
+-----------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| Operator | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Other |
+-----------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| +ProduceResults | person | 0 | 1 | 0 | | | | Fused in Pipeline 0 |
| | +------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +NodeIndexSeekByRange | person:Person(location) WHERE location > point({x: $autoint_0, y: $autoint_1}) AND location < point( | 0 | 1 | 2 | 72 | 8/0 | 11.041 | Fused in Pipeline 0 |
| | {x: $autoint_2, y: $autoint_3}) | | | | | | | |
+-----------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
Total database accesses: 2, total allocated memory: 136
Spatial bounding box searches (composite index)
The ability to do index seeks on bounded ranges works even with the 2D and 3D spatial Point
types. Any following (non-existence check) predicates (here on property p.firstname
for index :Person(place,firstname)
) will be rewritten as existence check with a filter. For index :Person(firstname,place)
, if the predicate on firstname
is equality or list membership then the bounded range is handled as a range itself. If the predicate on firstname
is anything else then the bounded range is rewritten to existence and filter.
MATCH (person:Person) WHERE point({x: 1, y: 5}) < person.place < point({x: 2,
y: 6}) AND person.firstname IS NOT NULL RETURN person
Compiler CYPHER 4.3
Planner COST
Runtime PIPELINED
Runtime version 4.3
+-----------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| Operator | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Other |
+-----------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| +ProduceResults | person | 0 | 1 | 0 | | | | Fused in Pipeline 0 |
| | +------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+ | +---------------------+
| +NodeIndexSeek | person:Person(place, firstname) WHERE place > point({x: $autoint_0, y: $autoint_1}) AND place < poin | 0 | 1 | 2 | 72 | 8/0 | 1.554 | Fused in Pipeline 0 |
| | t({x: $autoint_2, y: $autoint_3}) AND firstname IS NOT NULL | | | | | | | |
+-----------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
Total database accesses: 2, total allocated memory: 136