Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-1405 query planner uses hashjoin when scoped group pattern #1418

Merged
merged 2 commits into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Base implementation of {@link QueryModelNode}.
*/
public abstract class AbstractQueryModelNode implements QueryModelNode {
public abstract class AbstractQueryModelNode implements QueryModelNode, GraphPatternGroupable {

/*-----------*
* Variables *
Expand All @@ -25,6 +25,8 @@ public abstract class AbstractQueryModelNode implements QueryModelNode {

private QueryModelNode parent;

private boolean isGraphPatternGroup;

/*---------*
* Methods *
*---------*/
Expand All @@ -39,6 +41,26 @@ public void setParentNode(QueryModelNode parent) {
this.parent = parent;
}

/*
* (non-Javadoc)
*
* @see org.eclipse.rdf4j.query.algebra.GraphPatternGroupable#isGraphPatternGroup()
*/
@Override
public boolean isGraphPatternGroup() {
return isGraphPatternGroup;
}

/*
* (non-Javadoc)
*
* @see org.eclipse.rdf4j.query.algebra.GraphPatternGroupable#setGraphPatternGroup(boolean)
*/
@Override
public void setGraphPatternGroup(boolean isGraphPatternGroup) {
this.isGraphPatternGroup = isGraphPatternGroup;
}

/**
* Dummy implementation of {@link QueryModelNode#visitChildren} that does nothing. Subclasses should override this
* method when they have child nodes.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2019 Eclipse RDF4J contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*******************************************************************************/
package org.eclipse.rdf4j.query.algebra;

/**
* {@link QueryModelNode}s that can represent a full graph pattern group.
*
* Although the notion of a graph pattern group is strictly not relevant at the algebra level, it gives an indication to
* evaluation strategy implementations on how they can optimize join patterns wrt variable scope.
*
* @author Jeen Broekstra
*
*/
public interface GraphPatternGroupable {

/**
* indicates if the node represents the root of a graph pattern group.
*
* @return true iff the node represents the node of a graph pattern group.
*
*/
public boolean isGraphPatternGroup();

/**
* Set the value of {@link #isGraphPatternGroup()} to true or false.
*/
public void setGraphPatternGroup(boolean isGraphPatternGroup);

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* An abstract superclass for unary tuple operators which, by definition, has one argument.
*/
public abstract class UnaryTupleOperator extends AbstractQueryModelNode implements TupleExpr {
public abstract class UnaryTupleOperator extends AbstractQueryModelNode implements TupleExpr, GraphPatternGroupable {

/*-----------*
* Variables *
Expand All @@ -23,6 +23,8 @@ public abstract class UnaryTupleOperator extends AbstractQueryModelNode implemen
*/
protected TupleExpr arg;

private boolean isGraphPatternGroup;

/*--------------*
* Constructors *
*--------------*/
Expand All @@ -43,6 +45,16 @@ public UnaryTupleOperator(TupleExpr arg) {
* Methods *
*---------*/

@Override
public boolean isGraphPatternGroup() {
return isGraphPatternGroup;
}

@Override
public void setGraphPatternGroup(boolean isGraphPatternGroup) {
this.isGraphPatternGroup = isGraphPatternGroup;
}

/**
* Gets the argument of this unary tuple operator.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.eclipse.rdf4j.model.BNode;
import org.eclipse.rdf4j.model.Literal;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.query.algebra.GraphPatternGroupable;
import org.eclipse.rdf4j.query.algebra.Join;
import org.eclipse.rdf4j.query.algebra.Projection;
import org.eclipse.rdf4j.query.algebra.QueryModelNode;
Expand Down Expand Up @@ -55,6 +56,20 @@ public static boolean containsSubquery(TupleExpr t) {
return false;
}

/**
* Verifies if the supplied {@link TupleExpr} represents a group graph pattern.
*
* @param expr a {@link TupleExpr}
* @return <code>true</code> if the {@link TupleExpr} is {@link GraphPatternGroupable} and has its graph pattern
* group flag set to <code>true</code>, <code>false</code> otherwise.
*/
public static boolean isGraphPatternGroup(TupleExpr expr) {
if (expr instanceof GraphPatternGroupable) {
return ((GraphPatternGroupable) expr).isGraphPatternGroup();
}
return false;
}

/**
* Verifies if the supplied {@link TupleExpr} contains a {@link Projection}. If the supplied TupleExpr is a
* {@link Join} or contains a {@link Join}, projections inside that Join's arguments will not be taken into account.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,7 @@ public TupleExpr buildTupleExpr() {

for (int i = 1; i < requiredTEs.size(); i++) {
TupleExpr te = requiredTEs.get(i);
// if (containsProjection(te) || containsProjection(result))
// {
// result = new BottomUpJoin(result, te);
// }
// else {
result = new Join(result, te);
// }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.eclipse.rdf4j.query.algebra.ExtensionElem;
import org.eclipse.rdf4j.query.algebra.Filter;
import org.eclipse.rdf4j.query.algebra.FunctionCall;
import org.eclipse.rdf4j.query.algebra.GraphPatternGroupable;
import org.eclipse.rdf4j.query.algebra.Group;
import org.eclipse.rdf4j.query.algebra.GroupConcat;
import org.eclipse.rdf4j.query.algebra.GroupElem;
Expand Down Expand Up @@ -1023,6 +1024,8 @@ public Object visit(ASTGraphPatternGroup node, Object data) throws VisitorExcept
// bindings external to the group
TupleExpr te = graphPattern.buildTupleExpr();

((GraphPatternGroupable) te).setGraphPatternGroup(true);

parentGP.addRequiredTE(te);

graphPattern = parentGP;
Expand Down