Class QueryOptimizer
- java.lang.Object
-
- net.ontopia.topicmaps.query.impl.utils.QueryOptimizer
-
public class QueryOptimizer extends 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:
- Reordering of query clauses for better performance by limiting the number of intermediate results.
- Inlining rules which are simple aliases for a single predicate.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description 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
Constructors Constructor Description QueryOptimizer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addOptimizer(QueryOptimizerIF optimizer)
static QueryOptimizer
getOptimizer(TologQuery query)
INTERNAL: Get hold of an query optimizer instance.List
optimize(List clauses, QueryContext context)
ParsedRule
optimize(ParsedRule rule)
TologQuery
optimize(TologQuery query)
static List
reorder(List qclauses, Set boundvars, Set literalvars, String rulename, CostEstimator estimator)
INTERNAL: Optimizes the order of the query clauses in a context where the given variables are bound.
-
-
-
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 List optimize(List clauses, QueryContext context) throws InvalidQueryException
- Throws:
InvalidQueryException
-
reorder
public static List reorder(List qclauses, Set boundvars, Set literalvars, 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 hereliteralvars
- Contains the variables representing literals. Only an issue in rules.rulename
- The name of the current rule (so we can delay recursive evaluation).
-
-