private void executeQuery_1(Region region, boolean checkReferentialIntegrity) throws Exception {
    // Region region = CacheUtils.createRegion("pos", Portfolio.class);

    QueryService qs;
    qs = CacheUtils.getQueryService();
    String[] queries =
        {"SELECT DISTINCT * FROM " + SEPARATOR
            + "pos pf where pf.description = 'XXXX'  and pf.status='active' "};
    SelectResults[][] sr = new SelectResults[queries.length][2];

    ObjectType resType1 = null, resType2 = null;
    for (int i = 0; i < queries.length; i++) {
      Query q = null;
      try {
        q = CacheUtils.getQueryService().newQuery(queries[i]);
        QueryObserverImpl observer = new QueryObserverImpl();
        QueryObserverHolder.setInstance(observer);
        sr[i][0] = (SelectResults) q.execute();

        if (!observer.isIndexesUsed) {
          CacheUtils.log("NO INDEX USED");
        } else {
          fail("How did Index get created?");
        }
        // CacheUtils.log(Utils.printResult(r));
        resType1 = sr[i][0].getCollectionType().getElementType();
        resSize1 = (sr[i][0].size());
        CacheUtils.log(resType1);
        // strg1=resType1.getFieldNames();

        set1 = (sr[i][0].asSet());
        for (final Object o : set1) {
          valPf1 = o;
          // valPf1 = stc1.get(strg1[0]);
          // valPos1 = stc1.get(strg1[1]);
          isActive1 = ((Portfolio) valPf1).isActive();

        }
      } catch (Exception e) {
        e.printStackTrace();
        fail(q.getQueryString());
      }
    }

    // Create an Index on status and execute the same query again.

    qs = CacheUtils.getQueryService();
    Index index1 =
        qs.createIndex("statusIndex", IndexType.FUNCTIONAL, "pf.status", SEPARATOR + "pos pf");
    Index index2 =
        qs.createIndex("IdIndex", IndexType.FUNCTIONAL, "pf.iD", SEPARATOR + "pos pf");
    Index index3 =
        qs.createIndex("descriptionIndex", IndexType.FUNCTIONAL, "pf.description",
            SEPARATOR + "pos pf");

    for (int i = 0; i < queries.length; i++) {
      Query q = null;
      try {
        q = CacheUtils.getQueryService().newQuery(queries[i]);
        QueryObserverImpl observer2 = new QueryObserverImpl();
        QueryObserverHolder.setInstance(observer2);
        sr[i][1] = (SelectResults) q.execute();
        if (observer2.isIndexesUsed) {
          assertEquals(1, observer2.indexesUsed.size());
        } else {
          fail("FAILED: Index NOT Used");
        }
        resType2 = sr[i][1].getCollectionType().getElementType();
        resSize2 = (sr[i][1].size());
        CacheUtils.log(resType2);
        // strg2=resType2.getFieldNames();

        set2 = (sr[i][1].asSet());
        for (final Object o : set2) {
          valPf2 = o;
          // valPf2=stc2.get(strg2[0]);
          // valPos2=stc2.get(strg2[1]);
          isActive2 = ((Portfolio) valPf2).isActive();

        }
      } catch (Exception e) {
        e.printStackTrace();
        fail(q.getQueryString());
      }
    }

    if ((resType1).equals(resType2)) {
      CacheUtils.log("Both Search Results are of the same Type i.e.--> " + resType1);
    } else {
      fail("FAILED:Search result Type is different in both the cases");
    }
    if (resSize1 == resSize2 || resSize1 != 0) {
      CacheUtils
          .log("Search Results size is Non Zero and equal in both cases i.e.  Size= " + resSize1);
    } else {
      fail("FAILED:Search result size is different in both the cases");
    }
    itert2 = set2.iterator();
    itert1 = set1.iterator();
    while (itert1.hasNext()) {
      Object pos2 = itert2.next();
      Object pos1 = itert1.next();
      Object posFromRegion = region.get(((Portfolio) pos1).getPk());
      if (!pos1.equals(pos2)) {
        fail(
            "FAILED: In both the Cases the first member of StructSet i.e. Portfolio are different. ");
      }
      if (checkReferentialIntegrity) {
        assertTrue(pos2 == pos1);
        assertTrue(pos2 == posFromRegion);
      }
      /*
       * if( pos1 != pos2 )
       * fail("FAILED: In both the Cases the first member of StructSet i.e. Portfolio are different. "
       * );
       */

      /*
       * if(stc2.get(strg2[1]) != stc1.get(strg1[1]))
       * fail("FAILED: In both the cases Positions are different");
       * if(((Position)stc2.get(strg2[1])).secId != ((Position)stc1.get(strg1[1])).secId)
       * fail("FAILED: In both the cases Positions secIds are different");
       */
      if (((Portfolio) pos2).isActive() != ((Portfolio) pos1).isActive()) {
        fail("FAILED: Status of the Portfolios found are different");
      }
      if (((Portfolio) pos2).getID() != ((Portfolio) pos1).getID()) {
        fail("FAILED: IDs of the Portfolios found are different");
      }
    }
    CacheUtils.compareResultsOfWithAndWithoutIndex(sr, this);

  }
Test index usage on PR region & Local region if the total number of indexes created are more
than the fields used in the where clause of the query and the number of from clause iterators
is One
geode-core/src/integrationTest/java/org/apache/geode/cache/query/functional/IndexWithSngleFrmAndMultCondQryJUnitTest.java