db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1569396 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/sql/execute/ engine/org/apache/derby/impl/sql/compile/ engine/org/apache/derby/impl/sql/execute/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Tue, 18 Feb 2014 15:47:37 GMT
Author: rhillegas
Date: Tue Feb 18 15:47:36 2014
New Revision: 1569396

URL: http://svn.apache.org/r1569396
Log:
DERBY-3155: Propagate RowLocations out of index probes as necessary for the driving left join
of a MERGE statement; commits derby-3155-26-aa-copyRowLocationForIndexScans.diff.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/execute/ResultSetFactory.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/IndexToBaseRowNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericResultSetFactory.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/IndexRowToBaseRowResultSet.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/execute/ResultSetFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/execute/ResultSetFactory.java?rev=1569396&r1=1569395&r2=1569396&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/execute/ResultSetFactory.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/execute/ResultSetFactory.java
Tue Feb 18 15:47:36 2014
@@ -1086,6 +1086,7 @@ public interface ResultSetFactory {
 		@param optimizerEstimatedRowCount	Estimated total # of rows by
 											optimizer
 		@param optimizerEstimatedCost		Estimated total cost by optimizer
+		@param baseColumnCount		Number of columns in the base table
 
 		@return the index row to base row operation as a result set.
 		@exception StandardException thrown when unable to create the
@@ -1105,7 +1106,8 @@ public interface ResultSetFactory {
 								GeneratedMethod restriction,
 								boolean forUpdate,
 								double optimizerEstimatedRowCount,
-								double optimizerEstimatedCost)
+								double optimizerEstimatedCost,
+								int baseColumnCount )
 			throws StandardException;
 
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java?rev=1569396&r1=1569395&r2=1569396&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java Tue
Feb 18 15:47:36 2014
@@ -3211,6 +3211,11 @@ class FromBaseTable extends FromTable
 			heapReferencedCols = getResultColumns().getReferencedFormatableBitSet(isCursorTargetTable(),
true, false) ;
 		}
 		ResultColumnList heapRCL = getResultColumns().compactColumns(isCursorTargetTable(), false);
+		heapRCL.setIndexRow
+            (
+             baseConglomerateDescriptor.getConglomerateNumber(), 
+             forUpdate()
+             );
         retval = new IndexToBaseRowNode(this,
 										baseConglomerateDescriptor,
 										heapRCL,

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/IndexToBaseRowNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/IndexToBaseRowNode.java?rev=1569396&r1=1569395&r2=1569396&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/IndexToBaseRowNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/IndexToBaseRowNode.java
Tue Feb 18 15:47:36 2014
@@ -287,9 +287,10 @@ class IndexToBaseRowNode extends FromTab
 		mb.push(forUpdate);
 		mb.push(getCostEstimate().rowCount());
 		mb.push(getCostEstimate().getEstimatedCost());
+        mb.push( source.getTableDescriptor().getNumberOfColumns() );
 
 		mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getIndexRowToBaseRowResultSet",
-						ClassName.NoPutResultSet, 14);
+						ClassName.NoPutResultSet, 15);
 
 		/* The IndexRowToBaseRowResultSet generator is what we return */
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericResultSetFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericResultSetFactory.java?rev=1569396&r1=1569395&r2=1569396&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericResultSetFactory.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericResultSetFactory.java
Tue Feb 18 15:47:36 2014
@@ -829,7 +829,8 @@ public class GenericResultSetFactory imp
 								GeneratedMethod restriction,
 								boolean forUpdate,
 								double optimizerEstimatedRowCount,
-								double optimizerEstimatedCost)
+								double optimizerEstimatedCost,
+								int baseColumnCount )
 			throws StandardException
 	{
 		return new IndexRowToBaseRowResultSet(
@@ -847,7 +848,8 @@ public class GenericResultSetFactory imp
 								restriction,
 								forUpdate,
 							    optimizerEstimatedRowCount,
-								optimizerEstimatedCost);
+								optimizerEstimatedCost,
+								baseColumnCount);
 	}
 
 	/**

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=1569396&r1=1569395&r2=1569396&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
Tue Feb 18 15:47:36 2014
@@ -80,6 +80,14 @@ class IndexRowToBaseRowResultSet extends
 	public long restrictionTime;
 
     //
+    // For managing row locations which are returned for the left join
+    // which drives the execution of the MERGE statement.
+    //
+    private int _baseColumnCount;
+    private boolean _includeRowLocation;
+	private FormatableBitSet _heapColsWithoutRowLocation;
+
+    //
     // class interface
     //
     IndexRowToBaseRowResultSet(
@@ -97,7 +105,8 @@ class IndexRowToBaseRowResultSet extends
 					GeneratedMethod restriction,
 					boolean forUpdate,
 					double optimizerEstimatedRowCount,
-					double optimizerEstimatedCost) 
+					double optimizerEstimatedCost,
+					int baseColumnCount) 
 		throws StandardException
 	{
 		super(a, resultSetNumber, optimizerEstimatedRowCount, optimizerEstimatedCost);
@@ -111,6 +120,7 @@ class IndexRowToBaseRowResultSet extends
 		this.indexName = indexName;
 		this.forUpdate = forUpdate;
 		this.restriction = restriction;
+        _baseColumnCount = baseColumnCount;
 
 		/* RESOLVE - once we push Qualifiers into the store we
 		 * need to clear their Orderable cache on each open/reopen.
@@ -172,6 +182,18 @@ class IndexRowToBaseRowResultSet extends
 				}
 			}
 		}
+
+        //
+        // The row location column may be needed by the left join which drives
+        // the execution of the MERGE statement.
+        //
+        _includeRowLocation = (_baseColumnCount < accessedHeapCols.getLength());
+        if ( _includeRowLocation )
+        {
+            _heapColsWithoutRowLocation = (FormatableBitSet) accessedHeapCols.clone();
+            _heapColsWithoutRowLocation.clear( accessedHeapCols.getLength() - 1 );
+        }
+
 		recordConstructorTime();
 	}
 
@@ -338,8 +360,12 @@ class IndexRowToBaseRowResultSet extends
 
 				// Fetch the columns coming from the heap
 				boolean row_exists = 
-                    baseCC.fetch(
-                        baseRowLocation, rowArray, accessedHeapCols);
+                    baseCC.fetch
+                    (
+                     baseRowLocation,
+                     rowArray,
+                     _includeRowLocation ? _heapColsWithoutRowLocation : accessedHeapCols
+                     );
 
                 if (row_exists)
                 {
@@ -394,6 +420,11 @@ class IndexRowToBaseRowResultSet extends
 					currentRow = compactRow;
 				}
 
+                if ( _includeRowLocation )
+                {
+                    currentRow.setColumn( currentRow.nColumns(), baseRowLocation );
+                }
+
 				/* Update the run time statistics */
 				rowsSeen++;
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java?rev=1569396&r1=1569395&r2=1569396&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java
Tue Feb 18 15:47:36 2014
@@ -5355,6 +5355,67 @@ public class MergeStatementTest extends 
         goodStatement( dboConnection, "drop table t1_038" );
     }
     
+   /**
+     * <p>
+     * Verify correct behavior when the target table is read via index probing.
+     * </p>
+     */
+    public  void    test_039_indexProbe()
+        throws Exception
+    {
+        Connection  dboConnection = openUserConnection( TEST_DBO );
+
+        //
+        // create schema
+        //
+        goodStatement
+            (
+             dboConnection,
+             "create view sr_039( i ) as values 1"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "create table t1_039( x int, y int, z int )"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "create unique index idx on t1_039( x, y )"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "insert into t1_039 values ( 1, 100, 1000 ), ( 2, 200, 2000 )"
+             );
+
+        // now verify the behavior
+        goodUpdate
+            (
+             dboConnection,
+             "merge into t1_039\n" +
+             "using sr_039 on ( x = 1 )\n" +
+             "when matched then delete\n",
+             1
+             );
+        assertResults
+            (
+             dboConnection,
+             "select * from t1_039 order by x",
+             new String[][]
+             {
+                 { "2", "200", "2000" },
+             },
+             false
+             );
+
+        //
+        // drop schema
+        //
+        goodStatement( dboConnection, "drop view sr_039" );
+        goodStatement( dboConnection, "drop table t1_039" );
+    }
+    
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // ROUTINES



Mime
View raw message