net.ontopia.topicmaps.query.impl.utils
Class QueryOptimizer

java.lang.Object
  extended by net.ontopia.topicmaps.query.impl.utils.QueryOptimizer

public class QueryOptimizer
extends java.lang.Object

INTERNAL: An optimizer class that knows how to rewrite queries to equivalent, but more efficient queries. Used by the different query processor implementations to improve performance. Note that the only optimizations this class should perform are those which are independent of the tolog implementation used and which only rely on the semantics of tolog.

The only optimizations performed at the moment are:


Nested Class Summary
static class QueryOptimizer.AbstractQueryOptimizer
           
static class QueryOptimizer.AddTypeToRolePlayer
          INTERNAL:
static class QueryOptimizer.HierarchyWalker
          Replaces simple recursive rules with a more efficient custom implementation that just wraps the recursive step.
static class QueryOptimizer.NextPreviousOptimizer
          INTERNAL: Optimizes queries that look for the next or the previous value in a sequence from a given start value to not load all values and then do it the hard way, but instead to use a sorted index.
static class QueryOptimizer.PumpClause
           
static class QueryOptimizer.PumpPredicate
           
static class QueryOptimizer.RecursivePruner
          This optimizer adds RemoveDuplicatesPredicate on both sides of recursive calls within predicate rules.
static class QueryOptimizer.Reorderer
          INTERNAL: Optimizes the query by reordering the clauses into the optimal order for evaluation.
static class QueryOptimizer.RuleInliner
          INTERNAL: Optimizes the query by inlining all rules which are simple aliases for a single predicate.
static class QueryOptimizer.StringPrefixOptimizer
          INTERNAL: Optimizes queries that do lookup of occurrences by string value, then filter the string value by a prefix.
static class QueryOptimizer.TypeConflictResolver
          Finds cases of conflicting variables and resolves them by replacing predicates which can never succeed with DynamicFailurePredicate.
 
Constructor Summary
QueryOptimizer()
           
 
Method Summary
 void addOptimizer(QueryOptimizerIF optimizer)
           
static QueryOptimizer getOptimizer(TologQuery query)
          INTERNAL: Get hold of an query optimizer instance.
 java.util.List optimize(java.util.List clauses, QueryContext context)
           
 ParsedRule optimize(ParsedRule rule)
           
 TologQuery optimize(TologQuery query)
           
static java.util.List reorder(java.util.List qclauses, java.util.Set boundvars, java.util.Set literalvars, java.lang.String rulename, CostEstimator estimator)
          INTERNAL: Optimizes the order of the query clauses in a context where the given variables are bound.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryOptimizer

public QueryOptimizer()
Method Detail

getOptimizer

public static QueryOptimizer getOptimizer(TologQuery query)
INTERNAL: Get hold of an query optimizer instance.

Parameters:
query - The parsed query.

addOptimizer

public void addOptimizer(QueryOptimizerIF optimizer)

optimize

public TologQuery optimize(TologQuery query)
                    throws InvalidQueryException
Throws:
InvalidQueryException

optimize

public ParsedRule optimize(ParsedRule rule)
                    throws InvalidQueryException
Throws:
InvalidQueryException

optimize

public java.util.List optimize(java.util.List clauses,
                               QueryContext context)
                        throws InvalidQueryException
Throws:
InvalidQueryException

reorder

public static java.util.List reorder(java.util.List qclauses,
                                     java.util.Set boundvars,
                                     java.util.Set literalvars,
                                     java.lang.String rulename,
                                     CostEstimator estimator)
INTERNAL: Optimizes the order of the query clauses in a context where the given variables are bound. Done as a static method so we can use it from within RulePredicate.

Parameters:
qclauses - The list of clauses to be reordered.
boundvars - Contains the variables bound when we get here
literalvars - Contains the variables representing literals. Only an issue in rules.
rulename - The name of the current rule (so we can delay recursive evaluation).


Copyright © 2000-2012 Ontopia.