logger.trace("Incoming query model:\n{}", query);
// Clone the tuple expression to allow for more aggresive optimizations
query = query.clone();
Lock stLock = store.getStatementsReadLock();
try {
int snapshot = store.getCurrentSnapshot();
ReadMode readMode = ReadMode.COMMITTED;
if (!isAutoCommit()) {
snapshot++;
readMode = ReadMode.TRANSACTION;
}
TripleSource tripleSource = new MemTripleSource(includeInferred, snapshot, readMode);
EvaluationStrategyImpl strategy = new EvaluationStrategyImpl(tripleSource, query);
QueryOptimizerList optimizerList = new QueryOptimizerList();
optimizerList.add(new BindingAssigner());
optimizerList.add(new ConstantOptimizer(strategy));
optimizerList.add(new CompareOptimizer());
optimizerList.add(new ConjunctiveConstraintSplitter());
optimizerList.add(new DisjunctiveConstraintOptimizer());
optimizerList.add(new SameTermFilterOptimizer());
optimizerList.add(new QueryModelPruner());
optimizerList.add(new QueryJoinOptimizer(new MemEvaluationStatistics()));
optimizerList.add(new FilterOptimizer());
optimizerList.optimize(query, bindings);
logger.trace("Optimized query model:\n{}", query);
Cursor<BindingSet> iter;
iter = strategy.evaluate(query, EmptyBindingSet.getInstance());
iter = new LockingCursor<BindingSet>(stLock, iter);
return iter;
}
catch (StoreException e) {
stLock.release();
throw e;
}
catch (RuntimeException e) {
stLock.release();
throw e;
}
}