Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AC23810691 for ; Tue, 18 Feb 2014 15:48:10 +0000 (UTC) Received: (qmail 28096 invoked by uid 500); 18 Feb 2014 15:48:10 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 28013 invoked by uid 500); 18 Feb 2014 15:48:03 -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 28000 invoked by uid 99); 18 Feb 2014 15:48:02 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Feb 2014 15:48:02 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.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; Tue, 18 Feb 2014 15:47:58 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 5ECCA23888D7; Tue, 18 Feb 2014 15:47:37 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: derby-commits@db.apache.org From: rhillegas@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140218154737.5ECCA23888D7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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" ); } + /** + *

+ * Verify correct behavior when the target table is read via index probing. + *

+ */ + 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