public class ASTGraphGroupOptimizer extends Object implements IASTOptimizer
?foo
. All nested statement patterns must have ?foo
as their context, even if they occur within a subquery. (This is not true for
a named subquery which just projects its solutions but does not inherit the
parent's graph context. However, if we lifted the named subquery out, e.g.,
for bottom up evaluation semantics, then we need to impose the GRAPH
constraint on the named subquery which means running this optimizer before
the one which lifts out the named subquery.)SameTerm(?foo,?bar)
constraint inside of the
nested graph pattern.
The problem with this is that it does not enforce the constraint as soon as possible under some conditions. A rewrite of the variable would have that effect but the rewrite needs to be aware of variable scope rules so we do not rewrite the variable within a subquery if it is not projected by that subquery. We would also have to add a BIND(?foo AS ?bar) to make ?bar visible in the scope of parent groups.
However, there is an INCLUDE problem too. That could be handled by moving the INCLUDE into a subgroup with a BIND to renamed the variable or by adding a "projection" to the INCLUDE so we could rename the variable there.
Since this construction of nested graph patterns is rare, and since it is complicated to make it more efficient, we are going with the SameTerm() constraint for now.
GRAPH uri
is nested within another
GRAPH uri
for distinct IRIs.GRAPH uri
then that constant could be lifted up and bound using
Constant/2 on the outer graph pattern. Again, this is an optimization which
may not contribute much value except in very rare cases. We do not need to do
anything additional to make this case correct.StatementPatternNode
with an "IN" for (?g,namedGraphs)
.?g
is known bound coming into graph ?g {}
then we want to test for the existence of at least one statement on the CSPO
index for ?g
.This is basically ASK sp(_,_,_,uri) LIMIT 1, but we
must run this for each binding on ?g
.?g
can be statically analyzed as being bound to
a specific constant then we would rewrite ?g
using
Constant/2 and then handle this as GRAPH uri {}
This is basically what AST2BOpJoins
does when it follows the
decision tree for named and default graphs. So, maybe that logic can
be lifted into this class as a rewrite?
ASTEmptyGroupOptimizer, which handles {}
for non-GRAPH
groups.
Constructor and Description |
---|
ASTGraphGroupOptimizer() |
Modifier and Type | Method and Description |
---|---|
QueryNodeWithBindingSet |
optimize(AST2BOpContext context,
QueryNodeWithBindingSet input)
Optimize the AST.
|
public QueryNodeWithBindingSet optimize(AST2BOpContext context, QueryNodeWithBindingSet input)
IASTOptimizer
optimize
in interface IASTOptimizer
context
- The evaluation context.input
- The input to the optimizer, consisting of a queryNode and
input binding set.Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.