diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Condition.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Condition.java index 27fc822f30..2ac057a5b0 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Condition.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Condition.java @@ -565,6 +565,10 @@ public Object value() { return this.value; } + public void setValue(Object value) { + this.value = value; + } + public void serialKey(Object key) { this.serialKey = key; } diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQuery.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQuery.java index 8de686746d..73eaf3ea2e 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQuery.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQuery.java @@ -537,6 +537,23 @@ public ConditionQuery copyAndResetUnshared() { return query; } + public Condition.Relation copyRelation(Object key) { + Condition.Relation copyRes = null; + for (int i = 0; i < this.conditions.size(); i++) { + Condition c = this.conditions.get(i); + if (c.isRelation()) { + Condition.Relation r = (Condition.Relation) c; + if (r.key().equals(key)) { + copyRes = r.copy(); + this.conditions.set(i, copyRes); + break; + } + } + } + E.checkArgument(copyRes != null, "Copying Condition.Relation failed. key:%s", key); + return copyRes; + } + @Override public boolean test(HugeElement element) { if (!this.ids().isEmpty() && !super.test(element)) { diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java index 4d1cb05977..03e4c5b6e4 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java @@ -1464,20 +1464,25 @@ private Query optimizeQuery(ConditionQuery query) { VertexLabel vertexLabel = graph().vertexLabel(vertex.label()); return edgeLabel.linkWithLabel(vertexLabel.id(), dir.type()); }).collect(Collectors.toList()); - vertexIdList.clear(); - vertexIdList.addAll(filterVertexList); - if (CollectionUtils.isEmpty(vertexIdList)) { + if (CollectionUtils.isEmpty(filterVertexList)) { // Return empty query to skip storage query return new Query(query.resultType()); + } else if (vertexIdList.size() != filterVertexList.size()) { + // Modify on the copied relation to avoid affecting other query + Condition.Relation relation = query.copyRelation(HugeKeys.OWNER_VERTEX); + relation.setValue(filterVertexList); } } else if (query.containsRelation(HugeKeys.OWNER_VERTEX, Condition.RelationType.EQ)) { // For EQ query, just skip query if adjacent schema is unavailable. Id vertexId = query.condition(HugeKeys.OWNER_VERTEX); - Vertex vertex = this.graph().vertex(vertexId); - VertexLabel vertexLabel = graph().vertexLabel(vertex.label()); - if (!edgeLabel.linkWithLabel(vertexLabel.id(), dir.type())) { - // Return empty query to skip storage query - return new Query(query.resultType()); + Iterator iter = this.queryVertices(vertexId); + Vertex vertex = QueryResults.one(iter); + if (vertex != null) { + VertexLabel vertexLabel = graph().vertexLabel(vertex.label()); + if (!edgeLabel.linkWithLabel(vertexLabel.id(), dir.type())) { + // Return empty query to skip storage query + return new Query(query.resultType()); + } } }