YaeSakuraQ opened a new issue, #3479: URL: https://github.com/apache/hugegraph/issues/3479
### Bug Type (问题类型) performance (性能下降) ### Before submit - [x] 我已经确认现有的 [Issues](https://github.com/apache/hugegraph/issues) 与 [FAQ](https://hugegraph.apache.org/docs/guides/faq/) 中没有相同 / 重复问题 (I have confirmed and searched that there are no similar problems in the historical issue and documents) ### Environment (环境信息) - Server version: Apache HugeGraph 1.7.0 - Backend: RocksDB, single server - Deployment: `hugegraph/hugegraph:1.7.0` in Docker on macOS ARM64, with 2 CPUs and a 3 GiB memory limit - Query interface: Gremlin-Groovy over the Gremlin HTTP endpoint, GraphSON 3, default traversal strategies - Data size: 100,051 vertices and 100,102 edges ### Expected & Actual behavior (期望与实际表现) 1. **How to reproduce** Run the native Gremlin-Groovy setup in **Vertex/Edge example** in an empty graph with a fresh schema. The first pattern binds `u` and `t` via `Pattern_p_left_edge`. The fixture gives `u` one outgoing `Pattern_p_right_edge` to `t`. Vertex `t` has 100,001 incoming edges of that label, including the one from `u`. 2. **Actual behavior** Both traversals check the same directed edge. Query 1 checks from the source with `out()` and returns `[false]` in a median of **1.56 ms**. Query 2 checks from the target with `in()` and returns `[false]` in a median of **84.50 ms**. The `false` value is the constant projected after a successful match. The median runtimes differ by **54.33×**. The `profile()` excerpt for the adjacency step inside `where()` shows: ```text q1 HugeVertexStep(OUT,[Pattern_p_right_edge],vertex) traverserCount=1 q2 HugeVertexStep(IN,[Pattern_p_right_edge],vertex) traverserCount=100001 ``` 3. **Expected behavior** When the two endpoints are already bound, HugeGraph should use both vertices and the edge label to check for the directed edge. This would let the `in()` form avoid enumerating 100,001 incoming neighbors. ### Vertex/Edge example (问题点 / 边数据举例) ```javascript Run this setup in an empty HugeGraph graph with a fresh schema. Bind the graph's traversal source to `g`. In GraphSpace `DEFAULT` for graph `hugegraph`, the Gremlin HTTP alias is `{"g":"__g_DEFAULT-hugegraph"}`. def graph = g.getGraph() def s = graph.schema() s.propertyKey('uid').asLong().valueSingle().create() s.propertyKey('keep').asBoolean().valueSingle().create() s.propertyKey('value').asLong().valueSingle().create() s.propertyKey('p_gate_true').asBoolean().valueSingle().create() s.propertyKey('p_gate_false').asBoolean().valueSingle().create() s.propertyKey('p_anchor').asLong().valueSingle().create() s.propertyKey('_gsp_eid').asLong().valueSingle().create() s.vertexLabel('Pattern_p_match_label_0').useAutomaticId() .properties(*['uid', 'keep', 'value', 'p_gate_true', 'p_gate_false', 'p_anchor']) .nullableKeys(*['keep', 'value', 'p_gate_true', 'p_gate_false', 'p_anchor']).enableLabelIndex(true).create() s.vertexLabel('Pattern_p_match_label_1').useAutomaticId() .properties(*['uid', 'keep', 'value', 'p_gate_true', 'p_gate_false', 'p_anchor']) .nullableKeys(*['keep', 'value', 'p_gate_true', 'p_gate_false', 'p_anchor']).enableLabelIndex(true).create() s.vertexLabel('Random_label_3').useAutomaticId() .properties(*['uid', 'keep', 'value', 'p_gate_true', 'p_gate_false', 'p_anchor']) .nullableKeys(*['keep', 'value', 'p_gate_true', 'p_gate_false', 'p_anchor']).enableLabelIndex(true).create() s.edgeLabel('Pattern_p_left_edge').asBase().properties(*['keep', '_gsp_eid']).nullableKeys(*['keep']) .multiTimes().sortKeys('_gsp_eid').enableLabelIndex(true).create() s.edgeLabel('Pattern_p_left_edge__0').withBase('Pattern_p_left_edge').link('Random_label_3', 'Pattern_p_match_label_0') .properties(*['keep', '_gsp_eid']).nullableKeys(*['keep']).multiTimes().sortKeys('_gsp_eid') .enableLabelIndex(true).create() s.edgeLabel('Pattern_p_right_edge').asBase().properties(*['keep', '_gsp_eid']).nullableKeys(*['keep']) .multiTimes().sortKeys('_gsp_eid').enableLabelIndex(true).create() s.edgeLabel('Pattern_p_right_edge__0').withBase('Pattern_p_right_edge').link('Random_label_3', 'Pattern_p_match_label_0') .properties(*['keep', '_gsp_eid']).nullableKeys(*['keep']).multiTimes().sortKeys('_gsp_eid') .enableLabelIndex(true).create() s.edgeLabel('BACKGROUND_EDGE').asBase().properties(*['keep', '_gsp_eid']).nullableKeys(*['keep']) .multiTimes().sortKeys('_gsp_eid').enableLabelIndex(true).create() s.edgeLabel('BACKGROUND_EDGE__0').withBase('BACKGROUND_EDGE').link('Random_label_3', 'Random_label_3') .properties(*['keep', '_gsp_eid']).nullableKeys(*['keep']).multiTimes().sortKeys('_gsp_eid') .enableLabelIndex(true).create() s.indexLabel('gsp_index_0').onV('Random_label_3').by('p_anchor').secondary().create() s.indexLabel('gsp_index_1').onV('Pattern_p_match_label_0').by('uid').secondary().create() // Create the 50 start vertices in uid order. def vertexIds = [] def startProperties = [ [keep: true, value: 0L, p_anchor: 1L], [keep: true, value: 5L], [keep: true, value: 4L], [keep: false, value: 1L], [keep: true, value: 4L], [keep: false, value: 5L], [keep: true, value: 2L], [keep: true, value: 5L], [keep: true, value: 0L], [keep: true, value: 0L], [keep: false, value: 0L], [keep: true, value: 4L], [keep: false, value: 4L], [keep: true, value: 3L], [keep: true, value: 3L], [keep: true, value: 3L], [keep: true, value: 3L], [keep: true, value: 1L], [keep: true, value: 2L], [keep: false, value: 0L], [keep: true, value: 1L], [keep: true, value: 1L], [keep: true, value: 5L], [keep: true, value: 2L], [keep: true, value: 3L], [keep: true, value: 2L], [keep: false, value: 2L], [keep: true, value: 0L], [keep: true, value: 1L], [keep: true, value: 5L], [keep: true, value: 0L], [keep: true, value: 1L], [keep: true, value: 1L], [keep: true, value: 3L], [keep: true, value: 1L], [keep: false, value: 4L], [keep: true, value: 1L], [keep: true, value: 4L], [keep: true, value: 1L], [keep: true, value: 5L], [keep: true, value: 2L], [keep: true, value: 2L], [keep: true, value: 2L], [keep: false, value: 2L], [keep: true, value: 2L], [keep: false, value: 0L], [keep: true, value: 3L], [keep: true, value: 3L], [keep: false, value: 0L], [keep: true, value: 2L] ] startProperties.eachWithIndex { properties, uid -> def vertex = g.addV('Random_label_3').property('uid', uid as long).next() properties.each { k, v -> vertex.property(k, v) } vertexIds.add(vertex.id()) } graph.tx().commit() vertexIds.add(g.addV('Pattern_p_match_label_0').property('uid', 50L).property('keep', true).id().next()) (51L..100050L).each { uid -> vertexIds.add(g.addV('Random_label_3').property('uid', uid).property('keep', true).property('p_anchor', 0L).id().next()) if ((uid - 50L) % 250 == 0) graph.tx().commit() } def backgroundEdges = [ [49, 9, true], [15, 3, false], [37, 25, true], [8, 42, false], [40, 20, false], [2, 4, false], [6, 7, true], [43, 48, true], [4, 5, false], [30, 11, false], [17, 47, true], [23, 35, true], [5, 19, true], [32, 24, false], [4, 39, true], [8, 32, true], [27, 44, true], [29, 25, true], [22, 11, true], [2, 20, false], [14, 47, true], [27, 38, true], [13, 22, false], [32, 1, true], [25, 16, false], [1, 22, false], [16, 20, true], [27, 31, true], [35, 49, true], [0, 27, true], [13, 4, false], [0, 6, true], [37, 7, false], [40, 32, false], [33, 25, true], [33, 8, true], [2, 16, true], [27, 3, false], [45, 9, true], [16, 1, true], [34, 28, true], [27, 37, true], [36, 6, true], [38, 34, false], [33, 45, true], [9, 21, true], [27, 40, true], [29, 34, true], [44, 49, true], [26, 39, true], [49, 18, true], [22, 38, false], [43, 6, true], [27, 31, false], [36, 9, true], [36, 1, false], [18, 14, true], [1, 28, true], [27, 30, true], [27, 36, true], [47, 18, true], [42, 1, true], [16, 3, false], [21, 38, true], [5, 6, false], [39, 30, true], [5, 30, false], [23, 41, false], [11, 21, true], [10, 34, true], [20, 14, false], [36, 45, true], [20, 24, true], [40, 31, true], [18, 28, false], [15, 1, false], [3, 25, true], [45, 6, true], [42, 20, true], [39, 15, false], [14, 21, true], [4, 12, true], [30, 46, true], [39, 49, true], [20, 35, true], [28, 29, false], [11, 34, true], [12, 21, true], [5, 12, true], [14, 42, true], [16, 33, true], [38, 2, true], [42, 23, false], [46, 2, false], [7, 3, true], [19, 42, true], [0, 18, false], [15, 36, true], [9, 20, true], [11, 44, true] ] backgroundEdges.eachWithIndex { edge, ordinal -> g.V(vertexIds[edge[0]]).addE('BACKGROUND_EDGE__0').to(__.V(vertexIds[edge[1]])) .property('keep', edge[2]).property('_gsp_eid', ordinal as long).iterate() } graph.tx().commit() g.V(vertexIds[0]).addE('Pattern_p_left_edge__0').to(__.V(vertexIds[50])).property('_gsp_eid', 100L).iterate() (51..100050).each { uid -> g.V(vertexIds[uid]).addE('Pattern_p_right_edge__0').to(__.V(vertexIds[50])).property('_gsp_eid', uid + 50L).iterate() if ((uid - 50) % 250 == 0) graph.tx().commit() } g.V(vertexIds[0]).addE('Pattern_p_right_edge__0').to(__.V(vertexIds[50])).property('_gsp_eid', 100101L).iterate() graph.tx().commit() Run each query separately with `p0` bound to `1` (integer). // q1 g.V().hasLabel("Random_label_3").has("p_anchor",p0) .match( __.as("p_match_u").out("Pattern_p_left_edge").hasLabel("Pattern_p_match_label_0").as("p_match_0"), __.as("p_match_u").where(__.out("Pattern_p_right_edge").as("p_match_0"))) .select("p_match_u").constant(false) // q2 g.V().hasLabel("Random_label_3").has("p_anchor",p0) .match( __.as("p_match_u").out("Pattern_p_left_edge").hasLabel("Pattern_p_match_label_0").as("p_match_0"), __.as("p_match_0").where(__.in("Pattern_p_right_edge").as("p_match_u"))) .select("p_match_u").constant(false) q1 `result.data` {"@type": "g:List", "@value": [false]} q2 `result.data` {"@type": "g:List", "@value": [false]} ``` ### Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构) ```javascript //Response from `GET /graphspaces/DEFAULT/graphs/hugegraph/schema`. { "propertykeys": [ { "id": 1, "name": "uid", "data_type": "LONG", "cardinality": "SINGLE", "aggregate_type": "NONE", "write_type": "OLTP", "properties": [], "status": "CREATED", "user_data": { "~create_time": "2026-11-14 20:55:54.365" } }, { "id": 2, "name": "keep", "data_type": "BOOLEAN", "cardinality": "SINGLE", "aggregate_type": "NONE", "write_type": "OLTP", "properties": [], "status": "CREATED", "user_data": { "~create_time": "2026-11-14 20:55:54.369" } }, { "id": 3, "name": "value", "data_type": "LONG", "cardinality": "SINGLE", "aggregate_type": "NONE", "write_type": "OLTP", "properties": [], "status": "CREATED", "user_data": { "~create_time": "2026-11-14 20:55:54.369" } }, { "id": 4, "name": "p_gate_true", "data_type": "BOOLEAN", "cardinality": "SINGLE", "aggregate_type": "NONE", "write_type": "OLTP", "properties": [], "status": "CREATED", "user_data": { "~create_time": "2026-11-14 20:55:54.369" } }, { "id": 5, "name": "p_gate_false", "data_type": "BOOLEAN", "cardinality": "SINGLE", "aggregate_type": "NONE", "write_type": "OLTP", "properties": [], "status": "CREATED", "user_data": { "~create_time": "2026-11-14 20:55:54.369" } }, { "id": 6, "name": "p_anchor", "data_type": "LONG", "cardinality": "SINGLE", "aggregate_type": "NONE", "write_type": "OLTP", "properties": [], "status": "CREATED", "user_data": { "~create_time": "2026-11-14 20:55:54.370" } }, { "id": 7, "name": "_gsp_eid", "data_type": "LONG", "cardinality": "SINGLE", "aggregate_type": "NONE", "write_type": "OLTP", "properties": [], "status": "CREATED", "user_data": { "~create_time": "2026-11-14 20:55:54.370" } } ], "vertexlabels": [ { "id": 1, "name": "Pattern_p_match_label_0", "id_strategy": "AUTOMATIC", "primary_keys": [], "nullable_keys": [ "keep", "value", "p_gate_true", "p_gate_false", "p_anchor" ], "index_labels": [ "gsp_index_1" ], "properties": [ "uid", "keep", "value", "p_gate_true", "p_gate_false", "p_anchor" ], "status": "CREATED", "ttl": 0, "enable_label_index": true, "user_data": { "~create_time": "2026-11-14 20:55:54.372" } }, { "id": 2, "name": "Pattern_p_match_label_1", "id_strategy": "AUTOMATIC", "primary_keys": [], "nullable_keys": [ "keep", "value", "p_gate_true", "p_gate_false", "p_anchor" ], "index_labels": [], "properties": [ "uid", "keep", "value", "p_gate_true", "p_gate_false", "p_anchor" ], "status": "CREATED", "ttl": 0, "enable_label_index": true, "user_data": { "~create_time": "2026-11-14 20:55:54.373" } }, { "id": 3, "name": "Random_label_3", "id_strategy": "AUTOMATIC", "primary_keys": [], "nullable_keys": [ "keep", "value", "p_gate_true", "p_gate_false", "p_anchor" ], "index_labels": [ "gsp_index_0" ], "properties": [ "uid", "keep", "value", "p_gate_true", "p_gate_false", "p_anchor" ], "status": "CREATED", "ttl": 0, "enable_label_index": true, "user_data": { "~create_time": "2026-11-14 20:55:54.373" } } ], "edgelabels": [ { "id": 1, "name": "Pattern_p_left_edge", "edgelabel_type": "NORMAL", "source_label": "Random_label_3", "target_label": "Pattern_p_match_label_0", "links": [ { "Random_label_3": "Pattern_p_match_label_0" } ], "frequency": "MULTIPLE", "sort_keys": [ "_gsp_eid" ], "nullable_keys": [ "keep" ], "index_labels": [], "properties": [ "keep", "_gsp_eid" ], "status": "CREATED", "ttl": 0, "enable_label_index": true, "user_data": { "~create_time": "2026-11-14 20:55:54.375" } }, { "id": 2, "name": "Pattern_p_left_edge__0", "edgelabel_type": "NORMAL", "source_label": "Random_label_3", "target_label": "Pattern_p_match_label_0", "links": [ { "Random_label_3": "Pattern_p_match_label_0" } ], "frequency": "MULTIPLE", "sort_keys": [ "_gsp_eid" ], "nullable_keys": [ "keep" ], "index_labels": [], "properties": [ "keep", "_gsp_eid" ], "status": "CREATED", "ttl": 0, "enable_label_index": true, "user_data": { "~create_time": "2026-11-14 20:55:54.376" } }, { "id": 3, "name": "Pattern_p_right_edge", "edgelabel_type": "NORMAL", "source_label": "Random_label_3", "target_label": "Pattern_p_match_label_0", "links": [ { "Random_label_3": "Pattern_p_match_label_0" } ], "frequency": "MULTIPLE", "sort_keys": [ "_gsp_eid" ], "nullable_keys": [ "keep" ], "index_labels": [], "properties": [ "keep", "_gsp_eid" ], "status": "CREATED", "ttl": 0, "enable_label_index": true, "user_data": { "~create_time": "2026-11-14 20:55:54.376" } }, { "id": 4, "name": "Pattern_p_right_edge__0", "edgelabel_type": "NORMAL", "source_label": "Random_label_3", "target_label": "Pattern_p_match_label_0", "links": [ { "Random_label_3": "Pattern_p_match_label_0" } ], "frequency": "MULTIPLE", "sort_keys": [ "_gsp_eid" ], "nullable_keys": [ "keep" ], "index_labels": [], "properties": [ "keep", "_gsp_eid" ], "status": "CREATED", "ttl": 0, "enable_label_index": true, "user_data": { "~create_time": "2026-11-14 20:55:54.377" } }, { "id": 5, "name": "BACKGROUND_EDGE", "edgelabel_type": "NORMAL", "source_label": "Random_label_3", "target_label": "Random_label_3", "links": [ { "Random_label_3": "Random_label_3" } ], "frequency": "MULTIPLE", "sort_keys": [ "_gsp_eid" ], "nullable_keys": [ "keep" ], "index_labels": [], "properties": [ "keep", "_gsp_eid" ], "status": "CREATED", "ttl": 0, "enable_label_index": true, "user_data": { "~create_time": "2026-11-14 20:55:54.377" } }, { "id": 6, "name": "BACKGROUND_EDGE__0", "edgelabel_type": "NORMAL", "source_label": "Random_label_3", "target_label": "Random_label_3", "links": [ { "Random_label_3": "Random_label_3" } ], "frequency": "MULTIPLE", "sort_keys": [ "_gsp_eid" ], "nullable_keys": [ "keep" ], "index_labels": [], "properties": [ "keep", "_gsp_eid" ], "status": "CREATED", "ttl": 0, "enable_label_index": true, "user_data": { "~create_time": "2026-11-14 20:55:54.377" } } ], "indexlabels": [ { "id": 1, "name": "gsp_index_0", "base_type": "VERTEX_LABEL", "base_value": "Random_label_3", "index_type": "SECONDARY", "fields": [ "p_anchor" ], "status": "CREATED", "user_data": { "~create_time": "2026-11-14 20:55:54.382" } }, { "id": 2, "name": "gsp_index_1", "base_type": "VERTEX_LABEL", "base_value": "Pattern_p_match_label_0", "index_type": "SECONDARY", "fields": [ "uid" ], "status": "CREATED", "user_data": { "~create_time": "2026-11-14 20:55:54.600" } } ] } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
