db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r496645 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/sql/execute/ResultSetFactory.java impl/sql/compile/IndexToBaseRowNode.java impl/sql/execute/GenericResultSetFactory.java impl/sql/execute/IndexRowToBaseRowResultSet.java
Date Tue, 16 Jan 2007 09:57:22 GMT
Author: kahatlen
Date: Tue Jan 16 01:57:21 2007
New Revision: 496645

URL: http://svn.apache.org/viewvc?view=rev&rev=496645
Log:
DERBY-2226: Move column bitset computation to IndexToBaseRowNode

Patch contributed by Dyre Tjeldvoll.

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

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?view=diff&rev=496645&r1=496644&r2=496645
==============================================================================
--- 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 Jan 16 01:57:21 2007
@@ -1006,9 +1006,13 @@
 		@param heapColRefItem	A saved item for a bitImpl of columns that
 								are referenced in the underlying heap.  -1 if
 								no item.
-		@param indexColRefItem	A saved item for a bitImpl of columns that
-								are referenced in the underlying index.  -1 if
-								no item.
+		@param allColRefItem A saved item for a bitImpl of columns
+								that are referenced in the underlying
+								index and heap.  -1 if no item.
+		@param heapOnlyColRefItem A saved item for a bitImpl of
+								columns that are referenced in the
+								underlying heap only.  -1 if no item.
+
 		@param indexColMapItem	A saved item for a ReferencedColumnsDescriptorImpl
 								which tell  which columms are coming from the index.
 		@param restriction		The restriction, if any, to be applied to the base row
@@ -1029,7 +1033,8 @@
 								int resultSetNumber,
 								String indexName,
 								int heapColRefItem,
-								int indexColRefItem,
+								int allColRefItem,
+								int heapOnlyColRefItem,
 								int indexColMapItem,
 								GeneratedMethod restriction,
 								boolean forUpdate,

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?view=diff&rev=496645&r1=496644&r2=496645
==============================================================================
--- 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 Jan 16 01:57:21 2007
@@ -68,6 +68,8 @@
 	protected boolean	forUpdate;
 	private FormatableBitSet	heapReferencedCols;
 	private FormatableBitSet	indexReferencedCols;
+	private FormatableBitSet	allReferencedCols;
+	private FormatableBitSet	heapOnlyReferencedCols;
 
 	public void init(
 			Object	source,
@@ -89,6 +91,19 @@
 		this.forUpdate = ((Boolean) forUpdate).booleanValue();
 		this.heapReferencedCols = (FormatableBitSet) heapReferencedCols;
 		this.indexReferencedCols = (FormatableBitSet) indexReferencedCols;
+
+		if (this.indexReferencedCols == null) {
+			this.allReferencedCols = this.heapReferencedCols;
+			heapOnlyReferencedCols = this.heapReferencedCols;
+		}
+		else {
+			this.allReferencedCols =
+				new FormatableBitSet(this.heapReferencedCols);
+			this.allReferencedCols.or(this.indexReferencedCols);
+			heapOnlyReferencedCols =
+				new FormatableBitSet(allReferencedCols);
+			heapOnlyReferencedCols.xor(this.indexReferencedCols);
+		}
 	}
 
 	/** @see Optimizable#forUpdate */
@@ -187,14 +202,19 @@
 
 
 		int heapColRefItem = -1;
-		int indexColRefItem = -1;
 		if (heapReferencedCols != null)
 		{
 			heapColRefItem = acb.addItem(heapReferencedCols);
 		}
-		if (indexReferencedCols != null)
+		int allColRefItem = -1;
+		if (allReferencedCols != null)
 		{
-			indexColRefItem = acb.addItem(indexReferencedCols);
+			allColRefItem = acb.addItem(allReferencedCols);
+		}
+		int heapOnlyColRefItem = -1;
+		if (heapOnlyReferencedCols != null)
+		{
+			heapOnlyColRefItem = acb.addItem(heapOnlyReferencedCols);
 		}
 
 		/* Create the ReferencedColumnsDescriptorImpl which tells which columns
@@ -218,7 +238,10 @@
 		mb.push(resultSetNumber);
 		mb.push(source.getBaseTableName());
 		mb.push(heapColRefItem);
-		mb.push(indexColRefItem);
+
+		mb.push(allColRefItem);
+		mb.push(heapOnlyColRefItem);
+
 		mb.push(indexColMapItem);
 
 		// if there is no restriction, we just want to pass null.
@@ -263,7 +286,7 @@
 		mb.push(costEstimate.getEstimatedCost());
 
 		mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getIndexRowToBaseRowResultSet",
-						ClassName.NoPutResultSet, 13);
+						ClassName.NoPutResultSet, 14);
 
 		/* 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?view=diff&rev=496645&r1=496644&r2=496645
==============================================================================
--- 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 Jan 16 01:57:21 2007
@@ -738,7 +738,8 @@
 								int resultSetNumber,
 								String indexName,
 								int heapColRefItem,
-								int indexColRefItem,
+								int allColRefItem,
+								int heapOnlyColRefItem,
 								int indexColMapItem,
 								GeneratedMethod restriction,
 								boolean forUpdate,
@@ -755,7 +756,8 @@
 								resultSetNumber,
 								indexName,
 								heapColRefItem,
-								indexColRefItem,
+								allColRefItem,
+								heapOnlyColRefItem,
 								indexColMapItem,
 								restriction,
 								forUpdate,

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?view=diff&rev=496645&r1=496644&r2=496645
==============================================================================
--- 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 Jan 16 01:57:21 2007
@@ -36,6 +36,7 @@
 
 import org.apache.derby.iapi.sql.Activation;
 import org.apache.derby.iapi.sql.ResultSet;
+import org.apache.derby.impl.sql.GenericPreparedStatement;
 
 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
 import org.apache.derby.iapi.sql.conn.StatementContext;
@@ -75,7 +76,6 @@
 	private GeneratedMethod restriction;
     private long baseConglomId;
 	public FormatableBitSet accessedHeapCols;
-	private FormatableBitSet accessedIndexCols;
 	//caching accessed columns (heap+index) beetle 3865
 	private FormatableBitSet accessedAllCols;
 	public String indexName;
@@ -87,7 +87,6 @@
 	private ConglomerateController	baseCC;
 	private boolean                 closeBaseCCHere;
 	private ExecRow					resultRow;
-	private ExecRow					compactRow;
 	private boolean					forUpdate;
 	private DataValueDescriptor[]	rowArray;
 
@@ -117,7 +116,8 @@
 					int resultSetNumber,
 					String indexName,
 					int heapColRefItem,
-					int indexColRefItem,
+					int allColRefItem,
+					int heapOnlyColRefItem,
 					int indexColMapItem,
 					GeneratedMethod restriction,
 					boolean forUpdate,
@@ -126,8 +126,11 @@
 		throws StandardException
 	{
 		super(a, resultSetNumber, optimizerEstimatedRowCount, optimizerEstimatedCost);
-        scoci = (StaticCompiledOpenConglomInfo)(activation.getPreparedStatement().
-						getSavedObject(scociItem));
+		final GenericPreparedStatement gp =
+			(GenericPreparedStatement)a.getPreparedStatement();
+		final Object[] saved = gp.getSavedObjects();
+
+		scoci = (StaticCompiledOpenConglomInfo)saved[scociItem];
 		TransactionController tc = activation.getTransactionController();
 		dcoci = tc.getDynamicCompiledConglomInfo(conglomId);
         this.source = source;
@@ -142,76 +145,58 @@
 
 		// retrieve the valid column list from
 		// the saved objects, if it exists
-		this.accessedHeapCols = null;
-		if (heapColRefItem != -1)
-		{
-			this.accessedHeapCols = (FormatableBitSet)(a.getPreparedStatement().
-						getSavedObject(heapColRefItem));
-		}
-		if (indexColRefItem != -1)
-		{
-			this.accessedIndexCols = (FormatableBitSet)(a.getPreparedStatement().
-						getSavedObject(indexColRefItem));
+		if (heapColRefItem != -1) {
+			this.accessedHeapCols = (FormatableBitSet)saved[heapColRefItem];
 		}
-		if (accessedIndexCols == null)
-			accessedAllCols = accessedHeapCols;
-		else
-		{
-			accessedAllCols = new FormatableBitSet(accessedHeapCols);
-			accessedAllCols.or(accessedIndexCols);
+		if (allColRefItem != -1) {
+			this.accessedAllCols = (FormatableBitSet)saved[allColRefItem];
 		}
-			
+
 		// retrieve the array of columns coming from the index
-		indexCols = ((ReferencedColumnsDescriptorImpl) (a.getPreparedStatement().
-						getSavedObject(indexColMapItem))).getReferencedColumnPositions();
+		indexCols = 
+			((ReferencedColumnsDescriptorImpl)
+			 saved[indexColMapItem]).getReferencedColumnPositions();
 
 		/* Get the result row template */
 		resultRow = (ExecRow) resultRowAllocator.invoke(activation);
 
-		compactRow =
-			getCompactRow(resultRow,
-							accessedHeapCols,
-							accessedIndexCols,
-							false);
+		// Note that getCompactRow will assign its return value to the
+		// variable compactRow which can be accessed through
+		// inheritance. Hence we need not collect the return value
+		// of the method.
+		getCompactRow(resultRow, accessedAllCols, 
+					  (FormatableBitSet)null, false);
 
 		/* If there's no partial row bit map, then we want the entire
 		 * row, otherwise we need to diddle with the row array so that
 		 * we only get the columns coming from the heap on the fetch.
 		 */
-		if (accessedHeapCols == null)
-		{
+		if (accessedHeapCols == null) {
 			rowArray = resultRow.getRowArray();
 		}
-		else
-		{
+		else {
 			// Figure out how many columns are coming from the heap
-			int arraySize = accessedHeapCols.getNumBitsSet();
-			int accessedHeapColsSize = accessedHeapCols.size();
-
-			rowArray = new DataValueDescriptor[accessedHeapColsSize];
 
-			// Now, fill in rowArray with the desired columns
-			int partialIndex = 0;
-			int numFromIndex = 0;
-			for (int index = 0; index < accessedHeapColsSize; index++)
-			{
-				if (accessedIndexCols != null && accessedIndexCols.get(index))
-				{
-					numFromIndex++;
-					continue;
-				}
-				if (accessedHeapCols.get(index))
-				{
-					rowArray[index] =
-						resultRow.getRowArray()[index];
-					partialIndex++;
+			final DataValueDescriptor[] resultRowArray =
+				resultRow.getRowArray();
+			final FormatableBitSet heapOnly =
+				(FormatableBitSet)saved[heapOnlyColRefItem];
+			final int heapOnlyLen = heapOnly.getLength();
+
+			// Need a separate DataValueDescriptor array in this case
+			rowArray =
+ 				new DataValueDescriptor[heapOnlyLen];
+			final int minLen = Math.min(resultRowArray.length, heapOnlyLen);
+
+			// Make a copy of the relevant part of rowArray
+			for (int i = 0; i < minLen; ++i) {
+				if (resultRowArray[i] != null && heapOnly.isSet(i)) {
+					rowArray[i] = resultRowArray[i];
 				}
 			}
 		}
-
 		constructorTime += getElapsedMillis(beginTime);
-
-    }
+	}
 
 	//
 	// ResultSet interface (leftover from NoPutResultSet)



Mime
View raw message