The use of indexes

This section describes the query plans when indexes are used in various scenarios.

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.

1. Node index example

In the example below, the query uses a Person(firstname) node index, if it exists.

Query
MATCH (person:Person {firstname: 'Andy'}) RETURN person
Query Plan
Compiler CYPHER 4.3

Planner COST

Runtime INTERPRETED

Runtime version 4.3

+-----------------+----------------------------------------------------------+----------------+------+---------+------------------------+
| Operator        | Details                                                  | Estimated Rows | Rows | DB Hits | Page Cache Hits/Misses |
+-----------------+----------------------------------------------------------+----------------+------+---------+------------------------+
| +ProduceResults | person                                                   |              1 |    1 |       0 |                    0/0 |
| |               +----------------------------------------------------------+----------------+------+---------+------------------------+
| +NodeIndexSeek  | person:Person(firstname) WHERE firstname = $autostring_0 |              1 |    1 |       2 |                    0/0 |
+-----------------+----------------------------------------------------------+----------------+------+---------+------------------------+

Total database accesses: 2, total allocated memory: 64

2. Relationship index example

In this example, the query uses a KNOWS(since) relationship index, if it exists.

Query
MATCH (person)-[relationship:KNOWS { since: 1992 } ]->(friend) RETURN person, friend
Query Plan
Compiler CYPHER 4.3

Planner COST

Runtime INTERPRETED

Runtime version 4.3

+--------------------------------+-------------------------------------------------------------------------+----------------+------+---------+------------------------+
| Operator                       | Details                                                                 | Estimated Rows | Rows | DB Hits | Page Cache Hits/Misses |
+--------------------------------+-------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +ProduceResults                | person, friend                                                          |              1 |    1 |       0 |                    0/0 |
| |                              +-------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +DirectedRelationshipIndexSeek | (person)-[relationship:KNOWS(since)]->(friend) WHERE since = $autoint_0 |              1 |    1 |       2 |                    0/0 |
+--------------------------------+-------------------------------------------------------------------------+----------------+------+---------+------------------------+

Total database accesses: 2, total allocated memory: 64

3. 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.

Query
MATCH (person:Person) WHERE person.firstname = 'Andy' RETURN person
Query Plan
Compiler CYPHER 4.3

Planner COST

Runtime INTERPRETED

Runtime version 4.3

+-----------------+----------------------------------------------------------+----------------+------+---------+------------------------+
| Operator        | Details                                                  | Estimated Rows | Rows | DB Hits | Page Cache Hits/Misses |
+-----------------+----------------------------------------------------------+----------------+------+---------+------------------------+
| +ProduceResults | person                                                   |              1 |    1 |       0 |                    0/0 |
| |               +----------------------------------------------------------+----------------+------+---------+------------------------+
| +NodeIndexSeek  | person:Person(firstname) WHERE firstname = $autostring_0 |              1 |    1 |       2 |                    0/0 |
+-----------------+----------------------------------------------------------+----------------+------+---------+------------------------+

Total database accesses: 2, total allocated memory: 64

4. 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:

Query
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

5. 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.

Query
MATCH (friend)<-[r:KNOWS]-(person) WHERE r.since < 2011 RETURN friend, person
Query Plan
Compiler CYPHER 4.3

Planner COST

Runtime INTERPRETED

Runtime version 4.3

+---------------------------------------+--------------------------------------------------------------+----------------+------+---------+------------------------+
| Operator                              | Details                                                      | Estimated Rows | Rows | DB Hits | Page Cache Hits/Misses |
+---------------------------------------+--------------------------------------------------------------+----------------+------+---------+------------------------+
| +ProduceResults                       | friend, person                                               |              1 |    1 |       0 |                    0/0 |
| |                                     +--------------------------------------------------------------+----------------+------+---------+------------------------+
| +DirectedRelationshipIndexSeekByRange | (person)-[r:KNOWS(since)]->(friend) WHERE since < $autoint_0 |              1 |    1 |       2 |                    0/0 |
+---------------------------------------+--------------------------------------------------------------+----------------+------+---------+------------------------+

Total database accesses: 2, total allocated memory: 64

6. 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.

Query
MATCH ()-[r:KNOWS]-() WHERE r.since < 2011 AND r.lastMet > 2019 RETURN r.since
Query Plan
Compiler CYPHER 4.3

Planner COST

Runtime INTERPRETED

Runtime version 4.3

+----------------------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| Operator                         | Details                                                                                              | Estimated Rows | Rows | DB Hits | Page Cache Hits/Misses |
+----------------------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +ProduceResults                  | `r.since`                                                                                            |              4 |    2 |       0 |                    0/0 |
| |                                +------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +Projection                      | cache[r.since] AS `r.since`                                                                          |              4 |    2 |       0 |                    0/0 |
| |                                +------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +Filter                          | cache[r.lastMet] > $autoint_1                                                                        |              4 |    2 |       0 |                    0/0 |
| |                                +------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +UndirectedRelationshipIndexSeek | (anon_6)-[r:KNOWS(since, lastMet)]-(anon_19) WHERE since < $autoint_0 AND lastMet IS NOT NULL, cache |              7 |    2 |       2 |                    0/0 |
|                                  | [r.since], cache[r.lastMet]                                                                          |                |      |         |                        |
+----------------------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+

Total database accesses: 2, total allocated memory: 64

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

Query
MATCH (person:Person) WHERE 10000 < person.highScore < 20000 RETURN person
Query Plan
Compiler CYPHER 4.3

Planner COST

Runtime INTERPRETED

Runtime version 4.3

+-----------------------+----------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| Operator              | Details                                                                          | Estimated Rows | Rows | DB Hits | Page Cache Hits/Misses |
+-----------------------+----------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +ProduceResults       | person                                                                           |              1 |    1 |       0 |                    0/0 |
| |                     +----------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +NodeIndexSeekByRange | person:Person(highScore) WHERE highScore > $autoint_0 AND highScore < $autoint_1 |              1 |    1 |       2 |                    0/0 |
+-----------------------+----------------------------------------------------------------------------------+----------------+------+---------+------------------------+

Total database accesses: 2, total allocated memory: 64

8. 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.

Query
MATCH (person:Person) WHERE 10000 < person.highScore < 20000 AND person.name IS NOT NULL RETURN
  person
Query Plan
Compiler CYPHER 4.3

Planner COST

Runtime INTERPRETED

Runtime version 4.3

+-----------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| Operator        | Details                                                                                              | Estimated Rows | Rows | DB Hits | Page Cache Hits/Misses |
+-----------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +ProduceResults | person                                                                                               |              1 |    1 |       0 |                    0/0 |
| |               +------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +NodeIndexSeek  | person:Person(highScore, name) WHERE highScore > $autoint_0 AND highScore < $autoint_1 AND name IS N |              1 |    1 |       2 |                    0/0 |
|                 | OT NULL                                                                                              |                |      |         |                        |
+-----------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+

Total database accesses: 2, total allocated memory: 64

9. 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.

Query
MATCH (person)-[r:KNOWS]->(friend) WHERE r.since IN [1992, 2017] RETURN person, friend
Query Plan
Compiler CYPHER 4.3

Planner COST

Runtime INTERPRETED

Runtime version 4.3

+--------------------------------+----------------------------------------------------------------+----------------+------+---------+------------------------+
| Operator                       | Details                                                        | Estimated Rows | Rows | DB Hits | Page Cache Hits/Misses |
+--------------------------------+----------------------------------------------------------------+----------------+------+---------+------------------------+
| +ProduceResults                | person, friend                                                 |              1 |    1 |       0 |                    0/0 |
| |                              +----------------------------------------------------------------+----------------+------+---------+------------------------+
| +DirectedRelationshipIndexSeek | (person)-[r:KNOWS(since)]->(friend) WHERE since IN $autolist_0 |              1 |    1 |       3 |                    0/0 |
+--------------------------------+----------------------------------------------------------------+----------------+------+---------+------------------------+

Total database accesses: 3, total allocated memory: 64

10. 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.

Query
MATCH (person)-[r:KNOWS]->(friend) WHERE r.since IN [1992, 2017] AND r.lastMet IN [2002,
  2021] RETURN person, friend
Query Plan
Compiler CYPHER 4.3

Planner COST

Runtime INTERPRETED

Runtime version 4.3

+--------------------------------+----------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| Operator                       | Details                                                                                            | Estimated Rows | Rows | DB Hits | Page Cache Hits/Misses |
+--------------------------------+----------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +ProduceResults                | person, friend                                                                                     |              5 |    1 |       0 |                    0/0 |
| |                              +----------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +DirectedRelationshipIndexSeek | (person)-[r:KNOWS(since, lastMet)]->(friend) WHERE since IN $autolist_0 AND lastMet IN $autolist_1 |              5 |    1 |       5 |                    0/0 |
+--------------------------------+----------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+

Total database accesses: 5, total allocated memory: 64

11. 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.

Query
MATCH (person:Person) WHERE person.firstname STARTS WITH 'And' RETURN person
Query Plan
Compiler CYPHER 4.3

Planner COST

Runtime INTERPRETED

Runtime version 4.3

+-----------------------+--------------------------------------------------------------------+----------------+------+---------+------------------------+
| Operator              | Details                                                            | Estimated Rows | Rows | DB Hits | Page Cache Hits/Misses |
+-----------------------+--------------------------------------------------------------------+----------------+------+---------+------------------------+
| +ProduceResults       | person                                                             |              2 |    1 |       0 |                    0/0 |
| |                     +--------------------------------------------------------------------+----------------+------+---------+------------------------+
| +NodeIndexSeekByRange | person:Person(firstname) WHERE firstname STARTS WITH $autostring_0 |              2 |    1 |       2 |                    0/0 |
+-----------------------+--------------------------------------------------------------------+----------------+------+---------+------------------------+

Total database accesses: 2, total allocated memory: 64

12. 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.

Query
MATCH (person:Person) WHERE person.firstname STARTS WITH 'And' AND person.surname IS NOT NULL RETURN
  person
Query Plan
Compiler CYPHER 4.3

Planner COST

Runtime INTERPRETED

Runtime version 4.3

+-----------------+-----------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| Operator        | Details                                                                                             | Estimated Rows | Rows | DB Hits | Page Cache Hits/Misses |
+-----------------+-----------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +ProduceResults | person                                                                                              |              1 |    1 |       0 |                    0/0 |
| |               +-----------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +NodeIndexSeek  | person:Person(firstname, surname) WHERE firstname STARTS WITH $autostring_0 AND surname IS NOT NULL |              1 |    1 |       2 |                    0/0 |
+-----------------+-----------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+

Total database accesses: 2, total allocated memory: 64

13. 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.

Query
MATCH (person)-[r:KNOWS]->(friend) WHERE r.metIn ENDS WITH 'mo' RETURN person, friend
Query Plan
Compiler CYPHER 4.3

Planner COST

Runtime INTERPRETED

Runtime version 4.3

+----------------------------------------+-------------------------------------------------------------------------+----------------+------+---------+------------------------+
| Operator                               | Details                                                                 | Estimated Rows | Rows | DB Hits | Page Cache Hits/Misses |
+----------------------------------------+-------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +ProduceResults                        | person, friend                                                          |              0 |    1 |       0 |                    0/0 |
| |                                      +-------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +DirectedRelationshipIndexEndsWithScan | (person)-[r:KNOWS(metIn)]->(friend) WHERE metIn ENDS WITH $autostring_0 |              0 |    1 |       2 |                    0/0 |
+----------------------------------------+-------------------------------------------------------------------------+----------------+------+---------+------------------------+

Total database accesses: 2, total allocated memory: 64

14. 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.

Query
MATCH (person)-[r:KNOWS]->(friend) WHERE r.metIn ENDS WITH 'mo' AND r.lastMetIn IS NOT NULL RETURN
  person,
  friend
Query Plan
Compiler CYPHER 4.3

Planner COST

Runtime INTERPRETED

Runtime version 4.3

+--------------------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| Operator                       | Details                                                                                              | Estimated Rows | Rows | DB Hits | Page Cache Hits/Misses |
+--------------------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +ProduceResults                | person, friend                                                                                       |              1 |    1 |       0 |                    0/0 |
| |                              +------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +Filter                        | cache[r.metIn] ENDS WITH $autostring_0                                                               |              1 |    1 |       0 |                    0/0 |
| |                              +------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +DirectedRelationshipIndexScan | (person)-[r:KNOWS(metIn, lastMetIn)]->(friend) WHERE metIn IS NOT NULL AND lastMetIn IS NOT NULL, ca |              6 |    1 |       2 |                    0/0 |
|                                | che[r.metIn]                                                                                         |                |      |         |                        |
+--------------------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+

Total database accesses: 2, total allocated memory: 64

15. 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.

Query
MATCH (person:Person) WHERE person.firstname CONTAINS 'h' RETURN person
Query Plan
Compiler CYPHER 4.3

Planner COST

Runtime INTERPRETED

Runtime version 4.3

+------------------------+-----------------------------------------------------------------+----------------+------+---------+------------------------+
| Operator               | Details                                                         | Estimated Rows | Rows | DB Hits | Page Cache Hits/Misses |
+------------------------+-----------------------------------------------------------------+----------------+------+---------+------------------------+
| +ProduceResults        | person                                                          |              2 |    1 |       0 |                    0/0 |
| |                      +-----------------------------------------------------------------+----------------+------+---------+------------------------+
| +NodeIndexContainsScan | person:Person(firstname) WHERE firstname CONTAINS $autostring_0 |              2 |    1 |       2 |                    0/0 |
+------------------------+-----------------------------------------------------------------+----------------+------+---------+------------------------+

Total database accesses: 2, total allocated memory: 64

16. 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.

Query
MATCH (person:Person) WHERE person.surname CONTAINS '300' AND person.age IS NOT NULL RETURN person
Query Plan
Compiler CYPHER 4.3

Planner COST

Runtime INTERPRETED

Runtime version 4.3

+-----------------+--------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| Operator        | Details                                                                                          | Estimated Rows | Rows | DB Hits | Page Cache Hits/Misses |
+-----------------+--------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +ProduceResults | person                                                                                           |             11 |    1 |       0 |                    0/0 |
| |               +--------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +Filter         | cache[person.surname] CONTAINS $autostring_0                                                     |             11 |    1 |       0 |                    0/0 |
| |               +--------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +NodeIndexScan  | person:Person(surname, age) WHERE surname IS NOT NULL AND age IS NOT NULL, cache[person.surname] |            111 |  303 |     304 |                    0/0 |
+-----------------+--------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+

Total database accesses: 304, total allocated memory: 64

17. 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.

Query
MATCH (person)-[r:KNOWS]->(friend) WHERE r.since IS NOT NULL RETURN person, friend
Query Plan
Compiler CYPHER 4.3

Planner COST

Runtime INTERPRETED

Runtime version 4.3

+--------------------------------+-------------------------------------------------------------+----------------+------+---------+------------------------+
| Operator                       | Details                                                     | Estimated Rows | Rows | DB Hits | Page Cache Hits/Misses |
+--------------------------------+-------------------------------------------------------------+----------------+------+---------+------------------------+
| +ProduceResults                | person, friend                                              |              1 |    1 |       0 |                    0/0 |
| |                              +-------------------------------------------------------------+----------------+------+---------+------------------------+
| +DirectedRelationshipIndexScan | (person)-[r:KNOWS(since)]->(friend) WHERE since IS NOT NULL |              1 |    1 |       2 |                    0/0 |
+--------------------------------+-------------------------------------------------------------+----------------+------+---------+------------------------+

Total database accesses: 2, total allocated memory: 64

18. 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.

Query
MATCH (p:Person) WHERE p.firstname IS NOT NULL AND p.surname IS NOT NULL RETURN p
Query Plan
Compiler CYPHER 4.3

Planner COST

Runtime INTERPRETED

Runtime version 4.3

+-----------------+----------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| Operator        | Details                                                                          | Estimated Rows | Rows | DB Hits | Page Cache Hits/Misses |
+-----------------+----------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +ProduceResults | p                                                                                |              1 |    2 |       0 |                    0/0 |
| |               +----------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +NodeIndexScan  | p:Person(firstname, surname) WHERE firstname IS NOT NULL AND surname IS NOT NULL |              1 |    2 |       3 |                    0/0 |
+-----------------+----------------------------------------------------------------------------------+----------------+------+---------+------------------------+

Total database accesses: 3, total allocated memory: 64

19. 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.

Query
MATCH ()-[r:KNOWS]->() WHERE distance(r.lastMetPoint, point({x: 1, y: 2})) < 2 RETURN r.lastMetPoint
Query Plan
Compiler CYPHER 4.3

Planner COST

Runtime INTERPRETED

Runtime version 4.3

+---------------------------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| Operator                              | Details                                                                                              | Estimated Rows | Rows | DB Hits | Page Cache Hits/Misses |
+---------------------------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +ProduceResults                       | `r.lastMetPoint`                                                                                     |             13 |    9 |       0 |                    0/0 |
| |                                     +------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +Projection                           | cache[r.lastMetPoint] AS `r.lastMetPoint`                                                            |             13 |    9 |       0 |                    0/0 |
| |                                     +------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +Filter                               | distance(cache[r.lastMetPoint], point({x: $autoint_0, y: $autoint_1})) < $autoint_2                  |             13 |    9 |       0 |                    0/0 |
| |                                     +------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +DirectedRelationshipIndexSeekByRange | (anon_6)-[r:KNOWS(lastMetPoint)]->(anon_20) WHERE distance(lastMetPoint, point($autoint_0, $autoint_ |             13 |    9 |      10 |                    0/0 |
|                                       | 1)) < $autoint_2, cache[r.lastMetPoint]                                                              |                |      |         |                        |
+---------------------------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+

Total database accesses: 10, total allocated memory: 64

20. 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.

Query
MATCH (p:Person) WHERE distance(p.place, point({x: 1,
  y: 2})) < 2 AND p.name IS NOT NULL RETURN p.place
Query Plan
Compiler CYPHER 4.3

Planner COST

Runtime INTERPRETED

Runtime version 4.3

+-----------------+-----------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| Operator        | Details                                                                                             | Estimated Rows | Rows | DB Hits | Page Cache Hits/Misses |
+-----------------+-----------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +ProduceResults | `p.place`                                                                                           |             72 |    9 |       0 |                    0/0 |
| |               +-----------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +Projection     | cache[p.place] AS `p.place`                                                                         |             72 |    9 |       0 |                    0/0 |
| |               +-----------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +Filter         | distance(cache[p.place], point({x: $autoint_0, y: $autoint_1})) < $autoint_2                        |             72 |    9 |       0 |                    0/0 |
| |               +-----------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +NodeIndexSeek  | p:Person(place, name) WHERE distance(place, point($autoint_0, $autoint_1)) < $autoint_2 AND name IS |             72 |    9 |      10 |                    0/0 |
|                 | NOT NULL, cache[p.place]                                                                            |                |      |         |                        |
+-----------------+-----------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+

Total database accesses: 10, total allocated memory: 64

21. 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.

Query
MATCH (person:Person) WHERE point({x: 1, y: 5}) < person.location < point({x: 2, y: 6}) RETURN person
Query Plan
Compiler CYPHER 4.3

Planner COST

Runtime INTERPRETED

Runtime version 4.3

+-----------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| Operator              | Details                                                                                              | Estimated Rows | Rows | DB Hits | Page Cache Hits/Misses |
+-----------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +ProduceResults       | person                                                                                               |              0 |    1 |       0 |                    0/0 |
| |                     +------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +NodeIndexSeekByRange | person:Person(location) WHERE location > point({x: $autoint_0, y: $autoint_1}) AND location < point( |              0 |    1 |       2 |                    0/0 |
|                       | {x: $autoint_2, y: $autoint_3})                                                                      |                |      |         |                        |
+-----------------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+

Total database accesses: 2, total allocated memory: 64

22. 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.

Query
MATCH (person:Person) WHERE point({x: 1, y: 5}) < person.place < point({x: 2,
  y: 6}) AND person.firstname IS NOT NULL RETURN person
Query Plan
Compiler CYPHER 4.3

Planner COST

Runtime INTERPRETED

Runtime version 4.3

+-----------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| Operator        | Details                                                                                              | Estimated Rows | Rows | DB Hits | Page Cache Hits/Misses |
+-----------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +ProduceResults | person                                                                                               |              0 |    1 |       0 |                    0/0 |
| |               +------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+
| +NodeIndexSeek  | person:Person(place, firstname) WHERE place > point({x: $autoint_0, y: $autoint_1}) AND place < poin |              0 |    1 |       2 |                    0/0 |
|                 | t({x: $autoint_2, y: $autoint_3}) AND firstname IS NOT NULL                                          |                |      |         |                        |
+-----------------+------------------------------------------------------------------------------------------------------+----------------+------+---------+------------------------+

Total database accesses: 2, total allocated memory: 64