db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1426151 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/sql/execute/ impl/sql/compile/ impl/sql/execute/
Date Thu, 27 Dec 2012 10:02:11 GMT
Author: kahatlen
Date: Thu Dec 27 10:02:11 2012
New Revision: 1426151

URL: http://svn.apache.org/viewvc?rev=1426151&view=rev
Log:
DERBY-6003: Create row templates outside of the generated code

Make IndexRowToBaseRowResultSet use an ExecRowBuilder instead of a
generated method to produce row templates.

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/DistinctNode.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/FromVTI.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GroupByNode.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/compile/OrderByList.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/WindowResultSetNode.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?rev=1426151&r1=1426150&r2=1426151&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
Thu Dec 27 10:02:11 2012
@@ -1077,7 +1077,7 @@ public interface ResultSetFactory {
 								long conglomId,
 								int scoci,
 								NoPutResultSet source,
-								GeneratedMethod resultRowAllocator,
+								int resultRowAllocator,
 								int resultSetNumber,
 								String indexName,
 								int heapColRefItem,

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DistinctNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DistinctNode.java?rev=1426151&r1=1426150&r2=1426151&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DistinctNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/DistinctNode.java Thu
Dec 27 10:02:11 2012
@@ -313,7 +313,7 @@ public class DistinctNode extends Single
 		mb.push(true);
 		mb.push(inSortedOrder);
 		mb.push(orderItem);
-        mb.push(acb.addItem(resultColumns.buildRowTemplate(null)));
+        mb.push(acb.addItem(resultColumns.buildRowTemplate()));
 		mb.push(resultColumns.getTotalColumnSize());
 		mb.push(resultSetNumber);
 		mb.push(costEstimate.rowCount());

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=1426151&r1=1426150&r2=1426151&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 Thu
Dec 27 10:02:11 2012
@@ -3403,7 +3403,8 @@ public class FromBaseTable extends FromT
 
 		acb.pushThisAsActivation(mb);
 		mb.push(getResultSetNumber());
-        mb.push(acb.addItem(resultColumns.buildRowTemplate(referencedCols)));
+        mb.push(acb.addItem(
+            resultColumns.buildRowTemplate(referencedCols, false)));
 		mb.push(cd.getConglomerateNumber());
 		mb.push(tableDescriptor.getName());
 		//User may have supplied optimizer overrides in the sql
@@ -3496,7 +3497,8 @@ public class FromBaseTable extends FromT
      	acb.pushThisAsActivation(mb);
 		mb.push(conglomNumber);
 		mb.push(acb.addItem(scoci));
-        mb.push(acb.addItem(resultColumns.buildRowTemplate(referencedCols)));
+        mb.push(acb.addItem(
+            resultColumns.buildRowTemplate(referencedCols, false)));
 		mb.push(getResultSetNumber());
 		mb.push(hashKeyItem);
 		mb.push(tableDescriptor.getName());
@@ -3570,7 +3572,7 @@ public class FromBaseTable extends FromT
 	{
         // Put the result row template in the saved objects.
         int resultRowTemplate =
-                acb.addItem(resultColumns.buildRowTemplate(referencedCols));
+            acb.addItem(resultColumns.buildRowTemplate(referencedCols, false));
 
 		// pass in the referenced columns on the saved objects
 		// chain

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java?rev=1426151&r1=1426150&r2=1426151&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java Thu Dec
27 10:02:11 2012
@@ -1662,7 +1662,7 @@ public class FromVTI extends FromTable i
 		acb.pushThisAsActivation(mb); // arg 1
 
         // Get a row builder to allocate scan rows of the right shape and size.
-        mb.push(acb.addItem(resultColumns.buildRowTemplate(null))); // arg 2
+        mb.push(acb.addItem(resultColumns.buildRowTemplate())); // arg 2
 
 		// For a Version 2 VTI we never maintain the java.sql.PreparedStatement
 		// from compile time to execute time. This would rquire the PreparedStatement

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GroupByNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GroupByNode.java?rev=1426151&r1=1426150&r2=1426151&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GroupByNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GroupByNode.java Thu
Dec 27 10:02:11 2012
@@ -1088,7 +1088,7 @@ public class GroupByNode extends SingleC
 		mb.push(aggInfoItem);
 		mb.push(orderingItem);
 
-        mb.push(acb.addItem(resultColumns.buildRowTemplate(null)));
+        mb.push(acb.addItem(resultColumns.buildRowTemplate()));
 
 		mb.push(resultColumns.getTotalColumnSize());
 		mb.push(resultSetNumber);

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=1426151&r1=1426150&r2=1426151&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
Thu Dec 27 10:02:11 2012
@@ -237,7 +237,19 @@ public class IndexToBaseRowNode extends 
 		
 		mb.upCast(ClassName.NoPutResultSet);
 
-		resultColumns.generateHolder(acb, mb,  heapReferencedCols, indexReferencedCols);
+        // Skip over the index columns that are propagated from the source
+        // result set, if there are such columns. We won't pass the SQL NULL
+        // wrappers down to store for those columns anyways, so no need to
+        // generate them in the row template.
+        // NOTE: We have to check for the case where indexReferencedCols is
+        // not null, but no bits are set. This can happen when we need to get
+        // all of the columns from the heap due to a check constraint.
+        boolean skipPropagatedCols =
+                indexReferencedCols != null &&
+                indexReferencedCols.getNumBitsSet() != 0;
+        mb.push(acb.addItem(resultColumns
+                .buildRowTemplate(heapReferencedCols, skipPropagatedCols)));
+
 		mb.push(resultSetNumber);
 		mb.push(source.getBaseTableName());
 		mb.push(heapColRefItem);

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OrderByList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OrderByList.java?rev=1426151&r1=1426150&r2=1426151&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OrderByList.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OrderByList.java Thu
Dec 27 10:02:11 2012
@@ -398,7 +398,7 @@ public class OrderByList extends Ordered
 		mb.push(orderItem);
 
 		// row allocator
-        mb.push(acb.addItem(child.getResultColumns().buildRowTemplate(null)));
+        mb.push(acb.addItem(child.getResultColumns().buildRowTemplate()));
 
 		mb.push(child.getResultColumns().getTotalColumnSize());
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java?rev=1426151&r1=1426150&r2=1426151&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
Thu Dec 27 10:02:11 2012
@@ -1516,10 +1516,13 @@ public class ResultColumnList extends Qu
      *
      * @param referencedCols a bit map that tells which columns in the
      * source result set that are used, or {@code null} if all are used
+     * @param skipPropagatedCols whether to skip virtual columns whose
+     * source is the immediate child result set
      * @return an instance that produces rows of the same shape as this
      * result column list
      */
-    ExecRowBuilder buildRowTemplate(FormatableBitSet referencedCols)
+    ExecRowBuilder buildRowTemplate(FormatableBitSet referencedCols,
+                                    boolean skipPropagatedCols)
             throws StandardException
     {
         int columns = (referencedCols == null) ?
@@ -1527,17 +1530,28 @@ public class ResultColumnList extends Qu
 
         ExecRowBuilder builder = new ExecRowBuilder(columns, indexRow);
 
+        // Get the index of the first column to set in the row template.
         int colNum = (referencedCols == null) ? 0 : referencedCols.anySetBit();
 
         for (int i = 0; i < size(); i++) {
             ResultColumn rc = (ResultColumn) elementAt(i);
 
-            if (rc.getExpression() instanceof CurrentRowLocationNode) {
+            ValueNode sourceExpr = rc.getExpression();
+
+            if (sourceExpr instanceof CurrentRowLocationNode) {
                 builder.setColumn(colNum + 1, newRowLocationTemplate());
+            } else if (skipPropagatedCols &&
+                    sourceExpr instanceof VirtualColumnNode) {
+                // Skip over those columns whose source is the immediate
+                // child result set. (No need to generate a wrapper
+                // for a SQL NULL when we are smart enough not to pass
+                // that wrapper to the store.)
+                continue;
             } else {
                 builder.setColumn(colNum + 1, rc.getType());
             }
 
+            // Get the index of the next column to set in the row template.
             if (referencedCols == null) {
                 colNum++;
             } else {
@@ -1548,180 +1562,12 @@ public class ResultColumnList extends Qu
         return builder;
     }
 
-	/**
-		Generates a row with the size and shape of the ResultColumnList.
-
-		Some structures, like FromBaseTable and DistinctNode,
-		need to generate rowAllocator functions to get a row
-		the size and shape of their ResultColumnList.  
-
-		We return the method pointer, which is a field access
-		in the generated class.
-
-		@exception StandardException
-	 */
-	void generateHolder(ExpressionClassBuilder acb,
-								MethodBuilder mb,
-								FormatableBitSet referencedCols,
-								FormatableBitSet propagatedCols)
-								throws StandardException {
-
-		// what we return is a pointer to the method.
-   	    acb.pushMethodReference(mb, generateHolderMethod(acb, referencedCols, propagatedCols));
-	}
-
-	MethodBuilder generateHolderMethod(ExpressionClassBuilder acb,
-								FormatableBitSet referencedCols,
-								FormatableBitSet propagatedCols)
-							throws StandardException {
-		int			numCols;
-		String		rowAllocatorMethod;
-		String		rowAllocatorType;
-		int			highestColumnNumber = -1;
-
-		if (referencedCols != null)
-		{
-			// Find the number of the last column referenced in the table
-			for (int i = referencedCols.anySetBit();
-				 i != -1;
-				 i = referencedCols.anySetBit(i))
-			{
-				highestColumnNumber = i;
-			}
-		}
-		else
-		{
-			highestColumnNumber = size() - 1;
-		}
-
-		// Within the constructor:
-		//	 fieldX = getExecutionFactory().getValueRow(# cols);
-		// The body of the new method:
-   		// { 
-   		//   fieldX.setColumn(1, col(1).generateColumn(ps)));
-   		//   ... and so on for each column ...
-   		//   return fieldX;
-   		// }
-   		// static Method exprN = method pointer to exprN;
-
-   		// this sets up the method and the static field
-   		MethodBuilder exprFun = acb.newExprFun();
-
-		// Allocate the right type of row, depending on
-		// whether we're scanning an index or a heap.
-		if (indexRow)
-		{
-			rowAllocatorMethod = "getIndexableRow";
-			rowAllocatorType = ClassName.ExecIndexRow;
-		}
-		else
-		{
-			rowAllocatorMethod = "getValueRow";
-			rowAllocatorType = ClassName.ExecRow;
-		}
-		numCols = size();
-
-		/* Declare the field */
-		LocalField lf = acb.newFieldDeclaration(Modifier.PRIVATE, ClassName.ExecRow);
-		// Generate the code to create the row in the constructor
-		genCreateRow(acb, lf, rowAllocatorMethod, rowAllocatorType, highestColumnNumber + 1);
-
-		// now we fill in the body of the function
-
-		int colNum;
-
-		// If there is a referenced column map, the first column to fill
-		// in is the first one in the bit map - otherwise, it is
-		// column 0.
-		if (referencedCols != null)
-			colNum = referencedCols.anySetBit();
-		else
-			colNum = 0;
-
-		for (int index = 0; index < numCols; index++)
-		{
-			ResultColumn rc = ((ResultColumn) elementAt(index));
-
-			/* Special code generation for RID since expression is CurrentRowLocationNode.
-			 * Really need yet another node type that does its own code generation.
-			 */
-			if (rc.getExpression() instanceof CurrentRowLocationNode)
-			{
-                int savedItem = acb.addItem(newRowLocationTemplate());
-
-				// get the RowLocation template
-				exprFun.getField(lf); // instance for setColumn
-				exprFun.push(highestColumnNumber + 1); // first arg
-
-				exprFun.pushThis(); // instance for getRowLocationTemplate
-				exprFun.push(savedItem); // first arg
-				exprFun.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.Activation, "getRowLocationTemplate",
-									ClassName.RowLocation, 1);
-
-				exprFun.upCast(ClassName.DataValueDescriptor);
-				exprFun.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.Row, "setColumn",
-											"void", 2);
-				continue;
-			}
-
-			/* Skip over those columns whose source is the immediate
-			 * child result set.  (No need to generate a wrapper
-			 * for a SQL NULL when we are smart enough not to pass
-			 * that wrapper to the store.)
-			 * NOTE: Believe it or not, we have to check for the case
-			 * where referencedCols is not null, but no bits are set.
-			 * This can happen when we need to get all of the columns
-			 * from the heap due to a check constraint.
-			 */
-			if (propagatedCols != null &&
-				propagatedCols.getNumBitsSet() != 0)
-			{
-				/* We can skip this RC if it is simply propagating 
-				 * a column from the source result set.
-				 */
-				ValueNode sourceExpr = rc.getExpression();
-
-				if (sourceExpr instanceof VirtualColumnNode)
-				{
-					// There is a referenced columns bit set, so use
-					// it to figure out what the next column number is.
-					// colNum = referencedCols.anySetBit(colNum);
-					continue;
-				}
-			}
-
-			// generate the column space creation call
-       		// generate statements of the form
-    		// r.setColumn(columnNumber, columnShape);
-    		//
-    		// This assumes that there are no "holes" in the column positions,
-    		// and that column positions reflect the stored format/order
-			exprFun.getField(lf); // instance
-			exprFun.push(colNum + 1); // first arg
-			rc.generateHolder(acb, exprFun);
-
-			exprFun.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.Row, "setColumn", "void", 2);
-
-			// If there is a bit map of referenced columns, use it to
-			// figure out what the next column is, otherwise just go
-			// to the next column.
-			if (referencedCols != null)
-				colNum = referencedCols.anySetBit(colNum);
-			else
-				colNum++;
-    	}
-			
-		// generate:
-		// return fieldX;
-		// and add to the end of exprFun's body.
-		exprFun.getField(lf);
-		exprFun.methodReturn();
-
-		// we are done putting stuff in exprFun:
-		exprFun.complete();
-
-		return exprFun;
-	}
+    /**
+     * Shorthand for {@code buildRowTemplate(null, false)}.
+     */
+    ExecRowBuilder buildRowTemplate() throws StandardException {
+        return buildRowTemplate(null, false);
+    }
 
 	/**
 	 * Generate the code to create an empty row in the constructor.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/WindowResultSetNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/WindowResultSetNode.java?rev=1426151&r1=1426150&r2=1426151&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/WindowResultSetNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/WindowResultSetNode.java
Thu Dec 27 10:02:11 2012
@@ -410,7 +410,7 @@ public class WindowResultSetNode extends
         mb.upCast(ClassName.NoPutResultSet);
 
         /* row allocator */
-        mb.push(acb.addItem(resultColumns.buildRowTemplate(null))); // arg 3
+        mb.push(acb.addItem(resultColumns.buildRowTemplate())); // arg 3
 
         mb.push(resultSetNumber); //arg 4
 

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=1426151&r1=1426150&r2=1426151&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
Thu Dec 27 10:02:11 2012
@@ -804,7 +804,7 @@ public class GenericResultSetFactory imp
 								long conglomId,
 								int scociItem,
 								NoPutResultSet source,
-								GeneratedMethod resultRowAllocator,
+								int resultRowAllocator,
 								int resultSetNumber,
 								String indexName,
 								int heapColRefItem,

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=1426151&r1=1426150&r2=1426151&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
Thu Dec 27 10:02:11 2012
@@ -30,6 +30,7 @@ import org.apache.derby.iapi.services.sa
 import org.apache.derby.iapi.sql.Activation;
 import org.apache.derby.iapi.sql.execute.CursorResultSet;
 import org.apache.derby.iapi.sql.execute.ExecRow;
+import org.apache.derby.iapi.sql.execute.ExecRowBuilder;
 import org.apache.derby.iapi.sql.execute.NoPutResultSet;
 import org.apache.derby.iapi.store.access.ConglomerateController;
 import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo;
@@ -64,7 +65,6 @@ class IndexRowToBaseRowResultSet extends
 	// set in open() and not changed after that
 	private ConglomerateController	baseCC;
 	private boolean                 closeBaseCCHere;
-	private ExecRow					resultRow;
 	private boolean					forUpdate;
 	private DataValueDescriptor[]	rowArray;
 
@@ -87,7 +87,7 @@ class IndexRowToBaseRowResultSet extends
 					int scociItem,
 					Activation a,
 					NoPutResultSet source,
-					GeneratedMethod resultRowAllocator,
+					int resultRowAllocator,
 					int resultSetNumber,
 					String indexName,
 					int heapColRefItem,
@@ -132,7 +132,8 @@ class IndexRowToBaseRowResultSet extends
 			 saved[indexColMapItem]).getReferencedColumnPositions();
 
 		/* Get the result row template */
-		resultRow = (ExecRow) resultRowAllocator.invoke(activation);
+        ExecRow resultRow = ((ExecRowBuilder) saved[resultRowAllocator])
+                                .build(a.getExecutionFactory());
 
 		// Note that getCompactRow will assign its return value to the
 		// variable compactRow which can be accessed through



Mime
View raw message