5.6. A multilevel indexing structure (path tree)

5.6.1. Return zero range
5.6.2. Return the full range
5.6.3. Return partly shared path ranges

In this example, a multi-level tree structure is used to index event nodes (here Event1, Event2 and Event3, in this case with a YEAR-MONTH-DAY granularity, making this a timeline indexing structure. However, this approach should work for a wide range of multi-level ranges.

The structure follows a couple of rules:

The graph below depicts a structure with 3 Events being attached to an index structure at different leafs.

Graph

cypher-pathtree-layout-path.svg

5.6.1. Return zero range

Here, only the events indexed under one leaf (2010-12-31) are returned. The query only needs one path segment rootPath (color Green) through the index.

Graph

Query

START root=node:node_auto_index(name = 'Root')
MATCH rootPath=root-[:`2010`]->()-[:`12`]->()-[:`31`]->leaf, leaf-[:VALUE]->event
RETURN event.name
ORDER BY event.name ASC

Returning all events on the date 2010-12-31, in this case Event1 and Event2

Result

event.name
2 rows, 1 ms

"Event1"

"Event2"


5.6.2. Return the full range

In this case, the range goes from the first to the last leaf of the index tree. Here, startPath (color Greenyellow) and endPath (color Green) span up the range, valuePath (color Blue) is then connecting the leafs, and the values canan be read from the middle node, hanging off the values (color Red) path.

Graph

Query

START root=node:node_auto_index(name = 'Root')
MATCH startPath=root-[:`2010`]->()-[:`12`]->()-[:`31`]->startLeaf,
      endPath=root-[`:2011`]->()-[:`01`]->()-[:`03`]->endLeaf,
      valuePath=startLeaf-[:NEXT*0..]->middle-[:NEXT*0..]->endLeaf,
      values=middle-[:VALUE]->event
RETURN event.name
ORDER BY event.name ASC

Returning all events between 2010-12-31 and 2011-01-03, in this case all events.

Result

event.name
4 rows, 5 ms

"Event1"

"Event2"

"Event2"

"Event3"


5.6.3. Return partly shared path ranges

Here, the query range results in partly shared paths when querying the index, making the introduction of and common path segment commonPath (color Black) necessary, before spanning up startPath (color Greenyellow) and endPath (color Darkgreen) . After that, valuePath (color Blue) connects the leafs and the indexed values are returned off values (color Red) path.

Graph

Query

START root=node:node_auto_index(name = 'Root')
MATCH commonPath=root-[:`2011`]->()-[:`01`]->commonRootEnd,
      startPath=commonRootEnd-[:`01`]->startLeaf,
      endPath=commonRootEnd-[:`03`]->endLeaf,
      valuePath=startLeaf-[:NEXT*0..]->middle-[:NEXT*0..]->endLeaf,
      values=middle-[:VALUE]->event
RETURN event.name
ORDER BY event.name ASC

Returning all events between 2011-01-01 and 2011-01-03, in this case Event2 and Event3.

Result

event.name
2 rows, 4 ms

"Event2"

"Event3"