Skip to content

Commit

Permalink
[doc] Index (#1578)
Browse files Browse the repository at this point in the history
* index

* index doc

* add if not exists and CN version

* add if exists in drop index

* address wilson and darion comments

Co-authored-by: dutor <440396+dutor@users.noreply.github.com>
  • Loading branch information
amber-moe and dutor committed Jan 14, 2020
1 parent 713cddb commit c73da7b
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Schema 索引

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

schema 索引可用于快速处理图查询。**Nebula Graph** 支持两种类型的索引:**Tag 索引****Edge Type 索引**

多数图查询都从拥有共同属性的同一类型的点或边开始遍历。schema 索引使得这些全局检索操作在大型图上更为高效。

一般地,在使用 `CREATE TAG/EDGE` 语句将 Tag/Edge-type 创建好之后,即可为其创建索引。

## 创建索引

`CREATE INDEX` 用于为已有 Tag/Edge-type 创建索引。

### 创建单属性索引

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

上述语句在所有标签为 _player_ 的顶点上为属性 _name_ 创建了一个索引。

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

上述语句在 _follow_ 边类型的所有边上为属性 _degree_ 创建了一个索引。

### 创建组合索引

schema 索引还支持为多个属性同时创建索引。这种包含多种属性的索引在 **Nebula Graph** 中称为复合索引。

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

上述语句在所有标签为 _player_ 的顶点上为属性 _name__age_ 创建了一个复合索引。

## 列出索引

```ngql
SHOW {TAG | EDGE} INDEXES
```

`SHOW INDEXES` 用于列出已创建完成的 Tag/Edge-type 的索引信息。使用以下命令列出索引:

```ngql
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 |
-----------------------------
```

## 返回索引信息

```ngql
DESCRIBE {TAG | EDGE} INDEX <index_name>
```

`DESCRIBE INDEX` 用于返回指定索引信息。例如,使用以下命令返回索引信息:

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

## 删除索引

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

`DROP INDEX` 用于删除指定名称的 Tag/Edge-type 索引。例如,使用以下命令删除名为 _player_index_0_ 的索引:

```ngql
nebula> DROP TAG INDEX player_index_0;
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
DESCRIBE SPACE <space_name>
DESCRIBE TAG <tag_name>
DESCRIBE EDGE <edge_name>
DESCRIBE {TAG | EDGE} INDEX <index_name>
```

DESCRIBE 关键词的作用是获取关于 space, tag, edge 结构的信息。
Expand Down Expand Up @@ -48,3 +49,14 @@ nebula> DESCRIBE EDGE serve
|   end_year |  int |
---------------------
```

返回指定索引信息,对应 `DESCRIBE INDEX`

```ngql
nebula> DESCRIBE TAG INDEX player_index_0;
==================
| Field | Type |
==================
| name | string |
------------------
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
SHOW {SPACES | TAGS | EDGES | HOSTS | PARTS }
SHOW PARTS <part_id>
SHOW CREATE {TAG | EDGE} {<tag_name> | <edge_name>}
SHOW {TAG | EDGE} INDEXES
SHOW CONFIGS [graph|meta|storage]
```

Expand All @@ -13,6 +14,8 @@ SHOW CONFIGS [graph|meta|storage]

`SHOW CREATE TAG``SHOW CREATE EDGE` 返回当前图空间中指定的 tag、edge type 及其创建语法。如果 tag 或 edge type 包含默认值,则同时返回默认值。

`SHOW INDEXES` 用于列出已创建完成的标签或边类型的索引信息。

`SHOW HOSTS` 列出元服务器注册的所有存储主机。

`SHOW PARTS` 列出指定 SPACE 的 partition 信息。
Expand Down
8 changes: 5 additions & 3 deletions docs/manual-CN/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@
* [新建图空间](2.query-language/4.statement-syntax/1.data-definition-statements/create-space-syntax.md)
* [新建 Tag 和 Edge](2.query-language/4.statement-syntax/1.data-definition-statements/create-tag-edge-syntax.md)
* [更改 Tag 和 Edge](2.query-language/4.statement-syntax/1.data-definition-statements/alter-tag-edge-syntax.md)
* [Drop Tag](2.query-language/4.statement-syntax/1.data-definition-statements/drop-tag-syntax.md)
* [Drop Edge](2.query-language/4.statement-syntax/1.data-definition-statements/drop-edge-syntax.md)
* [Drop Space](2.query-language/4.statement-syntax/1.data-definition-statements/drop-space-syntax.md)
* [删除 Tag](2.query-language/4.statement-syntax/1.data-definition-statements/drop-tag-syntax.md)
* [删除 Edge](2.query-language/4.statement-syntax/1.data-definition-statements/drop-edge-syntax.md)
* [删除 Space](2.query-language/4.statement-syntax/1.data-definition-statements/drop-space-syntax.md)
* [索引](2.query-language/4.statement-syntax/1.data-definition-statements/index.md)

* 数据查询与操作语句 (DQL 和 DML)
* [删除边](2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/delete-edge-syntax.md)
* [删除顶点](2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/delete-vertex-syntax.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Schema Index

```ngql
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

```ngql
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.

```ngql
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:

```ngql
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.

<!-- Queries do no longer have to explicitly use an index, it’s more the behavior we know from SQL. When there is an index that can make a query more performant. Assume a query like
```ngql
MATCH (p:Person {name: 'Stefan'}) RETURN p
```
In case of no index being set up this will look up all Person nodes and check if their name property matches Stefan. If an index is present it will be used transparently. -->

## Show Index

```ngql
SHOW {TAG | EDGE} INDEXES
```

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

```ngql
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

```ngql
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:

```ngql
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

```ngql
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:

```ngql
nebula> DROP TAG INDEX player_index_0;
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
DESCRIBE SPACE <space_name>
DESCRIBE TAG <tag_name>
DESCRIBE EDGE <edge_name>
DESCRIBE {TAG | EDGE} INDEX <index_name>
```

The DESCRIBE keyword is used to obtain information about space, tag, edge structure.
The DESCRIBE keyword is used to obtain information about space, tag and edge structure.

Also notice that DESCRIBE is different from SHOW. Refer [SHOW](show-syntax.md).

Expand Down Expand Up @@ -48,3 +49,14 @@ nebula> DESCRIBE EDGE serve
|   end_year |  int |
---------------------
```

Obtain information about the index.

```ngql
nebula> DESCRIBE TAG INDEX player_index_0;
==================
| Field | Type |
==================
| name | string |
------------------
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
SHOW {SPACES | TAGS | EDGES | HOSTS | PARTS}
SHOW PARTS <part_id>
SHOW CREATE {TAG | EDGE} {<tag_name> | <edge_name>}
SHOW {TAG | EDGE} INDEXES
SHOW CONFIGS [graph|meta|storage]
```

`SHOW SPACES` lists the SPACES on the **Nebula Graph** cluster.

`SHOW TAGS` and `SHOW EDGES` return the defined tags and edge types in a given space, respectively.

`SHOW CREATE TAG` and `SHOW CREATE EDGE` return the specified tag or edge type and their creation syntax in a given space. If the tag or edge type contains a default value, the default value is also returned.
`SHOW CREATE TAG` and `SHOW CREATE EDGE` return the specified tag or edge type and their creation syntax in a given space. If the tag or edge type contains a default value, the default value is also returned.

`SHOW INDEXES` returns the defined tag/edg-type index information.

`SHOW HOSTS` is to list storage hosts registered by the meta server. There are 6 columns: ip, port, status (online/offline), leader partitions count in all spaces, leader partitions count in each space, total partitions count in all spaces.

Expand Down
1 change: 1 addition & 0 deletions docs/manual-EN/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ It is the optimal solution in the world capable of hosting graphs with dozens of
* [Drop Edge Syntax](2.query-language/4.statement-syntax/1.data-definition-statements/drop-edge-syntax.md)
* [Drop Space Syntax](2.query-language/4.statement-syntax/1.data-definition-statements/drop-space-syntax.md)
* [Drop Tag Syntax](2.query-language/4.statement-syntax/1.data-definition-statements/drop-tag-syntax.md)
* [Index](2.query-language/4.statement-syntax/1.data-definition-statements/index.md)
* Data Query and Manipulation Statements
* [Delete Edge Syntax](2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/delete-edge-syntax.md)
* [Delete Vertex Syntax](2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/delete-vertex-syntax.md)
Expand Down

0 comments on commit c73da7b

Please sign in to comment.