ArangoDB

Skip-Lists

This is an introduction to ArangoDB's skip-lists.



Skiplist Indexes

It is possible to define a skip-list index on one or more attributes (or paths) of a documents. This skip-list is then used in queries to locate documents within a given range. If the skip-list is unique, then no two documents are allowed to have the same set of attribute values.

Accessing Skip-List Indexes from the Shell


ensureUniqueSkiplist(field1, field2, ..., fieldn)
Creates a skiplist index on all documents using attributes as paths to the fields. At least one attribute must be given. All documents, which do not have the attribute path or with ore or more values that are not suitable, are ignored.

In case that the index was successfully created, the index identifier is returned.

arango> db.geo2.drop();
true

arango> db.geo2.ensureGeoIndex("location.latitude", "location.longitude");
23735273

arango> for (i = -90;  i <= 90;  i += 10) 
.......>   for (j = -180; j <= 180; j += 10)
.......>     db.geo2.save({ name : "Name" + i + "-" + j,
.......>                    location: { latitude : i,
.......>                                longitude : j } });

arango> db.geo2.near(0,0);
{ "location" : { "latitude" : 0, "longitude" : 0 },
  "name" : "Name0-0", 
  "_id" : "48956356:73466820" }
{ "location" : { "latitude" : 0, "longitude" : -10 },
  "name" : "Name0--10",
  "_id" : "48956356:73401284" }
.
.
{ "location" : { "latitude" : 20, "longitude" : -10 },
  "name" : "Name20--10",
  "_id" : "48956356:75891652" }
{ "location" : { "latitude" : 10, "longitude" : 20 },
  "name" : "Name10-20",
  "_id" : "48956356:74843076" }
...more results...


ensureSkiplist(field1, field2, ..., fieldn)
Creates a multi skiplist index on all documents using attributes as paths to the fields. At least one attribute must be given. All documents, which do not have the attribute path or with ore or more values that are not suitable, are ignored.

In case that the index was successfully created, the index identifier is returned.

arango> db.geo2.drop();
true

arango> db.geo2.ensureGeoIndex("location.latitude", "location.longitude");
23735273

arango> for (i = -90;  i <= 90;  i += 10) 
.......>   for (j = -180; j <= 180; j += 10)
.......>     db.geo2.save({ name : "Name" + i + "-" + j,
.......>                    location: { latitude : i,
.......>                                longitude : j } });

arango> db.geo2.near(0,0);
{ "location" : { "latitude" : 0, "longitude" : 0 },
  "name" : "Name0-0", 
  "_id" : "48956356:73466820" }
{ "location" : { "latitude" : 0, "longitude" : -10 },
  "name" : "Name0--10",
  "_id" : "48956356:73401284" }
.
.
{ "location" : { "latitude" : 20, "longitude" : -10 },
  "name" : "Name20--10",
  "_id" : "48956356:75891652" }
{ "location" : { "latitude" : 10, "longitude" : 20 },
  "name" : "Name10-20",
  "_id" : "48956356:74843076" }
...more results...