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

ignore existed index and add keywords #1370

Merged
merged 4 commits into from
Jan 11, 2022
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 @@ -66,6 +66,7 @@ GET
GO
GRANT
IF
IGNORE_EXISTED_INDEX
IN
INDEX
INDEXES
Expand Down
62 changes: 60 additions & 2 deletions docs-2.0/3.ngql-guide/12.vertex-statements/1.insert-vertex.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
## 语法

```ngql

INSERT VERTEX [IF NOT EXISTS] [tag_props, [tag_props] ...]
VALUES VID: ([prop_value_list])

Expand All @@ -23,7 +22,31 @@ prop_value_list:
[prop_value [, prop_value] ...]
```

- `IF NOT EXISTS`:用户可以使用`IF NOT EXISTS`关键字检测待插入的 VID 是否存在,只有不存在时,才会插入,如果已经存在,不会进行修改。
<!---
// 忽略已存在索引插入点
```ngql
INSERT VERTEX [IF NOT EXISTS] [IGNORE_EXISTED_INDEX] [tag_props, [tag_props] ...]
VALUES VID: ([prop_value_list])

tag_props:
tag_name ([prop_name_list])

prop_name_list:
[prop_name [, prop_name] ...]

prop_value_list:
[prop_value [, prop_value] ...]
```

- `IGNORE_EXISTED_INDEX`:插入点后不更新索引。建议在第一次导入时使用`IGNORE_EXISTED_INDEX`,可大幅度提升性能。

!!! danger

使用`IGNORE_EXISTED_INDEX`关键字时不删除旧索引,查找时可能会读取到错误数据。需要重新创建索引,详情信息见 [REBUILD INDEX](../3/../14.native-index-statements/4.rebuild-native-index.md。
--->


- `IF NOT EXISTS`:检测待插入的 VID 是否存在,只有不存在时,才会插入,如果已经存在,不会进行修改。

!!! Note

Expand Down Expand Up @@ -63,6 +86,41 @@ nebula> CREATE TAG IF NOT EXISTS t1();
nebula> INSERT VERTEX t1() VALUES "10":();
```

<!---
```ngql
# 插入点 VID 为"100"和"200",id 为 1 的点。
nebula> INSERT VERTEX person(id) VALUES "100":(1), "200":(1);

# 查询 id 为 1 的点,VID 为"100"和"200"的点都能查到。
nebula> LOOKUP ON person WHERE person.id == 1 YIELD id(vertex) as id;
+-------------+
| id |
+-------------+
| "100" |
| "200" |
+-------------+

# 忽略索引插入 VID 为"200",id 为 2 的点。
nebula> INSERT VERTEX IGNORE_EXISTED_INDEX person(id) VALUES "200":(2);

# 查询 id 为 1 的点,VID 为"100"和"200"的点都能查到。
nebula> LOOKUP ON person WHERE person.id == 1 YIELD id(vertex) as id;
+-------------+
| id |
+-------------+
| "100" |
| "200" |
+-------------+

# 查询 id 为 2 的点,仅能查到 VID 为"200"的点。
nebula> LOOKUP ON person WHERE person.id == 2 YIELD id(vertex) as id;
+-------+
| id |
+-------+
| "200" |
+-------+
--->

```ngql
nebula> CREATE TAG IF NOT EXISTS t2 (name string, age int);
nebula> INSERT VERTEX t2 (name, age) VALUES "11":("n1", 12);
Expand Down