Package org.apache.derbyTesting.junit

Examples of org.apache.derbyTesting.junit.RuntimeStatisticsParser


        "AND table1.id=m1.id AND m1.name='PostComponentId' "+
        "AND m1.value='21857' ORDER BY m0.value";

        s.execute("call SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1)");
        ResultSet rs = s.executeQuery(sql1);
    RuntimeStatisticsParser rtsp = SQLUtilities.getRuntimeStatisticsParser(s);
    assertTrue(rtsp.usedTableScan("TABLE2"));
    assertTrue(rtsp.whatSortingRequired());

        rs = s.executeQuery(sql1);
        String[][] result = {
                {"4294967297", "000001", "21857"},
                {"2147483653", "000002", "21857"},
View Full Code Here


        "m1.name='PostComponentId' AND m1.value='21857' " +
        "ORDER BY m0.value";

        s.execute("call SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1)");
        ResultSet rs = s.executeQuery(sql1);
    RuntimeStatisticsParser rtsp = SQLUtilities.getRuntimeStatisticsParser(s);
    assertTrue(rtsp.usedSpecificIndexForIndexScan("TABLE2","KEY3"));
    assertTrue(rtsp.whatSortingRequired());
 
        rs = s.executeQuery(sql1);
        String[][] result = {
                {"4294967297", "000001", "21857"},
                {"2147483653", "000002", "21857"},
View Full Code Here

        "AND table1.id=m1.id AND m1.name='PostComponentId' AND "+
        " m1.value='21857' ORDER BY m0.value";

    s.execute("call SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1)");
        ResultSet rs = s.executeQuery(sql1);
    RuntimeStatisticsParser rtsp = SQLUtilities.getRuntimeStatisticsParser(
        s);
    assertTrue(rtsp.usedSpecificIndexForIndexScan("TABLE2","KEY3"));
    assertTrue(rtsp.whatSortingRequired());

    rs = s.executeQuery(sql1);
        String[][] result = {
                {"4294967297", "000001", "21857"},
                {"2147483653", "000002", "21857"},
View Full Code Here

        rs = st.executeQuery("values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS()");
        rs.next();
        String rts = rs.getString(1);

        // Now verify the correct runtimeStatistics output
        RuntimeStatisticsParser rtsp = new RuntimeStatisticsParser(rts);
        // print out the full stats if derby.tests.debug is true
        println("full stats: \n" + rtsp.toString());
        // Checking only on the sequence of T3 and T1 scans.
        // If further checking is needed, uncomment more lines.
        rtsp.assertSequence(
             new String[] {
                        "Source result set:",
                        "_Project-Restrict ResultSet (5):",
                        "_Source result set:",
                        "__Hash Join ResultSet:",
View Full Code Here

                "values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS()");
            rs.next();
            String rts = rs.getString(1);

            // Now verify the correct runtimeStatistics output
            RuntimeStatisticsParser rtsp = new RuntimeStatisticsParser(rts);
            // print out the full stats if derby.tests.debug is true
            println("full stats: \n" + rtsp.toString());
            // the essentials are getting checked as per the comments
            // above. If further checking is needed, uncomment more lines.
            rtsp.assertSequence(
                    new String[] {
                        "Hash Join ResultSet:",
                        //"Left result set:",
                        //"_Sort ResultSet:",
                        //"_Source result set:",
                        //"__Project-Restrict ResultSet (7):",
                        //"__Source result set:",
                        //"___Nested Loop Join ResultSet:",
                        //"___Left result set:",
                        //"____Project-Restrict ResultSet (5):",
                        //"____Source result set:",
                        //"_____Table Scan ResultSet for T1 at read committed " +
                        //    "isolation level using share row locking chosen " +
                        //    "by the optimizer",
                        //"______Bit set of columns fetched={0}",
                        //"______Scan type=heap",
                        //"___Right result set:",
                        //"____Table Scan ResultSet for T2 at read committed " +
                        //    "isolation level using share row locking chosen " +
                        //    "by the optimizer",
                        //"_____Bit set of columns fetched=All",
                        //"_____Scan type=heap",
                        //"______Operator: =",                       
                        "Right result set:",
                        "_Hash Table ResultSet (13):"
                        //"_Source result set:",
                        //"__Sort ResultSet:",
                        //"__Source result set:",
                        //"___Project-Restrict ResultSet (12):",
                        //"___Source result set:",
                        //"____Hash Join ResultSet:",
                        //"____Left result set:",
                        //"_____Table Scan ResultSet for T3 at read committed " +
                        //    "isolation level using share row locking chosen " +
                        //    "by the optimizer",
                        //"______Bit set of columns fetched=All",
                        //"______Scan type=heap"
                        //,
           // after this, there's something peculiar with the
           // 'Right result set' line output, and this RuntimeStatisticsParser
           // method cannot find any further matches...
                        //"___Right result set:",
                        //"_____Hash Scan ResultSet for T4 at read committed " +
                        //    "isolation level using instantaneous share row" +
                        //    "locking: ",
                        //"______Bit set of columns fetched=All",
                        //"______Scan type=heap",
                        //"_______Operator: ="                       
                            });
            // ...so checking on the remaining output another way.
            assertTrue(rtsp.findString("Right result set:",3));       
            assertTrue(rtsp.findString("Hash Scan ResultSet for T4 at read " +
                "committed isolation level using instantaneous share row " +
                "locking: ",1));       
            //assertTrue(rtsp.findString("Bit set of columns fetched=All",2));       
            //assertTrue(rtsp.findString("Scan type=heap",4));       
           
            // Now add more data to the tables.
            st.executeUpdate("insert into t1 select * from t2");
            st.executeUpdate("insert into t2 select * from t1");
            st.executeUpdate("insert into t2 select * from t1");
            st.executeUpdate("insert into t1 select * from t2");
            st.executeUpdate("insert into t2 select * from t1");
            st.executeUpdate("insert into t1 select * from t2");
            st.executeUpdate("insert into t2 select * from t1");
            st.executeUpdate("insert into t1 select * from t2");
            st.executeUpdate("insert into t2 select * from t1");
            st.executeUpdate("insert into t1 select * from t2");
            st.executeUpdate("insert into t3 select * from t4");
            st.executeUpdate("insert into t4 select * from t3");
            st.executeUpdate("insert into t3 select * from t4");
            st.executeUpdate("insert into t4 select * from t3");
            st.executeUpdate("insert into t3 select * from t4");
            st.executeUpdate("insert into t4 select * from t3");
            st.executeUpdate("insert into t3 select * from t4");
            st.executeUpdate("insert into t4 select * from t3");
            st.executeUpdate("insert into t3 select * from t4");
            st.executeUpdate("insert into t4 select * from t3");
            st.executeUpdate("insert into t3 select * from t4");

            /* Drop the views and recreate them with slightly different
             * names.  The reason we use different names is to ensure that
             * the query will be "different" from the last time and thus we'll
             * we'll go through optimization again (instead of just using
             * the cached plan from last time).
             */

            st.executeUpdate("drop view v1");
            st.executeUpdate("drop view v2");

            // Use of the term "DISTINCT" makes it so that we don't flatten
            // the subqueries.
            st.executeUpdate("create view VV1 as " +
                "select distinct T1.i, T2.j from T1, T2 where T1.i = T2.i");
            st.executeUpdate("create view VV2 as " +
                "select distinct T3.a, T4.b from T3, T4 where T3.a = T4.a");
            // Now execute the query again using the larger tables.
            rs = st.executeQuery(
                "select * from VV1, VV2 " +
                "where VV1.j = VV2.b and VV1.i in (1,2,3,4,5)");
            expColNames = new String [] {"I", "J", "A", "B"};
            JDBC.assertColumnNames(rs, expColNames);
            expRS = new String [][]
                                  {
                    {"2", "2", "2", "2"},
                    {"4", "4", "4", "4"},
                    {"5", "5", "5", "5"}
                                  };
            JDBC.assertFullResultSet(rs, expRS, true);

            rs = st.executeQuery(
                "values SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS()");
            rs.next();
            rts = rs.getString(1);

            // Now verify the correct runtimeStatistics output
            rtsp = new RuntimeStatisticsParser(rts);
            // print out the full stats if derby.tests.debug is true
            println("full stats: \n" + rtsp.toString());
            // the essentials are getting checked as per the comments
            // above. If more detailed checking is needed, uncomment lines.
            rtsp.assertSequence(
                    new String[] {
                        "Hash Join ResultSet:",
                        //"Left result set:",
                        //"_Sort ResultSet:",
                        "_Rows input = 53055",
View Full Code Here

    // simple query SELECT MAX(D1) FROM T1:
    s.execute("call SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1)");
        JDBC.assertFullResultSet(
                s.executeQuery("SELECT MAX(D1) FROM D3904_T1"),
            new String[][] {  {"2008-10-02"} } );
    RuntimeStatisticsParser rtsp =
      SQLUtilities.getRuntimeStatisticsParser(s);
    assertTrue(rtsp.usedLastKeyIndexScan());
    assertFalse(rtsp.usedIndexRowToBaseRow());

    // A form of the Beetle 4423 query:
        JDBC.assertFullResultSet(
                s.executeQuery("SELECT MAX(D1) " +
          "FROM d3904_T1, D3904_T2 WHERE d3904_T1.D1='2008-10-02'"),
View Full Code Here


        s.execute("CALL SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1)");

        ResultSet rs;
        RuntimeStatisticsParser rtsp;

        // 0. Only the variant with the subquery did the re-write of outer to
        // inner join prior to this fix. When the re-write is performed, the
        // optimizer chooses a hash join on CITIES, which substantially speeds
        // up the query.

        rs = s.executeQuery("SELECT * FROM CITIES LEFT OUTER JOIN " +
                            "    (SELECT * FROM FLIGHTS, COUNTRIES) S " +
                            "  ON CITIES.AIRPORT = S.ORIG_AIRPORT " +
                            "  WHERE S.COUNTRY_ISO_CODE = 'US'");

        rtsp = SQLUtilities.getRuntimeStatisticsParser(s);
        assertTrue(rtsp.usedHashJoin());

        // 1. Equivalent variant failed to rewrite prior to patch and was slow.
        rs = s.executeQuery("SELECT * FROM CITIES LEFT OUTER JOIN FLIGHTS " +
                            "    INNER JOIN COUNTRIES ON 1=1 " +
                            "    ON CITIES.AIRPORT = FLIGHTS.ORIG_AIRPORT " +
                            "  WHERE COUNTRIES.COUNTRY_ISO_CODE = 'US'");


        rtsp = SQLUtilities.getRuntimeStatisticsParser(s);

        // Check that outer join has been rewritten
        assertFalse(rtsp.usedNLLeftOuterJoin());
        assertTrue(rtsp.usedHashJoin());


        // 1b. Equivalent variant of 1, just use ROJ instead.
        rs = s.executeQuery("SELECT * FROM FLIGHTS " +
                            "    INNER JOIN COUNTRIES ON 1=1 " +
                            "    RIGHT OUTER JOIN CITIES " +
                            "    ON CITIES.AIRPORT = FLIGHTS.ORIG_AIRPORT " +
                            "  WHERE COUNTRIES.COUNTRY_ISO_CODE = 'US'");


        rtsp = SQLUtilities.getRuntimeStatisticsParser(s);

        // Check that outer join has been rewritten
        assertFalse(rtsp.usedNLLeftOuterJoin()); // ROJ is made LOJ in case
                                                 // still used
        assertTrue(rtsp.usedHashJoin());


        // 2. Equivalent variant failed to rewrite prior to patch and was slow.
        rs = s.executeQuery("SELECT * FROM CITIES LEFT OUTER JOIN " +
                            "   (FLIGHTS CROSS JOIN COUNTRIES) " +
                            "  ON CITIES.AIRPORT = FLIGHTS.ORIG_AIRPORT " +
                            "  WHERE COUNTRIES.COUNTRY_ISO_CODE = 'US'");
        rtsp = SQLUtilities.getRuntimeStatisticsParser(s);

        // Check that outer join has been rewritten
        assertFalse(rtsp.usedNLLeftOuterJoin());
        assertTrue(rtsp.usedHashJoin());

        // 2b. Equivalent variant of 2, just use ROJ instead.
        rs = s.executeQuery(
            "SELECT * FROM " +
            "   (FLIGHTS CROSS JOIN COUNTRIES) RIGHT OUTER JOIN " +
            "    CITIES ON CITIES.AIRPORT = FLIGHTS.ORIG_AIRPORT " +
            "  WHERE COUNTRIES.COUNTRY_ISO_CODE = 'US'");
        rtsp = SQLUtilities.getRuntimeStatisticsParser(s);

        // Check that outer join has been rewritten
        assertFalse(rtsp.usedNLLeftOuterJoin()); // ROJ is made LOJ in case
                                                 // still used
        assertTrue(rtsp.usedHashJoin());

    }
View Full Code Here

     */
    public void testSelectSubqueriesSortAvoidance() throws SQLException {
        setAutoCommit(false);
        Statement s = createStatement();
        ResultSet rs;
        RuntimeStatisticsParser rtsp;
        s.executeUpdate("create table ts(i int, j int)");
        PreparedStatement ps = prepareStatement("insert into ts values(?,?)");
        for (int i=0; i < 100; i++) {
            ps.setInt(1,i);
            ps.setInt(2,i*2);
            ps.execute();
        }

        s.executeUpdate("create unique index t_i on ts(i)");
        s.execute("call SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1)");

        // ORDER BY inside a subquery should make use of index to avoid
        // sorting.
        rs = s.executeQuery("select * from (select i from ts order by i)tt");
        rtsp = SQLUtilities.getRuntimeStatisticsParser(s);

        // Verify that we use the index scan here and no sorting is incurred
        assertTrue(rtsp.usedSpecificIndexForIndexScan("TS","T_I"));
        assertFalse(rtsp.whatSortingRequired());

        s.execute("call SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(0)");
        rollback();
    }
View Full Code Here

                "--DERBY-PROPERTIES joinOrder=fixed \n" +
                "t1, scratch_table s " +
                "where t1.two = s.two " +
                "and s.hundred = CAST(CHAR(t1.hundred) AS INTEGER)").close();
        checkEstimatedRowCount(conn,802001.25);
        RuntimeStatisticsParser rtsp =
                SQLUtilities.getRuntimeStatisticsParser(s);
        assertTrue(rtsp.usedHashJoin());
       
        // preds are on column 2.
        // 0.1 -> 16*10.5
        s.executeQuery("select s.id from " +
                "--DERBY-PROPERTIES joinOrder=fixed \n" +
                "t1, scratch_table s " +
                "where t1.twenty = s.twenty").close();
        checkEstimatedRowCount(conn,1604002.5);
        rtsp = SQLUtilities.getRuntimeStatisticsParser(s);
        assertTrue(rtsp.usedSpecificIndexForIndexScan("T1", "T1_TWO_TWENTY"));
        assertTrue(rtsp.usedHashJoin());
       
        // preds are on column 2,3.
        // 0.01 -> 16*10.4
        s.executeQuery("select s.id from " +
                "--DERBY-PROPERTIES joinOrder=fixed \n" +
                "t1, scratch_table s " +
                "where t1.twenty = s.twenty " +
                "and s.hundred = CAST(CHAR(t1.hundred) AS INTEGER)").close();
        checkEstimatedRowCount(conn,160400.2500000);
        rtsp = SQLUtilities.getRuntimeStatisticsParser(s);
        assertTrue(rtsp.usedSpecificIndexForIndexScan("T1", "T1_TWENTY_HUNDRED"));
        assertTrue(rtsp.usedHashJoin());
    }
View Full Code Here

        s.executeQuery("select t1.id from t1, t2 " +
                "where t1.two = t2.two " +
                "and t1.twenty = t2.twenty " +
                "and t1.hundred = t2.hundred").close();
        checkEstimatedRowCount(conn,4010.00625);
        RuntimeStatisticsParser rtsp =
                SQLUtilities.getRuntimeStatisticsParser(s);
        assertTrue(rtsp.usedHashJoin());
       
        // now muck around with the order of the predicates
        // 2,100,20
        s.executeQuery("select t1.id from t1, t2 " +
                "where t1.two = t2.two " +
                "and t1.hundred = t2.hundred " +
                "and t1.twenty = t2.twenty").close();
        checkEstimatedRowCount(conn,4010.00625);
        rtsp = SQLUtilities.getRuntimeStatisticsParser(s);
        assertTrue(rtsp.usedHashJoin());
       
        // 100,20,2
        s.executeQuery("select t1.id from t1, t2 " +
                "where t1.hundred = t2.hundred " +
                "and t1.twenty = t2.twenty " +
                "and t1.two = t2.two").close();
        checkEstimatedRowCount(conn,4010.00625);
        rtsp = SQLUtilities.getRuntimeStatisticsParser(s);
        assertTrue(rtsp.usedHashJoin());
       
        // 100,2,20
        s.executeQuery("select t1.id from t1, t2 " +
                "where t1.hundred = t2.hundred " +
                "and t1.two = t2.two " +
                "and t1.twenty = t2.twenty").close();
        checkEstimatedRowCount(conn,4010.00625);
        rtsp = SQLUtilities.getRuntimeStatisticsParser(s);
        assertTrue(rtsp.usedHashJoin());
       
        s.executeQuery("select t1.id from t1, t2 " +
                "where t1.twenty = t2.twenty " +
                "and t1.hundred = t2.hundred " +
                "and t1.two = t2.two").close();
        checkEstimatedRowCount(conn,4010.00625);
        rtsp = SQLUtilities.getRuntimeStatisticsParser(s);
        assertTrue(rtsp.usedHashJoin());
       
        s.executeQuery("select t1.id from t1, t2 " +
                "where t1.twenty = t2.twenty " +
                "and t1.two = t2.two " +
                "and t1.hundred = t2.hundred").close();
        checkEstimatedRowCount(conn,4010.00625);
        rtsp = SQLUtilities.getRuntimeStatisticsParser(s);
        assertTrue(rtsp.usedHashJoin());
    }
View Full Code Here

TOP

Related Classes of org.apache.derbyTesting.junit.RuntimeStatisticsParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.