Class VarThisCompilationOptimiser
java.lang.Object
org.datanucleus.store.query.compiler.VarThisCompilationOptimiser
- All Implemented Interfaces:
CompilationOptimiser
Optimiser for query compilation that searches for variable equality like "var == this".
Since the variable is the same as the candidate it will replace all instances of the variable with the candidate.
TODO We should only update "var == this" in the same branch of the filter (i.e not if used in other branches of the filter)
Applies to the FILTER only.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) QueryCompilationThe compilation that we are optimising. -
Constructor Summary
ConstructorsConstructorDescriptionVarThisCompilationOptimiser(QueryCompilation compilation, MetaDataManager unused, ClassLoaderResolver clr) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidfindRedundantFilterVariables(Expression filterExpr, Set<String> varNames) Method to process the provided filter expression and find any variables that are to all intents and purposes redundant.voidoptimise()Method to perform the optimisation.private ExpressionreplaceVariableWithCandidateInExpression(String varName, Expression expr) Method that replaces any occurrence of the specified variable in the provided expression with the candidate primary expression.
-
Field Details
-
compilation
QueryCompilation compilationThe compilation that we are optimising.
-
-
Constructor Details
-
VarThisCompilationOptimiser
public VarThisCompilationOptimiser(QueryCompilation compilation, MetaDataManager unused, ClassLoaderResolver clr)
-
-
Method Details
-
optimise
public void optimise()Description copied from interface:CompilationOptimiserMethod to perform the optimisation.- Specified by:
optimisein interfaceCompilationOptimiser
-
replaceVariableWithCandidateInExpression
Method that replaces any occurrence of the specified variable in the provided expression with the candidate primary expression. Recurses to sub-expressions.- Parameters:
varName- Variable nameexpr- The expression to update- Returns:
- Updated expression
-
findRedundantFilterVariables
Method to process the provided filter expression and find any variables that are to all intents and purposes redundant. Checks for "var == this". In this case we can just replace the variable occurrences with "this".- Parameters:
filterExpr- The filtervarNames- The variable names that are redundant (updated by this method)
-