db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpendle...@apache.org
Subject svn commit: r1502795 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/execute/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Sat, 13 Jul 2013 15:02:43 GMT
Author: bpendleton
Date: Sat Jul 13 15:02:42 2013
New Revision: 1502795

URL: http://svn.apache.org/r1502795
Log:
DERBY-6216: XPLAIN feature does not work, gives XCL16: ResultSet not open

This change adjusts the implementation of the explain-only mode feature,
which is enabled via syscs_util.syscs_set_xplain_mode(1).

Prior to this change, the implementation short-circuited the open() method
of the ResultSet classes, causing the execution engine to terminate
immediately because the result sets were not open.

This change takes an alternate approach, suggested by Knut Anders: the open()
is allowed to proceed normally, but we short-circuit the getNextRow()
method of the ResultSet classes. This way, the result sets all appear to be
normal result sets, open and ready for business, but they do no work and
always produce an empty result.

Then, at the end of the execution, the statistics are gathered. They show
that no work was done, but they contain information about the overall "shape"
of the query plan (which result sets were constructed, and what the overall
result set tree looks like).

We also discovered that we were completely missing regression tests for the
explain-only feature, so this change adds a handful of regression tests,
including an IJ-based test, a simple embedded query, and a test that verifies
that explain-only mode can be turned on and off between executions of a
prepared query.

More testing would clearly be beneficial, but this should at least give us
a feature that basically works.


Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xplain.out   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/xplain.sql   (with props)
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AnyResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BasicNoPutResultSetImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BulkTableScanResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CurrentOfResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DependentResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DistinctScalarAggregateResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DistinctScanResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GroupedAggregateResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/HashScanResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/HashTableResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/IndexRowToBaseRowResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/LastIndexKeyResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MaterializedResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MergeJoinResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MultiProbeTableScanResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NestedLoopJoinResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NestedLoopLeftOuterJoinResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NormalizeResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/OnceResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ProjectRestrictResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RowCountResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RowResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScalarAggregateResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScrollInsensitiveResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/SetOpResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/SortResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/UnionResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VTIResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/WindowResultSet.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangScripts.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XplainStatisticsTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AnyResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AnyResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AnyResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AnyResultSet.java Sat Jul 13 15:02:42 2013
@@ -155,6 +155,9 @@ public class AnyResultSet extends NoPutR
 	 */
 	public ExecRow	getNextRowCore() throws StandardException 
 	{
+		if( isXplainOnlyMode() )
+			return null;
+
 	    ExecRow candidateRow = null;
 		ExecRow secondRow = null;
 	    ExecRow result = null;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BasicNoPutResultSetImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BasicNoPutResultSetImpl.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BasicNoPutResultSetImpl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BasicNoPutResultSetImpl.java Sat Jul 13 15:02:42 2013
@@ -145,6 +145,13 @@ implements NoPutResultSet
 		return activation;
 	}
 
+	protected final boolean isXplainOnlyMode()
+	{
+		LanguageConnectionContext lcc = getLanguageConnectionContext();
+		return
+		  (lcc.getRunTimeStatisticsMode() && lcc.getXplainOnlyMode());
+	}
+
 	// NoPutResultSet interface
 
 	/**
@@ -256,12 +263,7 @@ implements NoPutResultSet
 		attachStatementContext();
 
 		try {
-			LanguageConnectionContext lcc = getLanguageConnectionContext();
-			if(lcc.getRunTimeStatisticsMode() && lcc.getXplainOnlyMode()) {
-				// do nothing
-			} else {
-				openCore();
-			}
+			openCore();
 
 		} catch (StandardException se) {
 			activation.checkStatementValidity();
@@ -463,8 +465,8 @@ implements NoPutResultSet
 	 */
 	public final ExecRow	getNextRow() throws StandardException 
 	{
-		LanguageConnectionContext lcc = getLanguageConnectionContext();
-		if(lcc.getRunTimeStatisticsMode() && lcc.getXplainOnlyMode()){
+		if( isXplainOnlyMode() )
+		{
 			// return null to indicate no results available and 
 			// to bypass the execution
 			return null;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BulkTableScanResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BulkTableScanResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BulkTableScanResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BulkTableScanResultSet.java Sat Jul 13 15:02:42 2013
@@ -286,6 +286,9 @@ class BulkTableScanResultSet extends Tab
 	 */
 	public ExecRow getNextRowCore() throws StandardException
 	{
+		if( isXplainOnlyMode() )
+			return null;
+
 	    ExecRow result = null;
             
         checkCancellationFlag();

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CurrentOfResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CurrentOfResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CurrentOfResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CurrentOfResultSet.java Sat Jul 13 15:02:42 2013
@@ -100,6 +100,9 @@ class CurrentOfResultSet extends NoPutRe
      */
 	public ExecRow	getNextRowCore() throws StandardException {
 
+		if( isXplainOnlyMode() )
+			return null;
+
 		if ( isOpen ) {
 	        if ( ! next ) {
 	            next = true;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DependentResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DependentResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DependentResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DependentResultSet.java Sat Jul 13 15:02:42 2013
@@ -337,6 +337,9 @@ class DependentResultSet extends ScanRes
 	public ExecRow	getNextRowCore() throws StandardException 
 	{
 		
+		if( isXplainOnlyMode() )
+			return null;
+
 		beginTime = getCurrentTimeMillis();
 		if (searchRow == null)
 		{

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DistinctScalarAggregateResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DistinctScalarAggregateResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DistinctScalarAggregateResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DistinctScalarAggregateResultSet.java Sat Jul 13 15:02:42 2013
@@ -170,6 +170,9 @@ class DistinctScalarAggregateResultSet e
 	 */
 	public ExecRow	getNextRowCore() throws StandardException 
 	{
+		if( isXplainOnlyMode() )
+			return null;
+
 	    ExecIndexRow execIndexRow = null;
 	    ExecIndexRow aggResult = null;
 		boolean	cloneArg = true;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DistinctScanResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DistinctScanResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DistinctScanResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DistinctScanResultSet.java Sat Jul 13 15:02:42 2013
@@ -96,6 +96,9 @@ class DistinctScanResultSet extends Hash
 	 */
 	public ExecRow getNextRowCore() throws StandardException
 	{
+		if( isXplainOnlyMode() )
+			return null;
+
 	    ExecRow result = null;
 
 		beginTime = getCurrentTimeMillis();

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GroupedAggregateResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GroupedAggregateResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GroupedAggregateResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GroupedAggregateResultSet.java Sat Jul 13 15:02:42 2013
@@ -359,6 +359,9 @@ class GroupedAggregateResultSet extends 
 	 */
 	public ExecRow	getNextRowCore() throws StandardException 
 	{
+		if( isXplainOnlyMode() )
+			return null;
+
 		if (!isOpen)
 		{
 			return null;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/HashScanResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/HashScanResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/HashScanResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/HashScanResultSet.java Sat Jul 13 15:02:42 2013
@@ -360,6 +360,9 @@ public class HashScanResultSet extends S
 	 */
 	public ExecRow getNextRowCore() throws StandardException
 	{
+		if( isXplainOnlyMode() )
+			return null;
+
 	    ExecRow result = null;
 		DataValueDescriptor[] columns = null;
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/HashTableResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/HashTableResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/HashTableResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/HashTableResultSet.java Sat Jul 13 15:02:42 2013
@@ -298,6 +298,9 @@ class HashTableResultSet extends NoPutRe
 	 * @return the next row in the result
 	 */
 	public ExecRow	getNextRowCore() throws StandardException {
+		if( isXplainOnlyMode() )
+			return null;
+
 	    ExecRow result = null;
 		DataValueDescriptor[] columns = null;
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/IndexRowToBaseRowResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/IndexRowToBaseRowResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/IndexRowToBaseRowResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/IndexRowToBaseRowResultSet.java Sat Jul 13 15:02:42 2013
@@ -300,6 +300,8 @@ class IndexRowToBaseRowResultSet extends
 	 * @return the next row in the result
 	 */
 	public ExecRow	getNextRowCore() throws StandardException {
+		if( isXplainOnlyMode() )
+			return null;
 
 	    ExecRow sourceRow = null;
 		ExecRow retval = null;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/LastIndexKeyResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/LastIndexKeyResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/LastIndexKeyResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/LastIndexKeyResultSet.java Sat Jul 13 15:02:42 2013
@@ -201,6 +201,9 @@ class LastIndexKeyResultSet extends Scan
 	 */
 	public ExecRow getNextRowCore() throws StandardException
 	{
+		if( isXplainOnlyMode() )
+			return null;
+
 		if (returnedRow || !isOpen)
 		{
 		    clearCurrentRow();

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MaterializedResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MaterializedResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MaterializedResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MaterializedResultSet.java Sat Jul 13 15:02:42 2013
@@ -176,6 +176,9 @@ class MaterializedResultSet extends NoPu
 	 */
 	public ExecRow	getNextRowCore() throws StandardException
 	{
+		if( isXplainOnlyMode() )
+			return null;
+
 		ExecRow result = null;
 
 		beginTime = getCurrentTimeMillis();

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MergeJoinResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MergeJoinResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MergeJoinResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MergeJoinResultSet.java Sat Jul 13 15:02:42 2013
@@ -116,6 +116,9 @@ class MergeJoinResultSet extends JoinRes
 	 */
 	public ExecRow	getNextRowCore() throws StandardException
 	{
+		if( isXplainOnlyMode() )
+			return null;
+
 		beginTime = getCurrentTimeMillis();
 		if (! isOpen)
 			throw StandardException.newException(SQLState.LANG_RESULT_SET_NOT_OPEN, "next");

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MultiProbeTableScanResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MultiProbeTableScanResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MultiProbeTableScanResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MultiProbeTableScanResultSet.java Sat Jul 13 15:02:42 2013
@@ -416,6 +416,9 @@ class MultiProbeTableScanResultSet exten
      */
     public ExecRow getNextRowCore() throws StandardException
     {
+		if( isXplainOnlyMode() )
+			return null;
+
         checkCancellationFlag();
 
         // Step 1.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NestedLoopJoinResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NestedLoopJoinResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NestedLoopJoinResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NestedLoopJoinResultSet.java Sat Jul 13 15:02:42 2013
@@ -74,6 +74,9 @@ class NestedLoopJoinResultSet extends Jo
 	 */
 	public ExecRow	getNextRowCore() throws StandardException
 	{
+		if( isXplainOnlyMode() )
+			return null;
+
 	    ExecRow result = null;
 		boolean haveRow = false;
 	    boolean restrict = false;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NestedLoopLeftOuterJoinResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NestedLoopLeftOuterJoinResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NestedLoopLeftOuterJoinResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NestedLoopLeftOuterJoinResultSet.java Sat Jul 13 15:02:42 2013
@@ -68,6 +68,9 @@ class NestedLoopLeftOuterJoinResultSet e
 	 */
 	public ExecRow	getNextRowCore() throws StandardException
 	{
+		if( isXplainOnlyMode() )
+			return null;
+
 	    ExecRow result = null;
 		boolean haveRow = false;
 	    boolean restrict = false;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NormalizeResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NormalizeResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NormalizeResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/NormalizeResultSet.java Sat Jul 13 15:02:42 2013
@@ -175,6 +175,9 @@ class NormalizeResultSet extends NoPutRe
 	 */
 	public ExecRow	getNextRowCore() throws StandardException
 	{
+		if( isXplainOnlyMode() )
+			return null;
+
 		ExecRow		sourceRow = null;
 		ExecRow		result = null;
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/OnceResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/OnceResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/OnceResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/OnceResultSet.java Sat Jul 13 15:02:42 2013
@@ -161,6 +161,9 @@ public class OnceResultSet extends NoPut
 	 */
 	public ExecRow	getNextRowCore() throws StandardException 
 	{
+		if( isXplainOnlyMode() )
+			return null;
+
 	    ExecRow candidateRow = null;
 		ExecRow secondRow = null;
 	    ExecRow result = null;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ProjectRestrictResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ProjectRestrictResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ProjectRestrictResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ProjectRestrictResultSet.java Sat Jul 13 15:02:42 2013
@@ -242,6 +242,8 @@ class ProjectRestrictResultSet extends N
 	 * @return the next row in the result
 	 */
 	public ExecRow	getNextRowCore() throws StandardException {
+		if( isXplainOnlyMode() )
+			return null;
 
 	    ExecRow candidateRow = null;
 	    ExecRow result = null;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RowCountResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RowCountResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RowCountResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RowCountResultSet.java Sat Jul 13 15:02:42 2013
@@ -180,6 +180,8 @@ class RowCountResultSet extends NoPutRes
      * @return the next row in the result
      */
     public ExecRow  getNextRowCore() throws StandardException {
+	if( isXplainOnlyMode() )
+		return null;
 
         ExecRow result = null;
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RowResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RowResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RowResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RowResultSet.java Sat Jul 13 15:02:42 2013
@@ -131,6 +131,8 @@ class RowResultSet extends NoPutResultSe
 	 * @exception StandardException thrown on failure.
      */
 	public ExecRow	getNextRowCore() throws StandardException {
+		if( isXplainOnlyMode() )
+			return null;
 
 		currentRow = null;
 		beginTime = getCurrentTimeMillis();

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScalarAggregateResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScalarAggregateResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScalarAggregateResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScalarAggregateResultSet.java Sat Jul 13 15:02:42 2013
@@ -152,6 +152,9 @@ class ScalarAggregateResultSet extends G
 	 */
 	public ExecRow	getNextRowCore() throws StandardException 
 	{
+		if( isXplainOnlyMode() )
+			return null;
+
 		if (nextSatisfied)
 		{
 			clearCurrentRow();

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScrollInsensitiveResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScrollInsensitiveResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScrollInsensitiveResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScrollInsensitiveResultSet.java Sat Jul 13 15:02:42 2013
@@ -499,6 +499,9 @@ public class ScrollInsensitiveResultSet 
 	 */
 	public ExecRow	getNextRowCore() throws StandardException
 	{
+		if( isXplainOnlyMode() )
+			return null;
+
 		ExecRow result = null;
 
 		beginTime = getCurrentTimeMillis();

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/SetOpResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/SetOpResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/SetOpResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/SetOpResultSet.java Sat Jul 13 15:02:42 2013
@@ -135,6 +135,9 @@ class SetOpResultSet extends NoPutResult
 	 */
 	public ExecRow	getNextRowCore() throws StandardException
     {
+		if( isXplainOnlyMode() )
+			return null;
+
 		beginTime = getCurrentTimeMillis();
 	    if ( isOpen )
         {

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/SortResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/SortResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/SortResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/SortResultSet.java Sat Jul 13 15:02:42 2013
@@ -332,6 +332,9 @@ class SortResultSet extends NoPutResultS
 	 */
 	public ExecRow	getNextRowCore() throws StandardException 
 	{
+		if( isXplainOnlyMode() )
+			return null;
+
 		if (!isOpen)
 		{
 			return null;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java Sat Jul 13 15:02:42 2013
@@ -453,6 +453,9 @@ class TableScanResultSet extends ScanRes
 	 */
 	public ExecRow getNextRowCore() throws StandardException
 	{
+		if( isXplainOnlyMode() )
+			return null;
+
         checkCancellationFlag();
             
 		if (currentRow == null || scanRepositioned)

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/UnionResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/UnionResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/UnionResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/UnionResultSet.java Sat Jul 13 15:02:42 2013
@@ -115,6 +115,9 @@ class UnionResultSet extends NoPutResult
  	 *	@exception StandardException thrown on failure
 	 */
 	public ExecRow	getNextRowCore() throws StandardException {
+		if( isXplainOnlyMode() )
+			return null;
+
 	    ExecRow result = null;
 
 		beginTime = getCurrentTimeMillis();

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VTIResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VTIResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VTIResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VTIResultSet.java Sat Jul 13 15:02:42 2013
@@ -400,6 +400,9 @@ class VTIResultSet extends NoPutResultSe
      */
 	public ExecRow	getNextRowCore() throws StandardException 
 	{
+		if( isXplainOnlyMode() )
+			return null;
+
 	    ExecRow result = null;
 
 		beginTime = getCurrentTimeMillis();

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/WindowResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/WindowResultSet.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/WindowResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/WindowResultSet.java Sat Jul 13 15:02:42 2013
@@ -175,6 +175,9 @@ class WindowResultSet extends NoPutResul
      */
     public ExecRow getNextRowCore() throws StandardException
     {
+		if( isXplainOnlyMode() )
+			return null;
+
         ExecRow sourceRow = null;
         ExecRow retval = null;
         boolean restrict = false;

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xplain.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xplain.out?rev=1502795&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xplain.out (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xplain.out Sat Jul 13 15:02:42 2013
@@ -0,0 +1,105 @@
+ij> --
+--   Licensed to the Apache Software Foundation (ASF) under one or more
+--   contributor license agreements.  See the NOTICE file distributed with
+--   this work for additional information regarding copyright ownership.
+--   The ASF licenses this file to You under the Apache License, Version 2.0
+--   (the "License"); you may not use this file except in compliance with
+--   the License.  You may obtain a copy of the License at
+--
+--      http://www.apache.org/licenses/LICENSE-2.0
+--
+--   Unless required by applicable law or agreed to in writing, software
+--   distributed under the License is distributed on an "AS IS" BASIS,
+--   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+--   See the License for the specific language governing permissions and
+--   limitations under the License.
+--
+create table derby6216( a int, status varchar(10));
+0 rows inserted/updated/deleted
+ij> insert into derby6216 values (1, 'ACTIVE'), (2, 'IDLE');
+2 rows inserted/updated/deleted
+ij> call syscs_util.syscs_set_runtimestatistics(1);
+0 rows inserted/updated/deleted
+ij> call syscs_util.syscs_set_xplain_schema('STATS');
+0 rows inserted/updated/deleted
+ij> call syscs_util.syscs_set_xplain_mode(1);
+0 rows inserted/updated/deleted
+ij> select a from derby6216 where status != 'IDLE';
+A          
+-----------
+ij> call syscs_util.syscs_set_xplain_mode(0);
+0 rows inserted/updated/deleted
+ij> call syscs_util.syscs_set_runtimestatistics(0);
+0 rows inserted/updated/deleted
+ij> call syscs_util.syscs_set_xplain_schema('');
+0 rows inserted/updated/deleted
+ij> select stmt_text from stats.sysxplain_statements;
+STMT_TEXT                                                                                                                       
+--------------------------------------------------------------------------------------------------------------------------------
+select a from derby6216 where status != 'IDLE'                                                                                  
+ij> select st.stmt_text, rs.op_identifier
+       from stats.sysxplain_statements st
+       join stats.sysxplain_resultsets rs
+         on st.stmt_id = rs.stmt_id
+       order by st.stmt_text,rs.op_identifier;
+STMT_TEXT                                                                                                                       |OP_IDENTIFIER                                                                                                                   
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+select a from derby6216 where status != 'IDLE'                                                                                  |PROJECTION                                                                                                                      
+select a from derby6216 where status != 'IDLE'                                                                                  |TABLESCAN                                                                                                                       
+ij> select st.stmt_text, sp.no_visited_pages, sp.no_visited_rows 
+    from stats.sysxplain_scan_props sp, 
+         stats.sysxplain_resultsets rs, 
+         stats.sysxplain_statements st 
+    where st.stmt_id = rs.stmt_id and 
+          rs.scan_rs_id = sp.scan_rs_id and 
+          rs.op_identifier = 'TABLESCAN' and 
+          sp.scan_object_name = 'DERBY6216';
+STMT_TEXT                                                                                                                       |NO_VISITED&|NO_VISITED&
+--------------------------------------------------------------------------------------------------------------------------------------------------------
+select a from derby6216 where status != 'IDLE'                                                                                  |0          |0          
+ij> drop table stats.sysxplain_statements;
+0 rows inserted/updated/deleted
+ij> drop table stats.sysxplain_resultsets;
+0 rows inserted/updated/deleted
+ij> drop table stats.sysxplain_scan_props;
+0 rows inserted/updated/deleted
+ij> drop table stats.sysxplain_sort_props;
+0 rows inserted/updated/deleted
+ij> call syscs_util.syscs_set_runtimestatistics(1);
+0 rows inserted/updated/deleted
+ij> call syscs_util.syscs_set_xplain_schema('STATS');
+0 rows inserted/updated/deleted
+ij> call syscs_util.syscs_set_xplain_mode(1);
+0 rows inserted/updated/deleted
+ij> select sql_text from syscs_diag.transaction_table where status != 'IDLE';
+SQL_TEXT                                                                                                                        
+--------------------------------------------------------------------------------------------------------------------------------
+ij> call syscs_util.syscs_set_xplain_mode(0);
+0 rows inserted/updated/deleted
+ij> call syscs_util.syscs_set_runtimestatistics(0);
+0 rows inserted/updated/deleted
+ij> call syscs_util.syscs_set_xplain_schema('');
+0 rows inserted/updated/deleted
+ij> select stmt_text from stats.sysxplain_statements;
+STMT_TEXT                                                                                                                       
+--------------------------------------------------------------------------------------------------------------------------------
+select sql_text from syscs_diag.transaction_table where status != 'IDLE'                                                        
+ij> select st.stmt_text, rs.op_identifier, rs.op_details, rs.returned_rows
+       from stats.sysxplain_statements st
+       join stats.sysxplain_resultsets rs
+         on st.stmt_id = rs.stmt_id
+       order by st.stmt_text,rs.op_identifier;
+STMT_TEXT                                                                                                                       |OP_IDENTIFIER                                                                                                                   |OP_DETAILS                                                                                                                      |RETURNED_R&
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+select sql_text from syscs_diag.transaction_table where status != 'IDLE'                                                        |PROJECT-FILTER                                                                                                                  |2;                                                                                                                              |0          
+select sql_text from syscs_diag.transaction_table where status != 'IDLE'                                                        |PROJECTION                                                                                                                      |3;                                                                                                                              |0          
+select sql_text from syscs_diag.transaction_table where status != 'IDLE'                                                        |VTI                                                                                                                             |org.apache.derby.diag.TransactionTable, (1)                                                                                     |0          
+ij> select count(*) from stats.sysxplain_scan_props;
+1          
+-----------
+0          
+ij> select count(*) from stats.sysxplain_sort_props;
+1          
+-----------
+0          
+ij> 
\ No newline at end of file

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xplain.out
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangScripts.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangScripts.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangScripts.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangScripts.java Sat Jul 13 15:02:42 2013
@@ -92,6 +92,7 @@ public final class LangScripts extends S
         "union",
         "update",
         "valuesclause",
+        "xplain",
         };
     
     /**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XplainStatisticsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XplainStatisticsTest.java?rev=1502795&r1=1502794&r2=1502795&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XplainStatisticsTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XplainStatisticsTest.java Sat Jul 13 15:02:42 2013
@@ -71,7 +71,7 @@ import org.w3c.dom.NodeList;
  *
  * FIXME -- some general to-do items that I don't want to forget:
  * - should resultSetNumber be its own column in sysxplain_resultsets?
- * - need tests of xplain-only mode
+ * - need MORE tests of xplain-only mode
  * - need a test of external sorting/merging
  * - need to cross-check the result set types, and verify that they're
  *   all tested at least once
@@ -509,6 +509,18 @@ public class XplainStatisticsTest extend
         s.execute("call syscs_util.syscs_set_statistics_timing(1)");
     }
     
+    private static void enableXplainOnlyMode(Statement s)
+            throws SQLException
+    {
+        s.execute("call syscs_util.syscs_set_xplain_mode(1)");
+    }
+    
+    private static void clearXplainOnlyMode(Statement s)
+            throws SQLException
+    {
+        s.execute("call syscs_util.syscs_set_xplain_mode(0)");
+    }
+    
     /**
      * 
      * @param s
@@ -548,6 +560,7 @@ public class XplainStatisticsTest extend
     					null);
     		}
     	} 
+        s.execute("call syscs_util.syscs_set_xplain_schema('')");
     }
 
     private static void verifyXplainUnset(Statement s)
@@ -613,6 +626,32 @@ public class XplainStatisticsTest extend
         rs.close();
     }
     
+    private void dumpStatements(Statement s)
+        throws SQLException
+    {
+        ResultSet rs;
+        rs = s.executeQuery("select * from xpltest.sysxplain_statements");
+        while (rs.next())
+        {
+            System.out.println(
+                    rs.getString("stmt_id")+","+
+                    rs.getString("stmt_name")+","+
+                    rs.getString("stmt_type")+","+
+                    rs.getString("stmt_text")+","+
+                    rs.getString("jvm_id")+","+
+                    rs.getString("os_identifier")+","+
+                    rs.getString("xplain_mode")+","+
+                    rs.getString("xplain_time")+","+
+                    rs.getString("xplain_thread_id")+","+
+                    rs.getString("transaction_id")+","+
+                    rs.getString("session_id")+","+
+                    rs.getString("database_name")+","+
+                    rs.getString("drda_id")+","+
+                    rs.getString("timing_id"));
+        }
+        rs.close();
+    }
+    
     /**
      * Added by DERBY-4587
      * Returns the stmt_id for this particular statement
@@ -1034,6 +1073,298 @@ public class XplainStatisticsTest extend
         }
     }
     
+    private String getStmtIDByName(Statement s, String sName)
+			throws SQLException
+    {
+    	ResultSet rs;
+        String stmt_id = "?";
+        rs = s.executeQuery( 
+    		"select stmt_id from XPLTEST.sysxplain_statements "+
+		"where stmt_name='"+sName+"'"); 
+        if( rs.next() )
+	{
+            stmt_id = rs.getString(1); 
+	    //System.out.println("Found statemnt id " + stmt_id);
+	}
+        rs.close();
+        return stmt_id;
+    }
+    public void testSimpleXplainOnly() throws Exception
+    {
+        Statement s = createStatement();
+        ResultSet rs;
+
+        enableXplainStyle(s);
+        enableXplainOnlyMode(s);
+	s.setCursorName("1");
+        JDBC.assertEmpty(s.executeQuery(
+        	"SELECT country from countries "+
+	         "WHERE region = 'Central America'" ));
+        clearXplainOnlyMode(s);
+        disableXplainStyle(s);
+
+	// dumpStatements(s);
+        // dumpResultSets(s);
+	// There should be 1 statement captured with stmt_id='1'.
+	// It should have a PROJECTION and a TABLESCAN; the TABLESCAN should be
+	// on the COUNTRIES table.
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+            "select count(*) from xpltest.sysxplain_statements"), "1");
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+            "select count(*) from xpltest.sysxplain_statements "+
+	    "where stmt_name='1'"), "1");
+	String stmt_id = getStmtIDByName( s, "1" );
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+            "select count(*) from xpltest.sysxplain_resultsets "+
+	    "where stmt_id='"+stmt_id+"'"), "2");
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+            "select count(*) from xpltest.sysxplain_resultsets "+
+	    "where stmt_id='"+stmt_id+"' and op_identifier='PROJECTION'"), "1");
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+            "select count(*) from xpltest.sysxplain_resultsets "+
+	    "where stmt_id='"+stmt_id+"' and op_identifier='TABLESCAN'"), "1");
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+            "select op_details from xpltest.sysxplain_resultsets "+
+	    "where stmt_id='"+stmt_id+"' and op_identifier='TABLESCAN'"),
+	    "T: COUNTRIES");
+
+        enableXplainStyle(s);
+        enableXplainOnlyMode(s);
+	s.setCursorName("2");
+        JDBC.assertEmpty(s.executeQuery(
+            "select sql_text from syscs_diag.transaction_table " +
+	    "where status != 'IDLE'" ));
+        clearXplainOnlyMode(s);
+        disableXplainStyle(s);
+
+	//dumpStatements(s);
+        //dumpResultSets(s);
+
+	// This statement should have three result sets:
+	// - PROJECTION (select sql_text)
+	// - PROJECT-FILTER (where status != IDLE)
+	// - VTI (syscs_diag.transaction_table)
+	//
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+            "select count(*) from xpltest.sysxplain_statements"), "1");
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+            "select count(*) from xpltest.sysxplain_statements "+
+	    "where stmt_name='2'"), "1");
+	stmt_id = getStmtIDByName( s, "2" );
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+            "select count(*) from xpltest.sysxplain_resultsets "+
+	    "where stmt_id='"+stmt_id+"' and op_identifier='PROJECTION'"), "1");
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+            "select count(*) from xpltest.sysxplain_resultsets "+
+	    "where stmt_id='"+stmt_id+"' and "+
+	    "      op_identifier='PROJECT-FILTER'"), "1");
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+            "select count(*) from xpltest.sysxplain_resultsets "+
+	    "where stmt_id='"+stmt_id+"' and op_identifier='VTI'"), "1");
+
+        String selectStatement = 
+            "select region, count(country) from app.countries group by region";
+        enableXplainStyle(s);
+        enableXplainOnlyMode(s);
+	s.setCursorName("3");
+        JDBC.assertEmpty(s.executeQuery(selectStatement));
+
+        clearXplainOnlyMode(s);
+        disableXplainStyle(s);
+	//dumpStatements(s);
+        //dumpResultSets(s);
+
+        // This statement is executed as a PROJECTION with a child GROUPBY
+        // with a child PROJECTION with a child TABLESCAN. The TABLESCAN
+        // has a corresponding SCAN_PROPS row, the GROUPBY has a
+        // corresponding SORT_PROPS row. But since we're XPLAIN-ONLY, none
+	// of the actual processing did anything.
+        //
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+            "select count(*) from xpltest.sysxplain_resultsets"), "4");
+        JDBC.assertFullResultSet(s.executeQuery(
+                    "select op_identifier from xpltest.sysxplain_resultsets " +
+                    "order by op_identifier"),
+            new String[][] {
+                {"GROUPBY"},{"PROJECTION"},{"PROJECTION"},{"TABLESCAN"} } );
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+            "select count(*) from xpltest.sysxplain_resultsets " +
+            "where scan_rs_id is not null"), "1");
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+            "select count(*) from xpltest.sysxplain_resultsets " +
+            "where sort_rs_id is not null"), "1");
+        JDBC.assertFullResultSet(s.executeQuery(
+                    "select s.stmt_text, rs.op_identifier," +
+                    " srt.no_input_rows, srt.no_output_rows " +
+                    " from xpltest.sysxplain_sort_props srt, " +
+                    " xpltest.sysxplain_resultsets rs, " +
+                    " xpltest.sysxplain_statements s " +
+                    " where rs.stmt_id = s.stmt_id and " +
+                    " rs.sort_rs_id = srt.sort_rs_id"),
+            new String[][] {
+                {selectStatement, "GROUPBY", "0", "0"} } );
+
+        JDBC.assertUnorderedResultSet(s.executeQuery(
+                    "select srt.sort_type, srt.no_input_rows, " +
+                    " srt.no_output_rows, srt.no_merge_runs, " +
+                    " srt.merge_run_details, srt.eliminate_duplicates, " +
+                    " srt.in_sort_order, srt.distinct_aggregate " +
+                    "from xpltest.sysxplain_sort_props srt " +
+                    "join xpltest.sysxplain_resultsets rs " +
+                    "on srt.sort_rs_id = rs.sort_rs_id " +
+                    "where rs.op_identifier='GROUPBY'"),
+                new String[][] {
+                    {"IN","0","0",null, null, null,"N","N"} } );
+    }
+
+    public void testXplainOnlyExecutePrepared() throws Exception
+    {
+        Statement s = createStatement();
+        ResultSet rs;
+
+        String selectStatement = 
+            "select region, count(country) from app.countries group by region";
+        PreparedStatement ps = prepareStatement( selectStatement );
+        enableXplainStyle(s);
+        enableXplainOnlyMode(s);
+        JDBC.assertEmpty(ps.executeQuery());
+        clearXplainOnlyMode(s);
+        disableXplainStyle(s);
+	//dumpStatements(s);
+        //dumpResultSets(s);
+
+        // This statement is executed as a PROJECTION with a child GROUPBY
+        // with a child PROJECTION with a child TABLESCAN. The TABLESCAN
+        // has a corresponding SCAN_PROPS row, the GROUPBY has a
+        // corresponding SORT_PROPS row. But since we're XPLAIN-ONLY, none
+	// of the actual processing did anything.
+        //
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+            "select count(*) from xpltest.sysxplain_resultsets"), "4");
+        JDBC.assertFullResultSet(s.executeQuery(
+                    "select op_identifier from xpltest.sysxplain_resultsets " +
+                    "order by op_identifier"),
+            new String[][] {
+                {"GROUPBY"},{"PROJECTION"},{"PROJECTION"},{"TABLESCAN"} } );
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+            "select count(*) from xpltest.sysxplain_resultsets " +
+            "where scan_rs_id is not null"), "1");
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+            "select count(*) from xpltest.sysxplain_resultsets " +
+            "where sort_rs_id is not null"), "1");
+        JDBC.assertFullResultSet(s.executeQuery(
+                    "select s.stmt_text, rs.op_identifier," +
+                    " srt.no_input_rows, srt.no_output_rows " +
+                    " from xpltest.sysxplain_sort_props srt, " +
+                    " xpltest.sysxplain_resultsets rs, " +
+                    " xpltest.sysxplain_statements s " +
+                    " where rs.stmt_id = s.stmt_id and " +
+                    " rs.sort_rs_id = srt.sort_rs_id"),
+            new String[][] {
+                {selectStatement, "GROUPBY", "0", "0"} } );
+
+        JDBC.assertUnorderedResultSet(s.executeQuery(
+                    "select srt.sort_type, srt.no_input_rows, " +
+                    " srt.no_output_rows, srt.no_merge_runs, " +
+                    " srt.merge_run_details, srt.eliminate_duplicates, " +
+                    " srt.in_sort_order, srt.distinct_aggregate " +
+                    "from xpltest.sysxplain_sort_props srt " +
+                    "join xpltest.sysxplain_resultsets rs " +
+                    "on srt.sort_rs_id = rs.sort_rs_id " +
+                    "where rs.op_identifier='GROUPBY'"),
+                new String[][] {
+                    {"IN","0","0",null, null, null,"N","N"} } );
+
+	
+	// Since now we're not in XplainOnly mode, the prepared statement
+	// returns the expected normal result set.
+
+        JDBC.assertUnorderedResultSet(ps.executeQuery(),
+            new String[][] { 
+                {"Africa", "19"}, {"Asia", "15"},
+                {"Australia and New Zealand", "2"}, {"Caribbean", "10"},
+                {"Central America", "6"}, {"Central Asia", "4"},
+                {"Europe", "29"}, {"Middle East", "7"},
+                {"North Africa", "5"}, {"North America", "3"},
+                {"Pacific Islands", "3"}, {"South America", "11"} } );
+
+	// And then back to empty again:
+        enableXplainStyle(s);
+        enableXplainOnlyMode(s);
+        JDBC.assertEmpty(ps.executeQuery());
+        clearXplainOnlyMode(s);
+        disableXplainStyle(s);
+    }
+    
+    public void testXplainOnlyPrepared() throws Exception
+    {
+        Statement s = createStatement();
+        ResultSet rs;
+
+        String selectStatement = 
+            "select region, count(country) from app.countries group by region";
+
+        // Try preparing the statement while we're in xplain-only mode, then
+        // execute it normally.
+
+        enableXplainStyle(s);
+        enableXplainOnlyMode(s);
+        PreparedStatement ps2 = prepareStatement( selectStatement );
+        clearXplainOnlyMode(s);
+        JDBC.assertUnorderedResultSet(ps2.executeQuery(),
+            new String[][] { 
+                {"Africa", "19"}, {"Asia", "15"},
+                {"Australia and New Zealand", "2"}, {"Caribbean", "10"},
+                {"Central America", "6"}, {"Central Asia", "4"},
+                {"Europe", "29"}, {"Middle East", "7"},
+                {"North Africa", "5"}, {"North America", "3"},
+                {"Pacific Islands", "3"}, {"South America", "11"} } );
+        disableXplainStyle(s);
+	//dumpStatements(s);
+        //dumpResultSets(s);
+
+        // This statement is executed as a PROJECTION with a child GROUPBY
+        // with a child PROJECTION with a child TABLESCAN. The TABLESCAN
+        // has a corresponding SCAN_PROPS row, the GROUPBY has a
+        // corresponding SORT_PROPS row. But since we're XPLAIN-ONLY, none
+	// of the actual processing did anything.
+        //
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+            "select count(*) from xpltest.sysxplain_resultsets"), "4");
+        JDBC.assertFullResultSet(s.executeQuery(
+                    "select op_identifier from xpltest.sysxplain_resultsets " +
+                    "order by op_identifier"),
+            new String[][] {
+                {"GROUPBY"},{"PROJECTION"},{"PROJECTION"},{"TABLESCAN"} } );
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+            "select count(*) from xpltest.sysxplain_resultsets " +
+            "where scan_rs_id is not null"), "1");
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+            "select count(*) from xpltest.sysxplain_resultsets " +
+            "where sort_rs_id is not null"), "1");
+        JDBC.assertFullResultSet(s.executeQuery(
+                    "select s.stmt_text, rs.op_identifier," +
+                    " srt.no_input_rows, srt.no_output_rows " +
+                    " from xpltest.sysxplain_sort_props srt, " +
+                    " xpltest.sysxplain_resultsets rs, " +
+                    " xpltest.sysxplain_statements s " +
+                    " where rs.stmt_id = s.stmt_id and " +
+                    " rs.sort_rs_id = srt.sort_rs_id"),
+            new String[][] {
+                {selectStatement, "GROUPBY", "114", "12"} } );
+
+        JDBC.assertUnorderedResultSet(s.executeQuery(
+                    "select srt.sort_type, srt.no_input_rows, " +
+                    " srt.no_output_rows, srt.no_merge_runs, " +
+                    " srt.merge_run_details, srt.eliminate_duplicates, " +
+                    " srt.in_sort_order, srt.distinct_aggregate " +
+                    "from xpltest.sysxplain_sort_props srt " +
+                    "join xpltest.sysxplain_resultsets rs " +
+                    "on srt.sort_rs_id = rs.sort_rs_id " +
+                    "where rs.op_identifier='GROUPBY'"),
+                new String[][] {
+                    {"IN","114","12",null, null, null,"N","N"} } );
+    }
     
     
     /**

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/xplain.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/xplain.sql?rev=1502795&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/xplain.sql (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/xplain.sql Sat Jul 13 15:02:42 2013
@@ -0,0 +1,60 @@
+--
+--   Licensed to the Apache Software Foundation (ASF) under one or more
+--   contributor license agreements.  See the NOTICE file distributed with
+--   this work for additional information regarding copyright ownership.
+--   The ASF licenses this file to You under the Apache License, Version 2.0
+--   (the "License"); you may not use this file except in compliance with
+--   the License.  You may obtain a copy of the License at
+--
+--      http://www.apache.org/licenses/LICENSE-2.0
+--
+--   Unless required by applicable law or agreed to in writing, software
+--   distributed under the License is distributed on an "AS IS" BASIS,
+--   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+--   See the License for the specific language governing permissions and
+--   limitations under the License.
+--
+create table derby6216( a int, status varchar(10));
+insert into derby6216 values (1, 'ACTIVE'), (2, 'IDLE');
+call syscs_util.syscs_set_runtimestatistics(1); 
+call syscs_util.syscs_set_xplain_schema('STATS'); 
+call syscs_util.syscs_set_xplain_mode(1); 
+select a from derby6216 where status != 'IDLE'; 
+call syscs_util.syscs_set_xplain_mode(0); 
+call syscs_util.syscs_set_runtimestatistics(0); 
+call syscs_util.syscs_set_xplain_schema(''); 
+select stmt_text from stats.sysxplain_statements;
+select st.stmt_text, rs.op_identifier
+       from stats.sysxplain_statements st
+       join stats.sysxplain_resultsets rs
+         on st.stmt_id = rs.stmt_id
+       order by st.stmt_text,rs.op_identifier;
+select st.stmt_text, sp.no_visited_pages, sp.no_visited_rows 
+    from stats.sysxplain_scan_props sp, 
+         stats.sysxplain_resultsets rs, 
+         stats.sysxplain_statements st 
+    where st.stmt_id = rs.stmt_id and 
+          rs.scan_rs_id = sp.scan_rs_id and 
+          rs.op_identifier = 'TABLESCAN' and 
+          sp.scan_object_name = 'DERBY6216';
+
+drop table stats.sysxplain_statements;
+drop table stats.sysxplain_resultsets;
+drop table stats.sysxplain_scan_props;
+drop table stats.sysxplain_sort_props;
+
+call syscs_util.syscs_set_runtimestatistics(1); 
+call syscs_util.syscs_set_xplain_schema('STATS'); 
+call syscs_util.syscs_set_xplain_mode(1); 
+select sql_text from syscs_diag.transaction_table where status != 'IDLE'; 
+call syscs_util.syscs_set_xplain_mode(0); 
+call syscs_util.syscs_set_runtimestatistics(0); 
+call syscs_util.syscs_set_xplain_schema(''); 
+select stmt_text from stats.sysxplain_statements;
+select st.stmt_text, rs.op_identifier, rs.op_details, rs.returned_rows
+       from stats.sysxplain_statements st
+       join stats.sysxplain_resultsets rs
+         on st.stmt_id = rs.stmt_id
+       order by st.stmt_text,rs.op_identifier;
+select count(*) from stats.sysxplain_scan_props;
+select count(*) from stats.sysxplain_sort_props;

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/xplain.sql
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message