private boolean checkResultsCache(QueryResultsCache.LookupInfo lookupInfo, boolean needsReset) {
    if (lookupInfo == null) {
      return false;
    }
    try {
      // In case this has not been initialized elsewhere.
      QueryResultsCache.initialize(conf);
    } catch (Exception err) {
      throw new IllegalStateException(err);
    }
    // Don't increment the reader count for explain queries.
    boolean isExplainQuery = (ctx.getExplainConfig() != null);
    do {
      QueryResultsCache.CacheEntry cacheEntry = QueryResultsCache.getInstance().lookup(lookupInfo);
      if (cacheEntry != null) {
        // Potentially wait on the cache entry if entry is in PENDING status
        // Blocking here can potentially be dangerous - for example if the global compile lock
        // is used this will block all subsequent queries that try to acquire the compile lock,
        // so it should not be done unless parallel compilation is enabled.
        // We might not want to block for explain queries as well.
        if (cacheEntry.getStatus() == QueryResultsCache.CacheEntryStatus.PENDING) {
          if (!isExplainQuery &&
              conf.getBoolVar(HiveConf.ConfVars.HIVE_QUERY_RESULTS_CACHE_WAIT_FOR_PENDING_RESULTS) &&
              conf.getBoolVar(HiveConf.ConfVars.HIVE_SERVER2_PARALLEL_COMPILATION)) {
            if (!cacheEntry.waitForValidStatus()) {
              LOG.info("Waiting on pending cacheEntry, but it failed to become valid");
              // The pending query we were waiting on failed, but there might still be another
              // pending or completed entry in the cache that can satisfy this query. Lookup again.
              continue;
            }
          } else {
            LOG.info("Not waiting for pending cacheEntry");
            return false;
          }
        }

        if (cacheEntry.getStatus() == QueryResultsCache.CacheEntryStatus.VALID) {
          if (!isExplainQuery) {
            if (!cacheEntry.addReader()) {
              return false;
            }
          }
          // Use the cache rather than full query execution.
          // At this point the caller should return from semantic analysis.
          useCachedResult(cacheEntry, needsReset);
          return true;
        }
      }
    } while (false);
    return false;
  }
Check the query results cache to see if the query represented by the lookupInfo can be
answered using the results cache. If the cache contains a suitable entry, the semantic analyzer
will be configured to use the found cache entry to answer the query.
ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java