不理解一些nGQL 查询语句的区别,

nebula 版本:3.5.0
部署方式:分布式
安装方式:rpmr
是否上生产环境:N

案例使用的ngql

#建表
CREATE TAG model_conf(  name string, status int, groupid string, iconname string ,content string);
CREATE EDGE model_conf_relation ( used int, name string );
CREATE EDGE model_conf_tag ( name string , value string );
CREATE EDGE model_conf_prop ( name string , value string );

#索引
CREATE TAG  INDEX IF NOT EXISTS idx_model_conf ON model_conf();
CREATE TAG  INDEX IF NOT EXISTS idx_model_conf_name ON model_conf(name(30));
CREATE EDGE INDEX IF NOT EXISTS idx_model_conf_relation ON model_conf_relation();
CREATE EDGE INDEX IF NOT EXISTS model_conf_tag  ON model_conf_tag();
CREATE EDGE INDEX IF NOT EXISTS model_conf_tag_name  ON model_conf_tag(name(30));
CREATE EDGE INDEX IF NOT EXISTS idx_model_conf_prop  ON model_conf_prop();
CREATE EDGE INDEX IF NOT EXISTS idx_model_conf_prop_name  ON model_conf_prop(name(30));
CREATE EDGE INDEX IF NOT EXISTS prop_index_0 on model_conf_prop(value);

REBUILD TAG INDEX idx_model_conf;
REBUILD TAG INDEX idx_model_conf_name;
REBUILD EDGE INDEX idx_model_conf_relation;
REBUILD EDGE INDEX model_conf_tag;
REBUILD EDGE INDEX model_conf_tag_name;
REBUILD EDGE INDEX idx_model_conf_prop;
REBUILD EDGE INDEX prop_index_0;
REBUILD EDGE INDEX idx_model_conf_prop_name;

库中数据量

(root@nebula) [amdbconf]> SHOW STATS;
+---------+-----------------------+----------+
| Type    | Name                  | Count    |
+---------+-----------------------+----------+
| "Tag"   | "model_conf"          | 7210000  |
| "Edge"  | "model_conf_prop"     | 14420000 |
| "Edge"  | "model_conf_relation" | 7210000  |
| "Edge"  | "model_conf_tag"      | 14420000 |
| "Space" | "vertices"            | 7210000  |
| "Space" | "edges"               | 36050000 |
+---------+-----------------------+----------+
Got 6 rows (time spent 950µs/49.201121ms)

场景一:

 MATCH (v:model_conf)-[e:model_conf_tag]->(v:model_conf) WHERE e.name == "key902-0"   RETURN e LIMIT 1000;
结果耗时:Execution Time 0.007146 (s)

MATCH (v:model_conf)-[e:model_conf_tag]->(v:model_conf) WHERE e.name starts with  "key902-0"   RETURN e LIMIT 1000;
MATCH (v:model_conf)-[e:model_conf_tag]->(v:model_conf) WHERE e.name  =~ '.*' + "key902-0"+ '.*'  RETURN v LIMIT 1000;
结果异常:[ERROR (-1005)]: Storage Error: RPC failure, probably timeout.

边model_conf_tag.name有建立索引
第二和三条ngql走路全表扫描了吗?

场景二:

如下两条ngql 第二条查询边很慢,是为什么的?

# model_conf是顶点   model_conf_tag是边   model_conf.name和model_conf_tag.name都建立索引
lookup on model_conf  WHERE model_conf.name STARTS WITH "model49999"  YIELD model_conf.name AS name | LIMIT 100  
#查询结果1s内部、返回

LOOKUP ON model_conf_tag WHERE model_conf_tag.name STARTS WITH "key902-0"  YIELD properties(edge).name;
#查询结果30s才返回

第三条执行失败了,你可以前面两条用 profile 加在前面看下执行计划,后面那条用 explain 看下生成的执行计划。

(root@nebula) [amdbconf]> explain MATCH (v:model_conf)-[e:model_conf_tag]->(v:model_conf) WHERE e.name starts with  "key902-0"   RETURN e LIMIT 1000;
Execution succeeded (time spent 7.382ms/128.394736ms)

Execution Plan (optimize time 1060 us)

-----+----------------+--------------+----------------+-------------------------------------------------------
| id | name           | dependencies | profiling data | operator info                                        |
-----+----------------+--------------+----------------+-------------------------------------------------------
| 23 | Project        | 21           |                | outputVar: {                                         |
|    |                |              |                |   "colNames": [                                      |
|    |                |              |                |     "e"                                              |
|    |                |              |                |   ],                                                 |
|    |                |              |                |   "type": "DATASET",                                 |
|    |                |              |                |   "name": "__Limit_9"                                |
|    |                |              |                | }                                                    |
|    |                |              |                | inputVar: __Limit_21                                 |
|    |                |              |                | columns: [                                           |
|    |                |              |                |   "$-.e[0]"                                          |
|    |                |              |                | ]                                                    |
-----+----------------+--------------+----------------+-------------------------------------------------------
| 21 | Limit          | 17           |                | outputVar: {                                         |
|    |                |              |                |   "colNames": [                                      |
|    |                |              |                |     "v",                                             |
|    |                |              |                |     "e",                                             |
|    |                |              |                |     "v"                                              |
|    |                |              |                |   ],                                                 |
|    |                |              |                |   "type": "DATASET",                                 |
|    |                |              |                |   "name": "__Limit_21"                               |
|    |                |              |                | }                                                    |
|    |                |              |                | inputVar: __Filter_10                                |
|    |                |              |                | offset: 0                                            |
|    |                |              |                | count: 1000                                          |
-----+----------------+--------------+----------------+-------------------------------------------------------
| 17 | AppendVertices | 20           |                | outputVar: {                                         |
|    |                |              |                |   "colNames": [                                      |
|    |                |              |                |     "v",                                             |
|    |                |              |                |     "e",                                             |
|    |                |              |                |     "v"                                              |
|    |                |              |                |   ],                                                 |
|    |                |              |                |   "type": "DATASET",                                 |
|    |                |              |                |   "name": "__Filter_10"                              |
|    |                |              |                | }                                                    |
|    |                |              |                | inputVar: __Filter_16                                |
|    |                |              |                | space: 29                                            |
|    |                |              |                | dedup: true                                          |
|    |                |              |                | limit: -1                                            |
|    |                |              |                | filter: model_conf._tag IS NOT EMPTY                 |
|    |                |              |                | orderBy: []                                          |
|    |                |              |                | src: none_direct_dst($-.e,$-.v)                      |
|    |                |              |                | props: [                                             |
|    |                |              |                |   {                                                  |
|    |                |              |                |     "props": [                                       |
|    |                |              |                |       "_tag"                                         |
|    |                |              |                |     ],                                               |
|    |                |              |                |     "tagId": 30                                      |
|    |                |              |                |   }                                                  |
|    |                |              |                | ]                                                    |
|    |                |              |                | exprs:                                               |
|    |                |              |                | vertex_filter:                                       |
|    |                |              |                | if_track_previous_path: true                         |
-----+----------------+--------------+----------------+-------------------------------------------------------
| 20 | Filter         | 24           |                | outputVar: {                                         |
|    |                |              |                |   "colNames": [                                      |
|    |                |              |                |     "v",                                             |
|    |                |              |                |     "e"                                              |
|    |                |              |                |   ],                                                 |
|    |                |              |                |   "type": "DATASET",                                 |
|    |                |              |                |   "name": "__Filter_16"                              |
|    |                |              |                | }                                                    |
|    |                |              |                | inputVar: __Traverse_19                              |
|    |                |              |                | condition: ($-.v._vid==none_direct_dst($-.e,$-.v))   |
|    |                |              |                | isStable: false                                      |
-----+----------------+--------------+----------------+-------------------------------------------------------
| 24 | Traverse       | 1            |                | outputVar: {                                         |
|    |                |              |                |   "colNames": [                                      |
|    |                |              |                |     "v",                                             |
|    |                |              |                |     "e"                                              |
|    |                |              |                |   ],                                                 |
|    |                |              |                |   "type": "DATASET",                                 |
|    |                |              |                |   "name": "__Traverse_19"                            |
|    |                |              |                | }                                                    |
|    |                |              |                | inputVar: __IndexScan_1                              |
|    |                |              |                | space: 29                                            |
|    |                |              |                | dedup: true                                          |
|    |                |              |                | limit: -1                                            |
|    |                |              |                | filter: (model_conf_tag.name STARTS WITH "key902-0") |
|    |                |              |                | orderBy: []                                          |
|    |                |              |                | src: $_vid                                           |
|    |                |              |                | edgeTypes: []                                        |
|    |                |              |                | edgeDirection: OUT_EDGE                              |
|    |                |              |                | vertexProps: [                                       |
|    |                |              |                |   {                                                  |
|    |                |              |                |     "props": [                                       |
|    |                |              |                |       "name",                                        |
|    |                |              |                |       "status",                                      |
|    |                |              |                |       "groupid",                                     |
|    |                |              |                |       "iconname",                                    |
|    |                |              |                |       "content",                                     |
|    |                |              |                |       "_tag"                                         |
|    |                |              |                |     ],                                               |
|    |                |              |                |     "tagId": 30                                      |
|    |                |              |                |   }                                                  |
|    |                |              |                | ]                                                    |
|    |                |              |                | edgeProps: [                                         |
|    |                |              |                |   {                                                  |
|    |                |              |                |     "props": [                                       |
|    |                |              |                |       "_src",                                        |
|    |                |              |                |       "_type",                                       |
|    |                |              |                |       "_rank",                                       |
|    |                |              |                |       "_dst",                                        |
|    |                |              |                |       "name",                                        |
|    |                |              |                |       "value"                                        |
|    |                |              |                |     ],                                               |
|    |                |              |                |     "type": 33                                       |
|    |                |              |                |   }                                                  |
|    |                |              |                | ]                                                    |
|    |                |              |                | statProps:                                           |
|    |                |              |                | exprs:                                               |
|    |                |              |                | random: false                                        |
|    |                |              |                | steps: 1..1                                          |
|    |                |              |                | vertex filter:                                       |
|    |                |              |                | edge filter:                                         |
|    |                |              |                | if_track_previous_path: false                        |
|    |                |              |                | first step filter: model_conf._tag IS NOT EMPTY      |
|    |                |              |                | tag filter: model_conf._tag IS NOT EMPTY             |
-----+----------------+--------------+----------------+-------------------------------------------------------
|  1 | IndexScan      | 2            |                | outputVar: {                                         |
|    |                |              |                |   "colNames": [                                      |
|    |                |              |                |     "_vid"                                           |
|    |                |              |                |   ],                                                 |
|    |                |              |                |   "type": "DATASET",                                 |
|    |                |              |                |   "name": "__IndexScan_1"                            |
|    |                |              |                | }                                                    |
|    |                |              |                | inputVar:                                            |
|    |                |              |                | space: 29                                            |
|    |                |              |                | dedup: false                                         |
|    |                |              |                | limit: 9223372036854775807                           |
|    |                |              |                | filter:                                              |
|    |                |              |                | orderBy: []                                          |
|    |                |              |                | schemaId: 30                                         |
|    |                |              |                | isEdge: false                                        |
|    |                |              |                | returnCols: [                                        |
|    |                |              |                |   "_vid"                                             |
|    |                |              |                | ]                                                    |
|    |                |              |                | indexCtx: [                                          |
|    |                |              |                |   {                                                  |
|    |                |              |                |     "columnHints": [],                               |
|    |                |              |                |     "filter": "",                                    |
|    |                |              |                |     "index_id": 35                                   |
|    |                |              |                |   }                                                  |
|    |                |              |                | ]                                                    |
-----+----------------+--------------+----------------+-------------------------------------------------------
|  2 | Start          |              |                | outputVar: {                                         |
|    |                |              |                |   "colNames": [],                                    |
|    |                |              |                |   "type": "DATASET",                                 |
|    |                |              |                |   "name": "__Start_2"                                |
|    |                |              |                | }                                                    |
-----+----------------+--------------+----------------+-------------------------------------------------------

LOOKUP ON model_conf_tag WHERE model_conf_tag.name STARTS WITH “key902-0” YIELD properties(edge).name;的执行计划

(root@nebula) [amdbconf]> explain LOOKUP ON model_conf_tag WHERE model_conf_tag.name STARTS WITH "key902-0"  YIELD properties(edge).name;
Execution succeeded (time spent 42.668ms/43.145508ms)

Execution Plan (optimize time 339 us)

-----+-------------------+--------------+----------------+----------------------------------------------------------
| id | name              | dependencies | profiling data | operator info                                           |
-----+-------------------+--------------+----------------+----------------------------------------------------------
|  3 | Project           | 2            |                | outputVar: {                                            |
|    |                   |              |                |   "colNames": [                                         |
|    |                   |              |                |     "properties(EDGE).name"                             |
|    |                   |              |                |   ],                                                    |
|    |                   |              |                |   "type": "DATASET",                                    |
|    |                   |              |                |   "name": "__Project_3"                                 |
|    |                   |              |                | }                                                       |
|    |                   |              |                | inputVar: __Filter_2                                    |
|    |                   |              |                | columns: [                                              |
|    |                   |              |                |   "properties(EDGE).name"                               |
|    |                   |              |                | ]                                                       |
-----+-------------------+--------------+----------------+----------------------------------------------------------
|  2 | Filter            | 4            |                | outputVar: {                                            |
|    |                   |              |                |   "colNames": [                                         |
|    |                   |              |                |     "model_conf_tag._src",                              |
|    |                   |              |                |     "model_conf_tag._dst",                              |
|    |                   |              |                |     "model_conf_tag._rank",                             |
|    |                   |              |                |     "model_conf_tag._type",                             |
|    |                   |              |                |     "model_conf_tag.name",                              |
|    |                   |              |                |     "model_conf_tag.value"                              |
|    |                   |              |                |   ],                                                    |
|    |                   |              |                |   "type": "DATASET",                                    |
|    |                   |              |                |   "name": "__Filter_2"                                  |
|    |                   |              |                | }                                                       |
|    |                   |              |                | inputVar: __EdgeIndexFullScan_1                         |
|    |                   |              |                | condition: (model_conf_tag.name STARTS WITH "key902-0") |
|    |                   |              |                | isStable: false                                         |
-----+-------------------+--------------+----------------+----------------------------------------------------------
|  4 | EdgeIndexFullScan | 0            |                | outputVar: {                                            |
|    |                   |              |                |   "colNames": [                                         |
|    |                   |              |                |     "model_conf_tag._src",                              |
|    |                   |              |                |     "model_conf_tag._dst",                              |
|    |                   |              |                |     "model_conf_tag._rank",                             |
|    |                   |              |                |     "model_conf_tag._type",                             |
|    |                   |              |                |     "model_conf_tag.name",                              |
|    |                   |              |                |     "model_conf_tag.value"                              |
|    |                   |              |                |   ],                                                    |
|    |                   |              |                |   "type": "DATASET",                                    |
|    |                   |              |                |   "name": "__EdgeIndexFullScan_1"                       |
|    |                   |              |                | }                                                       |
|    |                   |              |                | inputVar:                                               |
|    |                   |              |                | space: 29                                               |
|    |                   |              |                | dedup: false                                            |
|    |                   |              |                | limit: 9223372036854775807                              |
|    |                   |              |                | filter:                                                 |
|    |                   |              |                | orderBy: []                                             |
|    |                   |              |                | schemaId: 33                                            |
|    |                   |              |                | isEdge: true                                            |
|    |                   |              |                | returnCols: [                                           |
|    |                   |              |                |   "_src",                                               |
|    |                   |              |                |   "_dst",                                               |
|    |                   |              |                |   "_rank",                                              |
|    |                   |              |                |   "_type",                                              |
|    |                   |              |                |   "name",                                               |
|    |                   |              |                |   "value"                                               |
|    |                   |              |                | ]                                                       |
|    |                   |              |                | indexCtx: [                                             |
|    |                   |              |                |   {                                                     |
|    |                   |              |                |     "columnHints": [],                                  |
|    |                   |              |                |     "filter": "",                                       |
|    |                   |              |                |     "index_id": 38                                      |
|    |                   |              |                |   }                                                     |
|    |                   |              |                | ]                                                       |
-----+-------------------+--------------+----------------+----------------------------------------------------------
|  0 | Start             |              |                | outputVar: {                                            |
|    |                   |              |                |   "colNames": [],                                       |
|    |                   |              |                |   "type": "DATASET",                                    |
|    |                   |              |                |   "name": "__Start_0"                                   |
|    |                   |              |                | }                                                       |
-----+-------------------+--------------+----------------+----------------------------------------------------------

Thu, 29 Jun 2023 15:50:18 CST

看起来是走的索引的 full scan,可能跟 starts with 的表达式处理有关系,你可以先用等式验证下计划,看看 indexscan 中的索引有没有 column hints 填充

边理论上数据比点多,快慢感觉应该和你的数据量也有关系。
另外,查点 你做了limit,查边没加

数量如下图

边上lookup带limit 后查询结果