Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 13813 invoked from network); 13 May 2009 10:56:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 13 May 2009 10:56:22 -0000 Received: (qmail 87613 invoked by uid 500); 13 May 2009 10:56:22 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 87573 invoked by uid 500); 13 May 2009 10:56:22 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 87564 invoked by uid 99); 13 May 2009 10:56:22 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 May 2009 10:56:22 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 May 2009 10:56:18 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2632D2388872; Wed, 13 May 2009 10:55:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r774281 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java Date: Wed, 13 May 2009 10:55:56 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090513105557.2632D2388872@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kahatlen Date: Wed May 13 10:55:56 2009 New Revision: 774281 URL: http://svn.apache.org/viewvc?rev=774281&view=rev Log: DERBY-4204: Runtime statistics not collected on re-execution of statement Make sure NoRowsResultSetImpl.close() prints the collected runtime statistics each time close() is called on a result set that is not currently closed. After DERBY-827 close() didn't print the statistics if the result set had been closed and reopened. Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java?rev=774281&r1=774280&r2=774281&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java Wed May 13 10:55:56 2009 @@ -62,7 +62,6 @@ abstract class NoRowsResultSetImpl implements ResultSet { final Activation activation; - private boolean dumpedStats; NoPutResultSet[] subqueryTrackingArray; private final boolean statisticsTimingOn; @@ -344,7 +343,6 @@ if (!isOpen) return; - if (! dumpedStats) { /* ** If run time statistics tracing is turned on, then now is the @@ -382,7 +380,6 @@ visitor.doXPLAIN(rsImpl,activation); } - dumpedStats = true; } /* This is the top ResultSet, Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java?rev=774281&r1=774280&r2=774281&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java Wed May 13 10:55:56 2009 @@ -39,6 +39,8 @@ import org.apache.derbyTesting.junit.BaseJDBCTestCase; import org.apache.derbyTesting.junit.CleanDatabaseTestSetup; import org.apache.derbyTesting.junit.JDBC; +import org.apache.derbyTesting.junit.RuntimeStatisticsParser; +import org.apache.derbyTesting.junit.SQLUtilities; // TODO: // - Add parameters to all PreparedStatements that support it @@ -2132,4 +2134,92 @@ ps.setMaxRows(2); JDBC.assertDrainResults(ps.executeQuery(), 2); } + + // Regression tests for DERBY-4204 (regression from DERBY-827) + /** + * Private helper method that prepares and executes an SQL statement + * multiple times and checks that the runtime statistics for the correct + * statement is collected. + * + * @param sql the SQL text to prepare and execute + */ + private void testRuntimeStatistics(String sql) throws SQLException { + Statement s = createStatement(); + s.execute("call syscs_util.syscs_set_runtimestatistics(1)"); + PreparedStatement ps = prepareStatement(sql); + for (int i = 0; i < 5; i++) { + ps.execute(); + while (true) { + if (ps.getMoreResults()) { + JDBC.assertDrainResults(ps.getResultSet()); + } else if (ps.getUpdateCount() == -1) { + // No result set and no update count means no more results + break; + } + } + RuntimeStatisticsParser rtsp = + SQLUtilities.getRuntimeStatisticsParser(s); + // Before DERBY-4204 the assert below would fail for some kinds + // of statements because the statistics for the previous call to + // SYSCS_GET_RUNTIMESTATISTICS() would be returned instead of the + // statistics for the previously executed statement. + assertTrue("Wrong statement", rtsp.findString(sql, 1)); + } + } + + /** + * Test that runtime statistics are collected on re-execution of a + * SELECT statement. + */ + public void testRuntimeStatisticsForSelect() throws SQLException { + createTestTable("dept", DS, "dept_data"); + testRuntimeStatistics("select * from dept"); + } + + /** + * Test that runtime statistics are collected on re-execution of an + * UPDATE statement. + */ + public void testRuntimeStatisticsForUpdate() throws SQLException { + createTestTable("dept", DS, "dept_data"); + testRuntimeStatistics("update dept set dname = upper(dname)"); + } + + /** + * Test that runtime statistics are collected on re-execution of an + * INSERT statement. + */ + public void testRuntimeStatisticsForInsert() throws SQLException { + createTestTable("dept", DS, "dept_data"); + testRuntimeStatistics("insert into dept select * from dept where 1<>1"); + } + + /** + * Test that runtime statistics are collected on re-execution of a + * DELETE statement. + */ + public void testRuntimeStatisticsForDelete() throws SQLException { + createTestTable("dept", DS, "dept_data"); + testRuntimeStatistics("delete from dept"); + } + + /** + * Test that runtime statistics are collected on re-execution of a + * VALUES statement. + */ + public void testRuntimeStatisticsForValues() throws SQLException { + testRuntimeStatistics("values (1, 2, 3, 'this is a test')"); + } + + /** + * Test that runtime statistics are collected on re-execution of a + * CALL statement. + */ + public void testRuntimeStatisticsForCall() throws SQLException { + createTestTable("dept", DS, "dept_data"); + testRuntimeStatistics( + "call syscs_util.syscs_compress_table(" + + "current schema, 'DEPT', 1)"); + } + }