Raw Index Access

Most Datomic programs will not access the indexes directly, instead taking advantage of Datomic's declarative Datalog query engine.

However, raw index access is available for integrations. For example, you might have use the indexes to make Datomic data available to a map/reduce framework spanning multiple data sources of different types.

Datomic Indexes

Datomic automatically maintains four indexes. Each index sorts datoms in a specific order. These indexes are named based on the sort order used:

IndexSort OrderContains
EAVTentity / attribute / value / txall datoms
AEVTattribute / entity / value / txall datoms
AVETattribute / value / entity / txall datoms
VAETvalue / attribute / entity / txall reference datoms

EAVT Index

The EAVT index provides efficient access to everything about a given entity. Conceptually this is very similar to row access style in a SQL database, except that entities can possess arbitrary attributes rather then being limited to a predefined set of columns.

The example below shows all of the facts about entity 42 grouped together:

../images/eavt.png

EAVT is also useful in master/detail lookups, since the references to detail entities are just ordinary Vs alongside the scalar attributes of the master entity. Better still, Datomic assigns entity ids so that when master and detail records are created in the same transaction, they will be colocated in EAVT.

Datomic's EAVT and VAET indexes can automatically navigate entity relationships in both directions, so you do not need to (and should not) create two attributes that model the same relationship but from different directions.

AEVT Index

The AEVT index provides efficient access to all values for a given attribute, comparable to traditional column access style. In the table below, notice how all :release/name attributes are grouped together. This allows Datomic to efficiently query for all values of the :release/name attribute, because the values reside next to one another in the index.

../images/aevt.png

AVET Index

The AVET index provides efficient access to particular combinations of attribute and value, much like a key-value store. The example below shows a portion of the AVET index allowing lookup by :release/name.

../images/avet.png

The AVET index also supports the index-range operation, which returns all attribute values in a particular range. For more information about index-range, refer to the Datomic API documentation for your programming language.

VAET Index

The VAET index contains all and only datoms with :db/valueType attributes whose value is :db.type/ref. This is also known as the reverse index, since it allows efficient navigation of relationships in reverse. This is similar to graph-style access.

If The Beatles are entity 100, you can see in the following table how their releases would be grouped together in this index.

Datomic's EAVT and VAET indexes can automatically navigate entity relationships in both directions, so you do not need to (and should not) create two attributes that model the same relationship but from different directions.

../images/vaet.png

Accessing Indexes Directly via the datoms API

The Client API provides direct access to the indexes via the datoms and indexrange operations. Consult the API documentation for more detailed information about these operations.

Next: Query Limitations