@Test
  public void testIndexUseSelfJoin() throws Exception {
    String[] queries = {"SELECT DISTINCT * FROM " + SEPARATOR + "pos p1, " + SEPARATOR
        + "pos p2 where p1.status = p2.status",
        "SELECT DISTINCT * FROM " + SEPARATOR + "pos p1, " + SEPARATOR
            + "pos p2 where p1.ID = p2.ID",
        "SELECT DISTINCT * FROM " + SEPARATOR + "pos p1, " + SEPARATOR
            + "pos p2 where p1.P1.secId = p2.P1.secId",
        "SELECT DISTINCT * FROM " + SEPARATOR + "pos p1, " + SEPARATOR
            + "pos p2 where p1.status = p2.status and p1.status = 'active'",
        "SELECT DISTINCT * FROM " + SEPARATOR + "pos p1, " + SEPARATOR
            + "pos p2 where p1.ID = p2.ID and p1.ID < 2",
        "SELECT * FROM " + SEPARATOR + "pos p1, " + SEPARATOR + "pos p2 where p1.ID = p2.ID",
        "SELECT * FROM " + SEPARATOR + "pos p1, " + SEPARATOR
            + "pos p2 where p1.P1.secId = p2.P1.secId",
        "SELECT * FROM " + SEPARATOR + "pos p1, " + SEPARATOR
            + "pos p2 where p1.status = p2.status and p1.status = 'active'",
        "SELECT * FROM " + SEPARATOR + "pos p1, " + SEPARATOR
            + "pos p2 where p1.ID = p2.ID and p1.ID < 2"};

    SelectResults[][] sr = new SelectResults[queries.length][2];
    for (int j = 0; j < queries.length; j++) {
      Query q = qs.newQuery(queries[j]);
      QueryObserverImpl observer = new QueryObserverImpl();
      QueryObserverHolder.setInstance(observer);
      sr[j][0] = (SelectResults) q.execute();
      if (sr[j][0].size() == 0) {
        fail("Query " + q.getQueryString() + " should have returned results");
      }
      if (!observer.isIndexesUsed) {
        fail("Index should have been used for query '" + q.getQueryString() + "'");
      }
    }
    qs.removeIndexes();
    for (int j = 0; j < queries.length; j++) {
      Query q = qs.newQuery(queries[j]);
      QueryObserverImpl observer = new QueryObserverImpl();
      QueryObserverHolder.setInstance(observer);
      sr[j][1] = (SelectResults) q.execute();
      if (sr[j][1].size() == 0) {
        fail("Query " + q.getQueryString() + " should have returned results");
      }
      if (observer.isIndexesUsed) {
        fail("Index should not be used for query '" + q.getQueryString() + "'");
      }
    }
    CacheUtils.compareResultsOfWithAndWithoutIndex(sr);
  }
Test to check if Region short cut method is used for querying, the Primary key index
utilization occurs or not
geode-core/src/integrationTest/java/org/apache/geode/cache/query/internal/index/IndexUseJUnitTest.java