Issue Details (XML | Word | Printable)

Key: DERBY-4204
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Knut Anders Hatlen
Reporter: Knut Anders Hatlen
Votes: 1
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Derby

Runtime statistics not collected on re-execution of statement

Created: 30/Apr/09 08:15 AM   Updated: 02/Feb/10 10:04 AM
Component/s: SQL
Affects Version/s: 10.3.1.4
Fix Version/s: 10.5.2.0, 10.6.0.0

Time Tracking:
Not Specified

File Attachments:
  Size
File Licensed for inclusion in ASF works addXPLAINTest.diff 2009-05-13 11:05 PM Bryan Pendleton 4 kB
File Licensed for inclusion in ASF works addXPLAINTestUsingCOUNT.diff 2009-05-14 02:59 PM Bryan Pendleton 4 kB
Text File Licensed for inclusion in ASF works d4204.diff 2009-05-12 11:58 AM Knut Anders Hatlen 5 kB
File Licensed for inclusion in ASF works repro.sql 2009-04-30 08:21 AM Knut Anders Hatlen 0.3 kB
File Licensed for inclusion in ASF works test.diff 2009-05-07 11:22 AM Knut Anders Hatlen 4 kB
Issue Links:
Reference
 

Bug behavior facts: Regression
Resolution Date: 18/May/09 11:15 AM
Labels:


 Description  « Hide
Runtime statistics are only collected the first time an insert/update/delete statement is executed. The behaviour changed between Derby 10.2.2.0 and Derby 10.3.1.4, so this was likely introduced by DERBY-827.

Reported on derby-dev:
http://mail-archives.apache.org/mod_mbox/db-derby-dev/200904.mbox/%3c8a0216de0904291334j4bc715c3s6d46fb65e5953659@mail.gmail.com%3e

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Knut Anders Hatlen made changes - 30/Apr/09 08:16 AM
Field Original Value New Value
Link This issue is related to DERBY-827 [ DERBY-827 ]
Knut Anders Hatlen added a comment - 30/Apr/09 08:21 AM
Here's a script that reproduces the problem.

With Derby 10.2.2.0, the last call to syscs_get_runtimestatistics returns the following:

Statement Name:
null
Statement Text:
insert into t values 1
.
.
.

With 10.3.1.4 (and later), it returns this:

Statement Name:
null
Statement Text:
values syscs_util.syscs_get_runtimestatistics()
.
.
.


The behaviour in 10.2.2.0 is the expected one, since the insert statement was the last one to be executed before syscs_get_runtimestatistics was called.

Re-execution of select statements appears to work as expected.

Knut Anders Hatlen made changes - 30/Apr/09 08:21 AM
Attachment repro.sql [ 12406886 ]
Knut Anders Hatlen made changes - 07/May/09 10:34 AM
Assignee Knut Anders Hatlen [ knutanders ]
Knut Anders Hatlen made changes - 07/May/09 10:34 AM
Status Open [ 1 ] In Progress [ 3 ]
Knut Anders Hatlen added a comment - 07/May/09 11:22 AM
Attached is a patch that adds JUnit test cases that test collection of runtime statistics for SELECT, UPDATE, INSERT, DELETE, VALUES and CALL when re-executing a prepared statement. The test cases for SELECT and VALUES pass, the rest of them fail.

Knut Anders Hatlen made changes - 07/May/09 11:22 AM
Attachment test.diff [ 12407454 ]
Bryan Pendleton added a comment - 07/May/09 01:33 PM
In the trunk, it would be neat if we could write a test case for this using the new XPLAIN tables feature.

I don't think we want to do that for the base patch because it would then be hard to back-port the
patch to 10.5 and earlier.

But if you let me know when you're done with the basic patch, I'll try writing a separate test-only
patch for the trunk which uses the XPLAIN tables feature to confirm this fix.

Knut Anders Hatlen added a comment - 11/May/09 01:19 PM
Good idea, Bryan. I tested it in ij and saw that re-execution of a prepared insert statement resulted in only one row in SYSXPLAIN_STATEMENTS, whereas re-execution of a prepared select statement resulted in one row per execution, so it should be possible to test this bug with the XPLAIN tables too.

Knut Anders Hatlen added a comment - 12/May/09 11:58 AM
First I thought we should reset the NoRowsResultSetImpl's dumpedStats flag, either in close() or when reopening the result set. But when I looked closer, I noticed that dumpedStats is only ever used in close(), and close() is short-circuited before we dump the stats if close() is called again before the result set is reopened. So I think we could just as well remove the flag and rely on the isOpen flag to protect against dumping the same stats multiple times.

The attached patch (d4204.diff) removes the dumpedStats flag and makes close() always dump the stats if the result set is open. It also adds regression tests for this bug.

All the regression tests passed.

Knut Anders Hatlen made changes - 12/May/09 11:58 AM
Attachment d4204.diff [ 12407865 ]
Knut Anders Hatlen made changes - 12/May/09 11:58 AM
Derby Info [Regression] [Patch Available, Regression]
Repository Revision Date User Message
ASF #774281 Wed May 13 10:55:56 UTC 2009 kahatlen 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.
Files Changed
MODIFY /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java

Knut Anders Hatlen added a comment - 13/May/09 10:59 AM
Committed the patch to trunk with revision 774281.

Bryan, it should be OK to add a regression test based on XPLAIN to trunk now, either as part of this issue or as a separate issue.

I'll leave this issue open until the fix has been backported.

Bryan Pendleton added a comment - 13/May/09 11:05 PM
Attached 'addXPLAINTest.diff' is a patch proposal which augments the test
that Knut added to additionally verify that the SYSXPLAIN_STATEMENTS
table sees 5 distinct rows when the statement is executed 5 times.

I verified (by re-introducing the bug in my environment) that prior to the
fix, the UPDATE, DELETE, and INSERT statements only saw 1 row in SYSXPLAIN_STATEMENTS,
while the SELECT and VALUES statements saw 5 rows, while with the
code change in place, all the statements capture 5 rows into SYSXPLAIN_STATEMENTS.

As opposed to the rest of the DERBY-4204 fix, this change should NOT be backported
to prior branches, because the XPLAIN tables feature is only present in the trunk.

Please let me know of any comments on the patch. If it seems OK, I'll commit it to the trunk.

Bryan Pendleton made changes - 13/May/09 11:05 PM
Attachment addXPLAINTest.diff [ 12408062 ]
Bryan Pendleton added a comment - 14/May/09 02:59 PM
Revised the new test slightly to make it more compact, by issuing
a COUNT query and using JDBC.assertFullResultSet to check the result.

Bryan Pendleton made changes - 14/May/09 02:59 PM
Attachment addXPLAINTestUsingCOUNT.diff [ 12408138 ]
Knut Anders Hatlen added a comment - 14/May/09 03:31 PM
Thanks for writing the test, Bryan! The test looks much better now that the boilerplate is removed. +1 to commit.

(One microscopic nit: assertSingleValueResultSet() would simplify the code slightly compared to assertFullResultSet(). And there's a typo in a comment: s/caputured/captured/)

Repository Revision Date User Message
ASF #774830 Thu May 14 15:53:51 UTC 2009 bpendleton DERBY-4204: Statistics not collected on re-execution of statement

This change enhances the DERBY-4204 regression test to verify that the
XPLAIN table form of statistics collection is also re-collected on each
statement re-execution. Without the DERBY-4204 fix, re-execution of DML
statements was only resulting in a single row in the SYSXPLAIN_STATEMENTS
table, while after the fix, the correct results of 5 rows are observed.

This change should NOT be backported to 10.5 and earlier branches, because
it depends on the XPLAIN functionality.
Files Changed
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java

Repository Revision Date User Message
ASF #774831 Thu May 14 15:54:00 UTC 2009 kahatlen DERBY-4204: Runtime statistics not collected on re-execution of statement

Merged fix from trunk (revision 774281).
Files Changed
MODIFY /db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java
MODIFY /db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java
MODIFY /db/derby/code/branches/10.5

Bryan Pendleton added a comment - 14/May/09 03:55 PM
Committed the revised test to the trunk as svn revision 774830. I'm not intending to do any further work on this issue.

Knut Anders Hatlen added a comment - 14/May/09 03:59 PM
Merged the fix to the 10.5 branch and committed revision 774831.

This fix is a candidate for back-porting to 10.4 and 10.3 as well since it's a regression. However, the test case doesn't compile since it uses a helper method not present on the 10.4 branch, so some manual intervention is needed in order to back-port it all the way.

Knut Anders Hatlen made changes - 14/May/09 03:59 PM
Fix Version/s 10.5.1.2 [ 12313870 ]
Fix Version/s 10.6.0.0 [ 12313727 ]
Knut Anders Hatlen added a comment - 18/May/09 11:15 AM
Marking the issue as resolved since the fix has been committed to trunk and to the 10.5 branch.

Knut Anders Hatlen made changes - 18/May/09 11:15 AM
Status In Progress [ 3 ] Resolved [ 5 ]
Derby Info [Patch Available, Regression] [Regression]
Resolution Fixed [ 1 ]
Dag H. Wanvik made changes - 30/Jun/09 03:55 PM
Bug behavior facts [Regression]
Kathey Marsden made changes - 16/Jul/09 09:24 PM
Fix Version/s 10.5.2.0 [ 12314116 ]
Fix Version/s 10.5.1.2 [ 12313870 ]
Knut Anders Hatlen made changes - 02/Feb/10 10:04 AM
Status Resolved [ 5 ] Closed [ 6 ]