You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by GitBox <gi...@apache.org> on 2019/02/12 11:35:06 UTC

[GitHub] afs commented on a change in pull request #527: SDB Transform - improve performance of OPTIONAL, MINUS

afs commented on a change in pull request #527: SDB Transform - improve performance of OPTIONAL, MINUS
URL: https://github.com/apache/jena/pull/527#discussion_r255914151
 
 

 ##########
 File path: jena-sdb/src/main/java/org/apache/jena/sdb/compiler/TransformOptimizeSubqueryFragments.java
 ##########
 @@ -0,0 +1,435 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sdb.compiler;
+
+import org.apache.jena.graph.Triple;
+import org.apache.jena.sparql.algebra.Op;
+import org.apache.jena.sparql.algebra.OpVisitor;
+import org.apache.jena.sparql.algebra.OpVisitorBase;
+import org.apache.jena.sparql.algebra.TransformCopy;
+import org.apache.jena.sparql.algebra.Transformer;
+import org.apache.jena.sparql.algebra.op.Op1;
+import org.apache.jena.sparql.algebra.op.Op2;
+import org.apache.jena.sparql.algebra.op.OpBGP;
+import org.apache.jena.sparql.algebra.op.OpGraph;
+import org.apache.jena.sparql.algebra.op.OpJoin;
+import org.apache.jena.sparql.algebra.op.OpLeftJoin;
+import org.apache.jena.sparql.algebra.op.OpMinus;
+import org.apache.jena.sparql.algebra.op.OpTable;
+import org.apache.jena.sparql.algebra.op.OpUnion;
+import org.apache.jena.sparql.core.BasicPattern;
+
+import java.util.ArrayDeque;
+import java.util.Deque;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * For large datasets, the performance of the OPTIONAL joins and MINUS in SQL can suffer, as the subqueries
+ * generate large views which are expensive to join.
+ *
+ * This optimizer transforms the algebra to insert the restrictions from outside of the optional subquery,
+ * reducing the amount of data that has to be joined.
+ *
+ * By reducing the amount of data that is considered in the LEFT JOIN/MINUS operations, the
+ * efficiency and performance of such constructs is greatly improved in most cases.
+ */
+public class TransformOptimizeSubqueryFragments extends TransformCopy {
+    private Deque<Op> tracker;
+
+    /**
+     * Static method to run the transformer (needs to keep track of visited nodes)
+     * @param op The algebra to rewrite
+     */
+    public static Op transform(Op op) {
+        final Deque<Op> stack = new ArrayDeque<>();
+        OpVisitor before = new Pusher(stack);
+        OpVisitor after = new Popper(stack);
+        return Transformer.transform(new TransformOptimizeSubqueryFragments(stack), op, before, after);
+    }
+
+    private TransformOptimizeSubqueryFragments(Deque<Op> tracker) {
+        this.tracker = tracker;
+    }
+
+    /**
+     * Run transformation on joins
+     *
+     * @param opJoin
+     * @param opLeft
+     * @param opRight
+     * @return
 
 Review comment:
   This is a javadoc warning on `@return`.   Either remove the `@return` here and everywhere else or put the type in (there are 4 instances of this)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services