Schema Index

CREATE {TAG | EDGE} INDEX [IF NOT EXISTS] <index_name> ON {<tag_name> | <edge_name>} (prop_name_list)

Schema indexes are built to fast process graph queries. Nebula Graph supports two different kinds of indexing to speed up query processing: tag indexes and edge type indexes.

Most graph queries start the traversal from a list of vertices or edges that are identified by their properties. Schema indexes make these global retrieval operations efficient on large graphs.

Normally, you create indexes on a tag/edge-type at the time the tag/edge-type itself is created with CREATE TAG/EDGE statement.

Create Index

CREATE INDEX enables you to add indexes to existing tag/edge-type.

NOTE: Creating index will affect the write performance.

We suggest you import data first and then rebuild the index in batch.

Create Single-Property Index

nebula> CREATE TAG INDEX player_index_0 on player(name);

The above statement creates an index for the name property on all vertices carrying the player tag.

nebula> CREATE EDGE INDEX follow_index_0 on follow(degree);

The above statement creates an index for the degree property on all edges carrying the follow edge type.

Create Composite Index

The schema indexes also support spawning over multiple properties. An index on multiple properties is called a composite index.

NOTE: Index across multiple tags is not yet supported.

Consider the following example:

nebula> CREATE TAG INDEX player_index_1 on player(name,age);

This statement creates a composite index for the name and age property on all vertices carrying the player tag.

Show Index

SHOW {TAG | EDGE} INDEXES

SHOW INDEXES returns the defined tag/edg-type index information. For example, list the indexes with the following command:

nebula> SHOW TAG INDEXES;
=============================
| Index ID | Index Name     |
=============================
| 22       | player_index_0 |
-----------------------------
| 23       | player_index_1 |
-----------------------------

nebula> SHOW EDGE INDEXES;
=============================
| Index ID | Index Name     |
=============================
| 24       | follow_index_0 |
-----------------------------

DESCRIBE INDEX

DESCRIBE {TAG | EDGE} INDEX <index_name>

DESCRIBE INDEX is used to obtain information about the index. For example, list the index information with the following command:

nebula> DESCRIBE TAG INDEX player_index_0;
==================
| Field | Type   |
==================
| name  | string |
------------------

nebula> DESCRIBE TAG INDEX player_index_1;
==================
| Field | Type   |
==================
| name  | string |
------------------
| age   | int    |
------------------

DROP INDEX

DROP {TAG | EDGE} INDEX [IF EXISTS] <index_name>

DROP INDEX drops the index named index_name from the tag/edge-type. For example, drop the index player_index_0 with the following command:

nebula> DROP TAG INDEX player_index_0;

REBUILD INDEX

REBUILD {TAG | EDGE} INDEX <index_name> OFFLINE

Create Index section describes how to build indexes to improve query performance. If the index is created before data insertion, there is no need to rebuild the index and this section can be skipped; if data is updated or newly inserted before the index creation, it is necessary to rebuild the indexes in order to make sure that the indexes contain the previously added data. If the current database does not provide any services, use the OFFLINE keyword to speed up the rebuilding.

After rebuilding is complete, you can use the SHOW {TAG | EDGE} INDEX STATUS command to check if the index is successfully rebuilt. For example:

nebula> CREATE TAG person(name string, age int, gender string, email string);
Execution succeeded (Time spent: 10.051/11.397 ms)

nebula> CREATE TAG INDEX single_person_index ON person(name);
Execution succeeded (Time spent: 2.168/3.379 ms)

nebula> REBUILD TAG INDEX single_person_index OFFLINE;
Execution succeeded (Time spent: 2.352/3.568 ms)

nebula> SHOW TAG INDEX STATUS;
==========================================
| Name                | Tag Index Status |
==========================================
| single_person_index | SUCCEEDED        |
------------------------------------------

Using Index

After the index is created and data is inserted, you can use the LOOKUP statement to query the data.

There is usually no need to specify which indexes to use in a query, Nebula Graph will figure that out by itself.