diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java b/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java index 487270ed7f..693b944be9 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java @@ -51,6 +51,22 @@ public static List flatten(ConditionQuery query) { public static List flatten(ConditionQuery query, boolean supportIn) { if (query.isFlattened() && !query.mayHasDupKeys(SPECIAL_KEYS)) { + Relations relations = new Relations(); + List noRelations = new ArrayList<>(); + for (Condition condition : query.conditions()) { + if (condition.isRelation()) { + relations.add((Relation) condition); + } else { + noRelations.add(condition); + } + } + relations = optimizeRelations(relations); + if (relations != null) { + ConditionQuery cq = newQueryFromRelations(query, relations); + cq.query(noRelations); + return ImmutableList.of(cq); + } + return ImmutableList.of(query); }