Skip to content

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.

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 for all vertices that have a particular tag is called a composite index. 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;