com.bigdata.rdf.sparql.ast.optimizers
Class ASTUnknownTermOptimizer
java.lang.Object
com.bigdata.rdf.sparql.ast.optimizers.ASTUnknownTermOptimizer
- All Implemented Interfaces:
- IASTOptimizer
public class ASTUnknownTermOptimizer
- extends Object
- implements IASTOptimizer
Pruning rules for unknown IVs in statement patterns:
If an optional join is known to fail, then remove the optional group in which
it appears from the group (which could be an optional group, a join group, or
a union).
If a statement pattern contains an unknown term, a with this statement
pattern will certainly fail. Thus the group in which the statement pattern
appears (the parent) will also fail. Continue recursively up the parent
hierarchy until we hit a UNION or an OPTIONAL parent. If we reach the root
of the where clause for a subquery, then continue up the groups in which the
subquery appears.
If the parent is a UNION, then remove the child from the UNION.
If a UNION has one child, then replace the UNION with the child.
If a UNION is empty, then fail the group in which it fails (unions are not
optional).
These rules should be triggered if a join is known to fail, which includes
the case of an unknown IV in a statement pattern as well
GRAPH uri {} where uri is not a named graph.
TODO From BigdataEvaluationStrategyImpl3#945
Prunes the sop tree of optional join groups containing values
not in the lexicon.
sopTree = stb.pruneGroups(sopTree, groupsToPrune);
If after pruning groups with unrecognized values we end up with a
UNION with no subqueries, we can safely just return an empty
iteration.
if (SOp2BOpUtility.isEmptyUnion(sopTree.getRoot())) {
return new EmptyIteration();
}
and also if we encounter a value not in the lexicon, we can still continue
with the query if the value is in either an optional tail or an optional join
group (i.e. if it appears on the right side of a LeftJoin). We can also
continue if the value is in a UNION. Otherwise we can stop evaluating right
now.
} catch (UnrecognizedValueException ex) {
if (sop.getGroup() == SOpTreeBuilder.ROOT_GROUP_ID) {
throw new UnrecognizedValueException(ex);
} else {
groupsToPrune.add(sopTree.getGroup(sop.getGroup()));
}
}
ASTPruneUnknownTerms : If an unknown terms appears in a StatementPatternNode
then we get to either fail the query or prune that part of the query. If it
appears in an optional, then prune the optional. if it appears in union, the
prune that part of the union. if it appears at the top-level then there are
no solutions for that query. This is part of what
BigdataEvaluationStrategyImpl3#toPredicate(final StatementPattern
stmtPattern) is doing. Note that toVE() as called from that method will throw
an UnknownValueException if the term is not known to the database.
FIXME Isolate pruning logic since we need to use it in more than one place.
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ASTUnknownTermOptimizer
public ASTUnknownTermOptimizer()
optimize
public IQueryNode optimize(AST2BOpContext context,
IQueryNode queryNode,
IBindingSet[] bindingSets)
- Description copied from interface:
IASTOptimizer
- Optimize the AST.
- Specified by:
optimize in interface IASTOptimizer
- Parameters:
context - The evaluation context.queryNode - The AST (in).
- Returns:
- The optimized AST.
Copyright © 2006-2012 SYSTAP, LLC. All Rights Reserved.