-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
8 changed files
with
254 additions
and
5 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
...al-CN/2.query-language/4.statement-syntax/1.data-definition-statements/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
...al-EN/2.query-language/4.statement-syntax/1.data-definition-statements/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters