core/src/main/java/com/orientechnologies/orient/core/sql/OCommandExecutorSQLSelect.java
public OCommandExecutorSQLSelect parse(final OCommandRequest iRequest) {
    final OCommandRequestText textRequest = (OCommandRequestText) iRequest;
    String queryText = textRequest.getText();
    String originalQuery = queryText;
    try {
      // System.out.println("NEW PARSER FROM: " + queryText);
      queryText = preParse(queryText, iRequest);
      // System.out.println("NEW PARSER TO: " + queryText);
      textRequest.setText(queryText);

      super.parse(iRequest);

      initContext();

      final int pos = parseProjections();
      if (pos == -1) {
        return this;
      }

      final int endPosition = parserText.length();

      parserNextWord(true);
      if (parserGetLastWord().equalsIgnoreCase(KEYWORD_FROM)) {
        // FROM
        parsedTarget = OSQLEngine.getInstance()
            .parseTarget(parserText.substring(parserGetCurrentPosition(), endPosition), getContext());
        parserSetCurrentPosition(
            parsedTarget.parserIsEnded() ? endPosition : parsedTarget.parserGetCurrentPosition() + parserGetCurrentPosition());
      } else {
        parserGoBack();
      }

      if (!parserIsEnded()) {
        parserSkipWhiteSpaces();

        while (!parserIsEnded()) {
          final String w = parserNextWord(true);

          if (!w.isEmpty()) {
            if (w.equals(KEYWORD_WHERE)) {
              compiledFilter = OSQLEngine.getInstance()
                  .parseCondition(parserText.substring(parserGetCurrentPosition(), endPosition), getContext(), KEYWORD_WHERE);
              optimize();
              parserSetCurrentPosition(compiledFilter.parserIsEnded() ?
                  endPosition :
                  compiledFilter.parserGetCurrentPosition() + parserGetCurrentPosition());
            } else if (w.equals(KEYWORD_LET)) {
              parseLet();
            } else if (w.equals(KEYWORD_GROUP)) {
              parseGroupBy();
            } else if (w.equals(KEYWORD_ORDER)) {
              parseOrderBy();
            } else if (w.equals(KEYWORD_UNWIND)) {
              parseUnwind();
            } else if (w.equals(KEYWORD_LIMIT)) {
              parseLimit(w);
            } else if (w.equals(KEYWORD_SKIP) || w.equals(KEYWORD_OFFSET)) {
              parseSkip(w);
            } else if (w.equals(KEYWORD_FETCHPLAN)) {
              parseFetchplan(w);
            } else if (w.equals(KEYWORD_NOCACHE)) {
              parseNoCache(w);
            } else if (w.equals(KEYWORD_TIMEOUT)) {
              parseTimeout(w);
            } else if (w.equals(KEYWORD_LOCK)) {
              final String lock = parseLock();

              if (lock.equalsIgnoreCase("DEFAULT")) {
                lockingStrategy = LOCKING_STRATEGY.DEFAULT;
              } else if (lock.equals("NONE")) {
                lockingStrategy = LOCKING_STRATEGY.NONE;
              } else if (lock.equals("RECORD")) {
                lockingStrategy = LOCKING_STRATEGY.EXCLUSIVE_LOCK;
              } else if (lock.equals("SHARED")) {
                lockingStrategy = LOCKING_STRATEGY.SHARED_LOCK;
              }
            } else if (w.equals(KEYWORD_PARALLEL)) {
              parallel = parseParallel(w);
            } else {
              if (preParsedStatement == null) {
                throwParsingException("Invalid keyword '" + w + "'");
              }//if the pre-parsed statement is OK, then you can go on with the rest, the SQL is valid and this is probably a space in a backtick
            }
          }
        }
      }
      if (limit == 0 || limit < -1) {
        throw new IllegalArgumentException("Limit must be > 0 or = -1 (no limit)");
      }
      validateQuery();
    } finally {
      textRequest.setText(originalQuery);
    }

    return this;
  }
public OCommandExecutorSQLSelect parse(final OCommandRequest iRequest) {
    final OCommandRequestText textRequest = (OCommandRequestText) iRequest;
    String queryText = textRequest.getText();
    String originalQuery = queryText;
    try {
      // System.out.println("NEW PARSER FROM: " + queryText);
      queryText = preParse(queryText, iRequest);
      // System.out.println("NEW PARSER TO: " + queryText);
      textRequest.setText(queryText);

      super.parse(iRequest);

      initContext();

      final int pos = parseProjections();
      if (pos == -1) {
        return this;
      }

      final int endPosition = parserText.length();

      parserNextWord(true);
      if (parserGetLastWord().equalsIgnoreCase(KEYWORD_FROM)) {
        // FROM
        parsedTarget = OSQLEngine.getInstance()
            .parseTarget(parserText.substring(parserGetCurrentPosition(), endPosition), getContext());
        parserSetCurrentPosition(
            parsedTarget.parserIsEnded() ? endPosition : parsedTarget.parserGetCurrentPosition() + parserGetCurrentPosition());
      } else {
        parserGoBack();
      }

      if (!parserIsEnded()) {
        parserSkipWhiteSpaces();

        while (!parserIsEnded()) {
          final String w = parserNextWord(true);

          if (!w.isEmpty()) {
            if (w.equals(KEYWORD_WHERE)) {
              compiledFilter = OSQLEngine.getInstance()
                  .parseCondition(parserText.substring(parserGetCurrentPosition(), endPosition), getContext(), KEYWORD_WHERE);
              optimize();
              parserSetCurrentPosition(compiledFilter.parserIsEnded() ?
                  endPosition :
                  compiledFilter.parserGetCurrentPosition() + parserGetCurrentPosition());
            } else if (w.equals(KEYWORD_LET)) {
              parseLet();
            } else if (w.equals(KEYWORD_GROUP)) {
              parseGroupBy();
            } else if (w.equals(KEYWORD_ORDER)) {
              parseOrderBy();
            } else if (w.equals(KEYWORD_UNWIND)) {
              parseUnwind();
            } else if (w.equals(KEYWORD_LIMIT)) {
              parseLimit(w);
            } else if (w.equals(KEYWORD_SKIP) || w.equals(KEYWORD_OFFSET)) {
              parseSkip(w);
            } else if (w.equals(KEYWORD_FETCHPLAN)) {
              parseFetchplan(w);
            } else if (w.equals(KEYWORD_NOCACHE)) {
              parseNoCache(w);
            } else if (w.equals(KEYWORD_TIMEOUT)) {
              parseTimeout(w);
            } else if (w.equals(KEYWORD_LOCK)) {
              final String lock = parseLock();

              if (lock.equalsIgnoreCase("DEFAULT")) {
                lockingStrategy = LOCKING_STRATEGY.DEFAULT;
              } else if (lock.equals("NONE")) {
                lockingStrategy = LOCKING_STRATEGY.NONE;
              } else if (lock.equals("RECORD")) {
                lockingStrategy = LOCKING_STRATEGY.EXCLUSIVE_LOCK;
              } else if (lock.equals("SHARED")) {
                lockingStrategy = LOCKING_STRATEGY.SHARED_LOCK;
              }
            } else if (w.equals(KEYWORD_PARALLEL)) {
              parallel = parseParallel(w);
            } else {
              if (preParsedStatement == null) {
                throwParsingException("Invalid keyword '" + w + "'");
              }//if the pre-parsed statement is OK, then you can go on with the rest, the SQL is valid and this is probably a space in a backtick
            }
          }
        }
      }
      if (limit == 0 || limit < -1) {
        throw new IllegalArgumentException("Limit must be > 0 or = -1 (no limit)");
      }
      validateQuery();
    } finally {
      textRequest.setText(originalQuery);
    }

    return this;
  }
public OCommandExecutorSQLSelect parse ( final OCommandRequest iRequest ) { final OCommandRequestText textRequest = ( OCommandRequestText ) iRequest ; String queryText = textRequest . getText ( ) ; String originalQuery = queryText ; try { // System.out.println("NEW PARSER FROM: " + queryText);
 queryText = preParse ( queryText , iRequest ) ; // System.out.println("NEW PARSER TO: " + queryText);
 textRequest . setText ( queryText ) ; super . parse ( iRequest ) ; initContext ( ) ; final int pos = parseProjections ( ) ; if ( pos == - 1 ) { return this ; } final int endPosition = parserText . length ( ) ; parserNextWord ( true ) ; if ( parserGetLastWord ( ) . equalsIgnoreCase ( KEYWORD_FROM ) ) { // FROM
 parsedTarget = OSQLEngine . getInstance ( ) . parseTarget ( parserText . substring ( parserGetCurrentPosition ( ) , endPosition ) , getContext ( ) ) ; parserSetCurrentPosition ( parsedTarget . parserIsEnded ( ) ? endPosition : parsedTarget . parserGetCurrentPosition ( ) + parserGetCurrentPosition ( ) ) ; } else { parserGoBack ( ) ; } if ( ! parserIsEnded ( ) ) { parserSkipWhiteSpaces ( ) ; while ( ! parserIsEnded ( ) ) { final String w = parserNextWord ( true ) ; if ( ! w . isEmpty ( ) ) { if ( w . equals ( KEYWORD_WHERE ) ) { compiledFilter = OSQLEngine . getInstance ( ) . parseCondition ( parserText . substring ( parserGetCurrentPosition ( ) , endPosition ) , getContext ( ) , KEYWORD_WHERE ) ; optimize ( ) ; parserSetCurrentPosition ( compiledFilter . parserIsEnded ( ) ? endPosition : compiledFilter . parserGetCurrentPosition ( ) + parserGetCurrentPosition ( ) ) ; } else if ( w . equals ( KEYWORD_LET ) ) { parseLet ( ) ; } else if ( w . equals ( KEYWORD_GROUP ) ) { parseGroupBy ( ) ; } else if ( w . equals ( KEYWORD_ORDER ) ) { parseOrderBy ( ) ; } else if ( w . equals ( KEYWORD_UNWIND ) ) { parseUnwind ( ) ; } else if ( w . equals ( KEYWORD_LIMIT ) ) { parseLimit ( w ) ; } else if ( w . equals ( KEYWORD_SKIP ) || w . equals ( KEYWORD_OFFSET ) ) { parseSkip ( w ) ; } else if ( w . equals ( KEYWORD_FETCHPLAN ) ) { parseFetchplan ( w ) ; } else if ( w . equals ( KEYWORD_NOCACHE ) ) { parseNoCache ( w ) ; } else if ( w . equals ( KEYWORD_TIMEOUT ) ) { parseTimeout ( w ) ; } else if ( w . equals ( KEYWORD_LOCK ) ) { final String lock = parseLock ( ) ; if ( lock . equalsIgnoreCase ( "DEFAULT" ) ) { lockingStrategy = LOCKING_STRATEGY . DEFAULT ; } else if ( lock . equals ( "NONE" ) ) { lockingStrategy = LOCKING_STRATEGY . NONE ; } else if ( lock . equals ( "RECORD" ) ) { lockingStrategy = LOCKING_STRATEGY . EXCLUSIVE_LOCK ; } else if ( lock . equals ( "SHARED" ) ) { lockingStrategy = LOCKING_STRATEGY . SHARED_LOCK ; } } else if ( w . equals ( KEYWORD_PARALLEL ) ) { parallel = parseParallel ( w ) ; } else { if ( preParsedStatement == null ) { throwParsingException ( "Invalid keyword '" + w + "'" ) ; } //if the pre-parsed statement is OK, then you can go on with the rest, the SQL is valid and this is probably a space in a backtick
 } } } } if ( limit == 0 || limit < - 1 ) { throw new IllegalArgumentException ( "Limit must be > 0 or = -1 (no limit)" ) ; } validateQuery ( ) ; } finally { textRequest . setText ( originalQuery ) ; } return this ; }
Compile the filter conditions only the first time.
Compile the filter conditions only the first time .