db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r774831 - in /db/derby/code/branches/10.5: ./ java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java
Date Thu, 14 May 2009 15:54:01 GMT
Author: kahatlen
Date: Thu May 14 15:54:00 2009
New Revision: 774831

URL: http://svn.apache.org/viewvc?rev=774831&view=rev
Log:
DERBY-4204: Runtime statistics not collected on re-execution of statement

Merged fix from trunk (revision 774281).

Modified:
    db/derby/code/branches/10.5/   (props changed)
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java

Propchange: db/derby/code/branches/10.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu May 14 15:54:00 2009
@@ -1 +1 @@
-/db/derby/code/trunk:772090,772449,772534
+/db/derby/code/trunk:772090,772449,772534,774281

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java?rev=774831&r1=774830&r2=774831&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java
Thu May 14 15:54:00 2009
@@ -60,7 +60,6 @@
 abstract class NoRowsResultSetImpl implements ResultSet
 {
 	final Activation    activation;
-	private boolean dumpedStats;
 	NoPutResultSet[]	subqueryTrackingArray;
 
 	private final boolean statisticsTimingOn;
@@ -342,7 +341,6 @@
 		if (!isOpen)
 			return;
 
-		if (! dumpedStats)
 		{
 			/*
 			** If run time statistics tracing is turned on, then now is the
@@ -384,7 +382,6 @@
 											  lcc.getRunTimeStatisticsObject().getStatementExecutionPlanText());
 				}
 			}
-			dumpedStats = true;
 		}
 
 		/* This is the top ResultSet, 

Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java?rev=774831&r1=774830&r2=774831&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java
(original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java
Thu May 14 15:54:00 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)");
+    }
+
 }



Mime
View raw message