An index stores additional information on certain types of data, so that retrieving said data becomes more efficient. Downsides of indexing are:
- requiring extra storage for each index and
- slowing down writes to the database.
Carefully choosing which data to index can tremendously improve data retrieval efficiency, and thus make index downsides negligible.
Indexing can be applied to data with a specific label or a combination of label and
property. They are not automatically created, instead a user needs to create
them explicitly. Creation is done using a special
CREATE INDEX ON :Label(property) language construct.
For example, to index nodes which are labeled as
:Person and have a property
After the index is created, retrieving those nodes will become more efficient.
For example, the following query will retrieve all nodes which have an
property, instead of fetching each
:Person node and checking whether the
Using index based retrieval also works when filtering labels and properties
WHERE. For example, the same effect as in the previous example can be
Since the filter inside
WHERE can contain any kind of an expression, the
expression can be complicated enough so that the index does not get used. We
are continuously improving the recognition of index usage opportunities from a
WHERE expression. If there is any suspicion that an index may not be used,
we recommend putting properties and labels inside the
Information about available indexes can be retrieved by using the following syntax:
The results of this query will be all of the labels and label-property pairs that Memgraph currently indexes.
Created indexes can also be deleted by using the following syntax: