Vertex Centric Indexes

Introduction to Vertex Centric Indexes

In ArangoDB there are special indices designed to speed up graph operations,especially if the graph contains supernodes (vertices that have an exceptionallyhigh amount of connected edges).These indices are called vertex centric indexes and can be used in additionto the existing edge index.

Motivation

The idea of this index is to index a combination of a vertex, the direction and any arbitraryset of other attributes on the edges.To take an example, if we have an attribute called type on the edges, we can use an outboundvertex-centric index on this attribute to find all edges attached to a vertex with a given type.The following query example could benefit from such an index:

  1. FOR v, e, p IN 3..5 OUTBOUND @start GRAPH @graphName
  2. FILTER p.edges[*].type ALL == "friend"
  3. RETURN v

Using the built-in edge-index ArangoDB can find the list of all edges attached to the vertex fast,but still it has to walk through this list and check if all of them have the attribute type == "friend".Using a vertex-centric index would allow ArangoDB to find all edges for the vertex having the attribute type == "friend"in the same time and can save the iteration to verify the condition.

Index creation

A vertex-centric can be either of the following types:

  • Hash Index
  • Skiplist Index
  • Persistent IndexAnd is created using their creation operations.However in the list of fields used to create the index we have to include either _from or _to.Let us again explain this by an example.Assume we want to create an hash-based outbound vertex-centric index on the attribute type.This can be created with the following way:
  1. arangosh> db.collection.ensureIndex({ type: "hash", fields: [ "_from", "type" ] })

Show execution results

  1. {
  2. "deduplicate" : true,
  3. "fields" : [
  4. "_from",
  5. "type"
  6. ],
  7. "id" : "collection/73986",
  8. "isNewlyCreated" : true,
  9. "selectivityEstimate" : 1,
  10. "sparse" : false,
  11. "type" : "hash",
  12. "unique" : false,
  13. "code" : 201
  14. }

Hide execution results

All options that are supported by the respective indexes are supported by the vertex-centric index as well.

Index usage

The AQL optimizer can decide to use a vertex-centric whenever suitable, however it is not guaranteed that thisindex is used, the optimizer may estimate that an other index is assumed to be better.The optimizer will consider this type of indexes on explicit filtering of _from respectively _to:

  1. FOR edge IN collection
  2. FILTER edge._from == "vertices/123456" AND edge.type == "friend"
  3. RETURN edge

and during pattern matching queries:

  1. FOR v, e, p IN 3..5 OUTBOUND @start GRAPH @graphName
  2. FILTER p.edges[*].type ALL == "friend"
  3. RETURN v