Class VarThisCompilationOptimiser

  • All Implemented Interfaces:
    CompilationOptimiser

    public class VarThisCompilationOptimiser
    extends java.lang.Object
    implements 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 Detail

      • compilation

        QueryCompilation compilation
        The compilation that we are optimising.
    • Method Detail

      • replaceVariableWithCandidateInExpression

        private Expression replaceVariableWithCandidateInExpression​(java.lang.String varName,
                                                                    Expression expr)
        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 name
        expr - The expression to update
        Returns:
        Updated expression
      • findRedundantFilterVariables

        private void findRedundantFilterVariables​(Expression filterExpr,
                                                  java.util.Set<java.lang.String> varNames)
        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 filter
        varNames - The variable names that are redundant (updated by this method)