Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc] rebuild index #1894

Merged
merged 5 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,39 @@ DROP {TAG | EDGE} INDEX [IF EXISTS] <index_name>
```ngql
nebula> DROP TAG INDEX player_index_0;
```

## 重构索引

```ngql
REBUILD {TAG | EDGE} INDEX <index_name> [OFFLINE]
```

[创建索引](#%e5%88%9b%e5%bb%ba%e7%b4%a2%e5%bc%95)部分介绍了如何创建索引以提高查询性能。如果索引在插入数据之前创建,此时无需执行索引重构操作;如果创建索引时,数据库里已经存有数据,则不会自动对旧的数据进行索引,此时需要对整个图中与索引相关的数据执行索引重构操作以保证索引包含了之前的数据。若当前数据库没有对外提供服务,则可在索引重构时使用 `OFFLINE` 关键字加快重构速度。

<!-- > 索引重构期间,对索引进行的所有幂等查询都会跳过索引并执行顺序扫描。这意味着在此操作期间查询运行速度较慢。非幂等命令(例如 INSERT、UPDATE 和 DELETE)将被阻止,直到重建索引为止。 -->

重构完成后,可使用 `SHOW {TAG | EDGE} INDEX STATUS` 命令查看索引是否重构成功。例如:

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

## 使用索引

索引创建完成并插入相关数据后,即可使用 [LOOKUP](../2.data-query-and-manipulation-statements/lookup-syntax.md) 语句进行数据查询。

通常无需指定在查询中具体使用的索引,**Nebula Graph** 会自行选择。
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,39 @@ DROP {TAG | EDGE} INDEX [IF EXISTS] <index_name>
```ngql
nebula> DROP TAG INDEX player_index_0;
```

## REBUILD INDEX

```ngql
REBUILD {TAG | EDGE} INDEX <index_name> [OFFLINE]
```

[Create Index](#create-index) section describes how to build indexes to improve query performance. If the index is created before inserting the data, there is no need to rebuild index and this section can be skipped; if data is updated or newly inserted after the index creation, it is necessary to rebuild the indexes in order to ensure 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.

<!-- > During the rebuilding, any idempotent queries will skip the index and perform sequential scans. This means that queries run slower during this operation. Non-idempotent commands, such as INSERT, UPDATE, and DELETE are blocked until the indexes are rebuilt. -->

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

```ngql
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](../2.data-query-and-manipulation-statements/lookup-syntax.md) 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.