db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From JR <jlr7...@gmail.com>
Subject Incorrect Runtime Statistics
Date Wed, 29 Apr 2009 20:34:49 GMT
I checked out and built the 10.4 branch and am seeing inconsistent
results when requesting the runtime statistics for a prepared
statement. I've tracked it down to the "isTopResultSet" check in the
NoPutResultSetImpl.close() method. It seems that "isTopResultSet"
doesn't get changed for the second (and subsequent) executions of
insert and delete statements. This causes the runtime statistics
update logic to be skipped and will return the stats for the wrong
statement.

I'm including the test that I'm using the verify this behavior. I've
omitted the setup/teardown parts for brevity but I can provide the
full source if it will help. The test fails in the second call to
assertCorrectStatistics() at the call to assertFalse() because the
statistics are for the call to GET_RUNTIMESTATISTICS().

Thanks for any help you can provide.

    private static final String GET_RUNTIMESTATISTICS_QUERY = "VALUES
SYSCS_UTIL.SYSCS_GET_RUNTIMESTATISTICS()";
    private static final String ENABLE_RUNTIMESTATISTICS_CALL = "CALL
SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1)";
    private static final String ENABLE_TIMING_CALL = "CALL
SYSCS_UTIL.SYSCS_SET_STATISTICS_TIMING(1)";
    private static final String CREATE_TABLE = "CREATE TABLE
TEST_TABLE (dummy varchar(1))";
    private static final String DROP_TABLE = "DROP TABLE TEST_TABLE";
    private static final String INSERT_STATEMENT = "INSERT INTO
TEST_TABLE (dummy) VALUES('a')";

    public void testSimpleInsert() throws SQLException {
        Connection conn = DATA_SOURCE.getConnection();
        final PreparedStatement insertStatement =
conn.prepareStatement(INSERT_STATEMENT);

        String stats = null;
        try {
            enableStatistics(conn);

            assertEquals(1, insertStatement.executeUpdate());
            stats = getRuntimeStatistics(conn);
            assertCorrectStatistics(stats, INSERT_STATEMENT);

            assertEquals(1, insertStatement.executeUpdate());
            stats = getRuntimeStatistics(conn);
            assertCorrectStatistics(stats, INSERT_STATEMENT); // FAILS!
        } finally {
            insertStatement.close();
            conn.close();
        }
    }

    private static void assertCorrectStatistics(String stats, String
expectedString) {
        assertNotNull(stats);
        assertFalse("Returned statistics for incorrect statement.", stats
                .contains(GET_RUNTIMESTATISTICS_QUERY));
        assertTrue("Expected string not found in statistics.",
stats.contains(expectedString));
    }

    private static String getRuntimeStatistics(Connection conn) throws
SQLException {
        PreparedStatement planStatement =
conn.prepareStatement(GET_RUNTIMESTATISTICS_QUERY);
        String stats = null;
        ResultSet results = null;
        try {
            results = planStatement.executeQuery();
            results.next();
            stats = results.getString(1);
        } finally {
            if (results != null)
                results.close();
            planStatement.close();
        }
        return stats;
    }

Mime
View raw message