Skip to content

Commit

Permalink
support-full-scan-in-match-&multitag-condition (#2058)
Browse files Browse the repository at this point in the history
* support-full-scan-in-match-&multitag-condition

* Update 6.cheatsheet-for-ngql.md
  • Loading branch information
abby-cyber committed Apr 25, 2023
1 parent 8d31dbf commit 6e7d310
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 131 deletions.
3 changes: 0 additions & 3 deletions docs-2.0/1.introduction/3.vid.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,3 @@ There are only two ways to locate `start vid`:

2. For example, `LOOKUP ON player WHERE player.name == "Tony Parker"` or `MATCH (v:player {name:"Tony Parker"})` locates `start vid` by the index of the property `player.name`.

!!! caution

For example, `match (n) return n;` returns an error: `Scan vertices or edges need to specify a limit number, or limit number can not push down.`, because it is a global scan, you must use the `LIMIT` clause to limit the number of returns.
10 changes: 5 additions & 5 deletions docs-2.0/2.quick-start/6.cheatsheet-for-ngql.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,15 @@
| --------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| Match vertices | `(v)` | You can use a user-defined variable in a pair of parentheses to represent a vertex in a pattern. For example: `(v)`. |
| Match tags | `MATCH (v:player) RETURN v` | You can specify a tag with `:<tag_name>` after the vertex in a pattern. |
| Match multiple tags | `MATCH (v:player:team) RETURN v LIMIT 10` | To match vertices with multiple tags, use colons (:). |
| Match vertex properties | `MATCH (v:player{name:"Tim Duncan"}) RETURN v` <br><br>`MATCH (v) WITH v, properties(v) as props, keys(properties(v)) as kk LIMIT 10000 WHERE [i in kk where props[i] == "Tim Duncan"] RETURN v` | You can specify a vertex property with `{<prop_name>: <prop_value>}` after the tag in a pattern; or use a vertex property value to get vertices directly. |
| Match multiple tags | `MATCH (v:player:team) RETURN v` | To match vertices with multiple tags, use colons (:). |
| Match vertex properties | `MATCH (v:player{name:"Tim Duncan"}) RETURN v` <br><br>`MATCH (v) WITH v, properties(v) as props, keys(properties(v)) as kk WHERE [i in kk where props[i] == "Tim Duncan"] RETURN v` | You can specify a vertex property with `{<prop_name>: <prop_value>}` after the tag in a pattern; or use a vertex property value to get vertices directly. |
| Match a VID. | `MATCH (v) WHERE id(v) == 'player101' RETURN v` | You can use the VID to match a vertex. The `id()` function can retrieve the VID of a vertex. |
| Match multiple VIDs. | `MATCH (v:player { name: 'Tim Duncan' })--(v2) WHERE id(v2) IN ["player101", "player102"] RETURN v2` | To match multiple VIDs, use `WHERE id(v) IN [vid_list]`. |
| Match connected vertices | `MATCH (v:player{name:"Tim Duncan"})--(v2) RETURN v2.player.name AS Name` | You can use the `--` symbol to represent edges of both directions and match vertices connected by these edges. You can add a `>` or `<` to the `--` symbol to specify the direction of an edge. |
| Match paths | `MATCH p=(v:player{name:"Tim Duncan"})-->(v2) RETURN p` | Connected vertices and edges form a path. You can use a user-defined variable to name a path as follows. |
| Match edges | `MATCH (v:player{name:"Tim Duncan"})-[e]-(v2) RETURN e`<br>`MATCH ()<-[e]-() RETURN e LIMIT 3` | Besides using `--`, `-->`, or `<--` to indicate a nameless edge, you can use a user-defined variable in a pair of square brackets to represent a named edge. For example: `-[e]-`. |
| Match an edge type | `MATCH ()-[e:follow]-() RETURN e LIMIT 5` |Just like vertices, you can specify an edge type with `:<edge_type>` in a pattern. For example: `-[e:follow]-`. |
| Match edge type properties | ` MATCH (v:player{name:"Tim Duncan"})-[e:follow{degree:95}]->(v2) RETURN e` <br><br>`MATCH ()-[e]->() WITH e, properties(e) as props, keys(properties(e)) as kk LIMIT 10000 WHERE [i in kk where props[i] == 90] RETURN e`| You can specify edge type properties with `{<prop_name>: <prop_value>}` in a pattern. For example: `[e:follow{likeness:95}]`; or use an edge type property value to get edges directly. |
| Match edges | `MATCH (v:player{name:"Tim Duncan"})-[e]-(v2) RETURN e`<br>`MATCH ()<-[e]-() RETURN e` | Besides using `--`, `-->`, or `<--` to indicate a nameless edge, you can use a user-defined variable in a pair of square brackets to represent a named edge. For example: `-[e]-`. |
| Match an edge type | `MATCH ()-[e:follow]-() RETURN e` |Just like vertices, you can specify an edge type with `:<edge_type>` in a pattern. For example: `-[e:follow]-`. |
| Match edge type properties | ` MATCH (v:player{name:"Tim Duncan"})-[e:follow{degree:95}]->(v2) RETURN e` <br><br>`MATCH ()-[e]->() WITH e, properties(e) as props, keys(properties(e)) as kk WHERE [i in kk where props[i] == 90] RETURN e`| You can specify edge type properties with `{<prop_name>: <prop_value>}` in a pattern. For example: `[e:follow{likeness:95}]`; or use an edge type property value to get edges directly. |
| Match multiple edge types | `MATCH (v:player{name:"Tim Duncan"})-[e:follow | :serve]->(v2) RETURN e` | The `|` symbol can help matching multiple edge types. For example: `[e:follow|:serve]`. The English colon (:) before the first edge type cannot be omitted, but the English colon before the subsequent edge type can be omitted, such as `[e:follow|serve]`. |
| Match multiple edges | `MATCH (v:player{name:"Tim Duncan"})-[]->(v2)<-[e:serve]-(v3) RETURN v2, v3` | You can extend a pattern to match multiple edges in a path. |
| Match fixed-length paths | `MATCH p=(v:player{name:"Tim Duncan"})-[e:follow*2]->(v2) RETURN DISTINCT v2 AS Friends` | You can use the `:<edge_type>*<hop>` pattern to match a fixed-length path. `hop` must be a non-negative integer. The data type of `e` is the list.|
Expand Down
11 changes: 0 additions & 11 deletions docs-2.0/20.appendix/0.FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,6 @@ See [show-stats](../3.ngql-guide/7.general-query-statements/6.show/14.show-stats

For more information, see [`INDEX`](../3.ngql-guide/14.native-index-statements/1.create-native-index.md), [`LOOKUP`](../3.ngql-guide/7.general-query-statements/5.lookup.md), and [`MATCH`](../3.ngql-guide/7.general-query-statements/2.match.md).

### "How to get all the vertices/edges without specifying the types?"

By nGQL, you CAN NOT directly getting all the vertices without specifying the tags, neither the edges, or you can use the `LIMIT` clause to limit the number of returns.

E.g., You CAN NOT run `MATCH (n) RETURN (n)`. An error like `Scan vertices or edges need to specify a limit number, or limit number can not push down.` will be returned.

You can use [NebulaGraph Algorithm](../graph-computing/nebula-algorithm.md).

Or get vertices by each tag, and then group them by yourself.


### "Can non-English characters be used as identifiers, such as the names of graph spaces, tags, edge types, properties, and indexes?"

Yes, for more information, see [Keywords and reserved words](../3.ngql-guide/1.nGQL-overview/keywords-and-reserved-words.md).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ For how to create full-text indexes, see [Deploy full-text index](../../4.deploy

## Must-read for using indexes

The concept and using restrictions of indexes are comparatively complex. You can use it together with `LOOKUP` and `MATCH` statements.
The concept and using restrictions of indexes are comparatively complex. Before you use indexes, you must read the following sections carefully.

You can use `CREATE INDEX` to add native indexes for the existing tags, edge types, or properties. They are usually called as tag indexes, edge type indexes, and property indexes.

Expand All @@ -20,9 +20,7 @@ If a property index `i_TA` is created for the property `A` of the tag `T` and `i

- The query engine can use `i_TA` to replace `i_T`.

- In the `MATCH` statement, `i_T` cannot replace `i_TA` for querying properties.

- In the `LOOKUP` statement, `i_T` may replace `i_TA` for querying properties.
- In the `MATCH` and `LOOKUP` statements, `i_T` may replace `i_TA` for querying properties.

!!! compatibility "Legacy version compatibility"

Expand All @@ -38,6 +36,8 @@ Although the same results can be obtained by using alternative indexes for queri

Long indexes decrease the scan performance of the Storage Service and use more memory. We suggest that you set the indexing length the same as that of the longest string to be indexed. The longest index length is 256 bytes.

## Steps

If you must use indexes, we suggest that you:

1. Import the data into NebulaGraph.
Expand Down
11 changes: 11 additions & 0 deletions docs-2.0/3.ngql-guide/14.native-index-statements/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

Indexes are built to fast process graph queries. Nebula Graph supports two kinds of indexes: native indexes and full-text indexes. This topic introduces the index types and helps choose the right index.

## Usage Instructions

- Indexes can improve query performance but may reduce write performance.

- An index is a prerequisite for locating data when executing a `LOOKUP `statement. If there is no index, an error will be reported when executing the `LOOKUP` statement.

- When using an index, NebulaGraph will automatically select the most optimal index.

- Indexes with high selectivity, that is, when the ratio of the number of records with unique values in the index column to the total number of records is high (for example, the ratio for `ID numbers` is `1`), can significantly improve query performance. For indexes with low selectivity (such as `country`), query performance might not experience a substantial improvement.


## Native indexes

Native indexes allow querying data based on a given property. Features are as follows.
Expand Down
Loading

0 comments on commit 6e7d310

Please sign in to comment.