db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From be...@apache.org
Subject svn commit: r406683 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ engine/org/apache/derby/impl/sql/execute/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/master/DerbyNet/...
Date Mon, 15 May 2006 17:10:13 GMT
Author: bernt
Date: Mon May 15 10:10:11 2006
New Revision: 406683

URL: http://svn.apache.org/viewcvs?rev=406683&view=rev
Log:
DERBY-1087 Updatable result sets behave different depending on the type of query used to generate
the result set. Submitted by Fernanda Pizzorno

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/URCoveringIndexTest.java
  (with props)
Modified:
    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/execute/IndexRowToBaseRowResultSet.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dblook_test_net.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dblook_test_net.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dblook_test.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java?rev=406683&r1=406682&r2=406683&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 Mon
May 15 10:10:11 2006
@@ -2721,7 +2721,8 @@
 		}
 		
 		/* No need to go to the data page if this is a covering index */
-		if (ap.getCoveringIndexScan())
+		/* Derby-1087: use data page when returning an updatable resultset */
+		if (ap.getCoveringIndexScan() && (!cursorTargetTable()))
 		{
 			/* Massage resultColumns so that it matches the index. */
 			resultColumns = newResultColumns(resultColumns,

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/IndexRowToBaseRowResultSet.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/IndexRowToBaseRowResultSet.java?rev=406683&r1=406682&r2=406683&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
Mon May 15 10:10:11 2006
@@ -105,17 +105,6 @@
 	protected boolean currentRowPrescanned;
 	private boolean sourceIsForUpdateIndexScan;
 
-	// for scrollable insensitive updatable result sets, the rowLocation of each
-	// row is stored in a hash table, and used to position the scan by calling 
-	// the method positionScanAtRowLocation. When this method is called, the 
-	// baseRowLocation will be set to the value of the cached rowLocation, and
-	// it will not be necessary to read the row from the B-tree in order to get
-	// the rowLocation of the current row.
-	// If positionFromRowLocation is true, then baseRowLocation can be used for
-	// fetching the currentRow, and it is not necessary to read the rowLocation
-	// from the B-tree, otherwise, the rowLocation must be read from the B-tree.
-	private boolean positionFromRowLocation;
-
     //
     // class interface
     //
@@ -223,7 +212,6 @@
 		}
 
 		constructorTime += getElapsedMillis(beginTime);
-		this.positionFromRowLocation = false;
 
     }
 
@@ -614,7 +602,6 @@
 		throws StandardException 
 	{
 		baseRowLocation = rl;
-		positionFromRowLocation = true;
 		source.positionScanAtRowLocation(rl);
 	}
 
@@ -645,84 +632,22 @@
 			return null;
 		}
 
-		// If positionFromRowLocation is true, we can use the baseRowLocation
-		// directly and do not need to read the rowLocation from the b-tree
-		// before fetching the row.
-		if (positionFromRowLocation) {
-			sourceRow = activation.getExecutionFactory().
-					getValueRow(indexCols.length);
-			sourceRow.setRowArray(rowArray);
-			// Fetch the columns coming from the heap
-			boolean row_exists = 
-				baseCC.fetch(
-					baseRowLocation, rowArray, (FormatableBitSet) null);
-			if (row_exists) {
-				setCurrentRow(sourceRow);
-			} else {
-				clearCurrentRow();
-				currentRow = null;
-			}
-			return currentRow;
-		}
-		
-		/* Call the child result set to get it's current row.
-		 * If no row exists, then return null, else requalify it
-		 * before returning.
-		 */
-		sourceRow = ((CursorResultSet) source).getCurrentRow();
-		if (sourceRow != null)
-		{
-			/*
-			** Presumably, if the index row is still there, the RowLocation
-			** it contains is still valid.  This means we don't have to
-			** check whether the row is still there.
-			*/
-			if (SanityManager.DEBUG) {
-				SanityManager.ASSERT(
-					sourceRow.getColumn(sourceRow.nColumns())
-														instanceof RowLocation,
-					"Last column of source row is not a RowLocation"
-						);
-			}
-
-			baseRowLocation = (RowLocation)
-						sourceRow.getColumn(sourceRow.nColumns());
-
-			// Fetch the columns coming from the heap
-			boolean row_exists = 
-                baseCC.fetch(
-                    baseRowLocation, rowArray, (FormatableBitSet) null);
-
-            if (row_exists)
-            {
-				// Copy the columns coming from the index into resultRow
-				for (int index = 0; index < indexCols.length; index++)
-				{
-					if (indexCols[index] != -1)
-					{
-						compactRow.setColumn(
-										index + 1,
-										sourceRow.getColumn(indexCols[index] + 1));
-					}
-				}
-
-                setCurrentRow(compactRow);
-
-                currentRow = compactRow;
-            }
-            else
-            {
-                clearCurrentRow();
-
-                currentRow = null;
-            }
-
-        } else {
+		// We do not need to read the row from the index first, since we already 
+		// have the rowLocation of the current row and can read it directly from 
+		// the heap.
+		sourceRow = activation.getExecutionFactory().
+				getValueRow(indexCols.length);
+		sourceRow.setRowArray(rowArray);
+		// Fetch the columns coming from the heap
+		boolean row_exists = 
+			baseCC.fetch(
+				baseRowLocation, rowArray, (FormatableBitSet) null);
+		if (row_exists) {
+			setCurrentRow(sourceRow);
+		} else {
 			clearCurrentRow();
-
 			currentRow = null;
 		}
-		
 		return currentRow;
 	}
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dblook_test_net.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dblook_test_net.out?rev=406683&r1=406682&r2=406683&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dblook_test_net.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dblook_test_net.out
Mon May 15 10:10:11 2006
@@ -1332,12 +1332,6 @@
 Conglomerate
 -----
 <systemid>
-<StoredPreparedStatement>APP.<sysname> -> <Conglomerate>BAR.<sysname>
-StoredPreparedStatement
-<systemid>
-Conglomerate
------
-<systemid>
 <StoredPreparedStatement>APP.<sysname> -> <Conglomerate>BAR.IX3
 StoredPreparedStatement
 <systemid>
@@ -1480,6 +1474,18 @@
 View
 T6
 ColumnsInTable
+-----
+<systemid>
+<StoredPreparedStatement>APP.<sysname> -> <Conglomerate>BAR.<sysname>
+StoredPreparedStatement
+<systemid>
+Conglomerate
+-----
+<systemid>
+<StoredPreparedStatement>APP.<sysname> -> <Conglomerate>BAR.<sysname>
+StoredPreparedStatement
+<systemid>
+Conglomerate
 -----
 ========== SYSFILES ==========
 <systemid>

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dblook_test_net.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dblook_test_net.out?rev=406683&r1=406682&r2=406683&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dblook_test_net.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dblook_test_net.out
Mon May 15 10:10:11 2006
@@ -1332,12 +1332,6 @@
 Conglomerate
 -----
 <systemid>
-<StoredPreparedStatement>APP.<sysname> -> <Conglomerate>BAR.<sysname>
-StoredPreparedStatement
-<systemid>
-Conglomerate
------
-<systemid>
 <StoredPreparedStatement>APP.<sysname> -> <Conglomerate>BAR.IX3
 StoredPreparedStatement
 <systemid>
@@ -1480,6 +1474,18 @@
 View
 T6
 ColumnsInTable
+-----
+<systemid>
+<StoredPreparedStatement>APP.<sysname> -> <Conglomerate>BAR.<sysname>
+StoredPreparedStatement
+<systemid>
+Conglomerate
+-----
+<systemid>
+<StoredPreparedStatement>APP.<sysname> -> <Conglomerate>BAR.<sysname>
+StoredPreparedStatement
+<systemid>
+Conglomerate
 -----
 ========== SYSFILES ==========
 <systemid>

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dblook_test.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dblook_test.out?rev=406683&r1=406682&r2=406683&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dblook_test.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dblook_test.out
Mon May 15 10:10:11 2006
@@ -1474,6 +1474,12 @@
 <systemid>
 Conglomerate
 ----
+<systemid>
+<StoredPreparedStatement>APP.<sysname> -> <Conglomerate>BAR.<sysname>
+StoredPreparedStatement
+<systemid>
+Conglomerate
+----
 ========== SYSFILES ==========
 <systemid>
 FOO
@@ -3269,12 +3275,6 @@
 Conglomerate
 ----
 <systemid>
-<StoredPreparedStatement>APP.<sysname> -> <Conglomerate>BAR.<sysname>
-StoredPreparedStatement
-<systemid>
-Conglomerate
-----
-<systemid>
 <StoredPreparedStatement>APP.<sysname> -> <Conglomerate>BAR.IX3
 StoredPreparedStatement
 <systemid>
@@ -3417,6 +3417,18 @@
 View
 T6
 ColumnsInTable
+----
+<systemid>
+<StoredPreparedStatement>APP.<sysname> -> <Conglomerate>BAR.<sysname>
+StoredPreparedStatement
+<systemid>
+Conglomerate
+----
+<systemid>
+<StoredPreparedStatement>APP.<sysname> -> <Conglomerate>BAR.<sysname>
+StoredPreparedStatement
+<systemid>
+Conglomerate
 ----
 ========== SYSFILES ==========
 <systemid>

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall?rev=406683&r1=406682&r2=406683&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall
Mon May 15 10:10:11 2006
@@ -24,3 +24,4 @@
 jdbcapi/UpdateXXXTest.junit
 jdbcapi/SURQueryMixTest.junit
 jdbcapi/SURTest.junit
+jdbcapi/URCoveringIndexTest.junit

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/URCoveringIndexTest.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/URCoveringIndexTest.java?rev=406683&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/URCoveringIndexTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/URCoveringIndexTest.java
Mon May 15 10:10:11 2006
@@ -0,0 +1,153 @@
+/*
+ *
+ * Derby - Class URCoveringIndexTest
+ *
+ * Copyright 2006 The Apache Software Foundation or its 
+ * licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+package org.apache.derbyTesting.functionTests.tests.jdbcapi;
+import org.apache.derbyTesting.functionTests.util.TestUtil;
+import org.apache.derbyTesting.functionTests.util.BaseJDBCTestCase;
+import junit.framework.*;
+import java.sql.*;
+
+/**
+ * Tests updatable result sets when there is a index that includes all data for 
+ * the query (covering index).
+ *
+ * DERBY-1087
+ *
+ * @author Fernanda Pizzorno
+ */
+public class URCoveringIndexTest extends BaseJDBCTestCase {
+    
+    /** Creates a new instance of SURBaseTest */
+    public URCoveringIndexTest(String name) {
+        super(name);
+    }
+
+    /**
+     * Set up the connection to the database.
+     */
+    public void setUp() throws  Exception {       
+        con = getConnection();
+        con.setAutoCommit(false);
+
+        String createTableWithPK = "CREATE TABLE tableWithPK (" +
+                "c1 int primary key," +
+                "c2 int)";
+        String insertData = "INSERT INTO tableWithPK values (1, 1)";
+        Statement stmt = con.createStatement();
+        stmt.execute(createTableWithPK);
+        
+        stmt.execute(insertData);
+    }
+    
+    /**
+     * Rollback the transaction
+     */
+    public void tearDown() throws Exception {
+        println("TearDown");
+        try { 
+            con.rollback();
+            con.close();
+        } catch (SQLException e) {
+            printStackTrace(e);
+        }      
+    }
+    
+    private void testUpdateUpdatedTupleWithCoveringIndex(
+            boolean scroll,
+            boolean usePositionedUpdate) throws SQLException{
+        
+        SQLWarning w = null;
+        int resultsetType = scroll ? ResultSet.TYPE_SCROLL_INSENSITIVE :
+                ResultSet.TYPE_FORWARD_ONLY;
+        
+        if (!(con.getMetaData().supportsResultSetConcurrency(resultsetType,
+                ResultSet.CONCUR_UPDATABLE))) {
+            return;
+        }
+
+            
+        Statement updStmt = con.createStatement(resultsetType, 
+                ResultSet.CONCUR_UPDATABLE);
+        Statement roStmt = con.createStatement();
+        
+        ResultSet rs = updStmt.executeQuery("SELECT c1 FROM tableWithPK");
+        rs.next();
+        int orig_c1 = rs.getInt(1);
+        roStmt.executeUpdate("UPDATE tableWithPK SET c1 = " + 
+                (orig_c1 + 10) + "WHERE c1 = " + rs.getInt(1));
+        rs.clearWarnings();
+        if (usePositionedUpdate) {
+            roStmt.executeUpdate("UPDATE tableWithPK set c1 = " + 
+                    (orig_c1 + 20) + "WHERE CURRENT OF " + 
+                    rs.getCursorName());
+            w = roStmt.getWarnings();
+        } else {
+            rs.updateInt(1, (orig_c1 + 20));
+            rs.updateRow();
+            w = rs.getWarnings();
+        }
+        assertTrue("Update should not produce any warnings ", w == null);
+        rs.close();
+        
+        rs = roStmt.executeQuery("SELECT c1 FROM tableWithPK");
+        rs.next();
+        assertEquals("Expecting c1 to be " + orig_c1 + " + 20", 
+                rs.getInt(1), (orig_c1 + 20));
+        rs.close();
+        roStmt.close();
+        updStmt.close();
+
+    }
+
+    /**
+     * Updates a previously updated row with a covering index using positioned
+     * updates and scrollable result sets.
+     */
+    public void testUpdateUpdatedTupleScrollPostitioned()  throws SQLException{
+        testUpdateUpdatedTupleWithCoveringIndex(true, true);
+    }
+
+    /**
+     * Updates a previously updated row with a covering index using updateRow
+     * and scrollable result sets.
+     */
+    public void testUpdateUpdatedTupleScrollUpdateRow()  throws SQLException{
+        testUpdateUpdatedTupleWithCoveringIndex(true, false);
+    }
+
+    /**
+     * Updates a previously updated row with a covering index using positioned
+     * updates and forward only result sets.
+     */
+    public void testUpdateUpdatedTupleFOPositioned()  throws SQLException{
+        testUpdateUpdatedTupleWithCoveringIndex(false, true);
+    }
+
+    /**
+     * Updates a previously updated row with a covering index using updateRow
+     * and forward only result sets.
+     */
+    public void testUpdateUpdatedTupleFOUpdateRow()  throws SQLException{
+        testUpdateUpdatedTupleWithCoveringIndex(false, false);
+    }
+
+
+    protected Connection con = null; // Connection established in setUp()
+       
+}

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



Mime
View raw message