javeme commented on code in PR #2314:
URL:
https://github.com/apache/incubator-hugegraph/pull/2314#discussion_r1342001848
##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -1395,8 +1397,8 @@ private <R> QueryList<R> optimizeQueries(Query query,
}
boolean supportIn =
this.storeFeatures().supportsQueryWithInCondition();
- for (ConditionQuery cq : ConditionQueryFlatten.flatten(
- (ConditionQuery) query, supportIn)) {
+ for (ConditionQuery cq: ConditionQueryFlatten.flatten(
+ (ConditionQuery) query, supportIn)) {
Review Comment:
prefer to keep the old style
##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -1405,13 +1407,127 @@ private <R> QueryList<R> optimizeQueries(Query query,
* 2.index-query result(ids after optimization), which may be
empty.
*/
if (q == null) {
- queries.add(this.indexQuery(cq), this.batchSize);
+ boolean sys = cq.syspropConditions().size() != 0;
+ if (sys){
+ queries.add(this.indexQuery(cq), this.batchSize);
+ } else {
+ excludeOnlyLabelQuery(cq, queries);
+ }
+
} else if (!q.empty()) {
queries.add(q);
}
}
return queries;
}
+ private boolean hasOlapCondition(ConditionQuery query) {
+ for (Id pk : query.userpropKeys()) {
+ if(this.graph().propertyKey(pk).olap()) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+ // Method to reorder conditions
+ private void excludeOnlyLabelQuery(ConditionQuery cq, QueryList queries) {
+ // 判断是否命中索引
Review Comment:
can we translate all Chinese comments?
##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -1405,13 +1407,127 @@ private <R> QueryList<R> optimizeQueries(Query query,
* 2.index-query result(ids after optimization), which may be
empty.
*/
if (q == null) {
- queries.add(this.indexQuery(cq), this.batchSize);
+ boolean sys = cq.syspropConditions().size() != 0;
Review Comment:
sysprop?
##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java:
##########
@@ -1554,20 +1560,31 @@ protected void removeIndex(IndexLabel indexLabel) {
this.doRemove(this.serializer.writeIndex(index));
}
- private static class MatchedIndex {
+ protected static class MatchedIndex {
+
+ private final Set<SchemaLabel> schemaLabels;
+ private final Set<IndexLabel> indexLabels;
- private SchemaLabel schemaLabel;
- private Set<IndexLabel> indexLabels;
public MatchedIndex(SchemaLabel schemaLabel,
Set<IndexLabel> indexLabels) {
- this.schemaLabel = schemaLabel;
+ //this.schemaLabels = new HashSet<>();
Review Comment:
remove it?
##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/AbstractTransaction.java:
##########
@@ -133,7 +133,7 @@ public Number queryNumber(Query query) {
}
@Watched(prefix = "tx")
- public QueryResults<BackendEntry> query(Query query) {
+ protected QueryResults<BackendEntry> query(Query query) {
Review Comment:
not sure why need to mark protected
##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -1405,13 +1407,127 @@ private <R> QueryList<R> optimizeQueries(Query query,
* 2.index-query result(ids after optimization), which may be
empty.
*/
if (q == null) {
- queries.add(this.indexQuery(cq), this.batchSize);
+ boolean sys = cq.syspropConditions().size() != 0;
+ if (sys){
+ queries.add(this.indexQuery(cq), this.batchSize);
+ } else {
+ excludeOnlyLabelQuery(cq, queries);
+ }
+
} else if (!q.empty()) {
queries.add(q);
}
}
return queries;
}
+ private boolean hasOlapCondition(ConditionQuery query) {
+ for (Id pk : query.userpropKeys()) {
+ if(this.graph().propertyKey(pk).olap()) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+ // Method to reorder conditions
+ private void excludeOnlyLabelQuery(ConditionQuery cq, QueryList queries) {
+ // 判断是否命中索引
+ Set<GraphIndexTransaction.MatchedIndex> indexes = this.indexTx
+ .collectMatchedIndexes(cq);
+ if (CollectionUtils.isEmpty(indexes)){
+ if (this.hasOlapCondition(cq)) {
+ // 未命中索引且包含olap属性查询,需要throw NoIndexException
+ throw new NoIndexException("Don't accept query " +
+ "based on properties [olap] that are not indexed in any
label");
+ } else {
+ // 走算子下沉
+// E.checkState(this.indexTx.store().features()
+// .supportsFilterInStore(),
+// "Must support filter in store");
+ queries.add(cq);
+ }
+ } else {
+ // 命中索引
+ queries.add(this.indexQuery(cq), this.batchSize);
+
+ // 判断是否存在部分数据没有创建索引
+ fillQueryLabel(cq, indexes).stream().forEach(queries::add);
+ }
+ }
+ private List<ConditionQuery> fillQueryLabel(ConditionQuery rawQuery,
+
Set<GraphIndexTransaction.MatchedIndex> matchedIndices) {
+ List<ConditionQuery> queries = new ArrayList<>();
+
+ // 如果条件查询中包含olap相关属性查询,暂不做补充查询
+ if(this.hasOlapCondition(rawQuery)) {
+ return queries;
+ }
+
+ Collection<VertexLabel> vertexLabels = this.graph().vertexLabels();
+ Collection<EdgeLabel> edgeLabels = this.graph().edgeLabels();
+
+ Set<SchemaLabel> matchedLabels =
+ matchedIndices.stream()
+ .flatMap(matchedIndex -> matchedIndex.schemaLabels().stream())
+ .collect(Collectors.toSet());
+
+ Id label = rawQuery.condition(HugeKeys.LABEL);
+ if (label == null) {
Review Comment:
prefer `return if (label != null)`
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]