db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1579937 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql: compile/MatchingClauseNode.java compile/MergeNode.java execute/GenericConstantActionFactory.java execute/MatchingClauseConstantAction.java
Date Fri, 21 Mar 2014 13:07:45 GMT
Author: rhillegas
Date: Fri Mar 21 13:07:45 2014
New Revision: 1579937

URL: http://svn.apache.org/r1579937
Log:
DERBY-3155: Simplify processing of then rows for the DELETE actions of MERGE statements; commit
derby-3155-50-aa-revampDeleteThenRows.diff.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MatchingClauseNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MergeNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MatchingClauseConstantAction.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MatchingClauseNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MatchingClauseNode.java?rev=1579937&r1=1579936&r2=1579937&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MatchingClauseNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MatchingClauseNode.java
Fri Mar 21 13:07:45 2014
@@ -87,7 +87,6 @@ public class MatchingClauseNode extends 
 
     /** the columns in the temporary conglomerate which drives the INSERT/UPDATE/DELETE */
     private ResultColumnList        _thenColumns;
-    private int[]                           _deleteColumnOffsets;
 
     // Filled in at generate() time
     private int                             _clauseNumber;
@@ -775,33 +774,6 @@ public class MatchingClauseNode extends 
         }
     }
 
-    /**
-     * <p>
-     * Calculate the 1-based offsets which define the "then" rows which will be buffered
up
-     * for a DELETE action at run-time. The rows are constructed
-     * from the columns in the SELECT list of the driving left joins. This method
-     * calculates an array of offsets into the SELECT list. The columns at those
-     * offsets will form the row which is buffered up for the DELETE
-     * action.
-     * </p>
-     */
-    private void    bindDeleteThenColumns( ResultColumnList selectList )
-        throws StandardException
-    {
-        int     thenCount = _thenColumns.size();
-        int     selectCount = selectList.size();
-        
-        _deleteColumnOffsets = new int[ thenCount ];
-
-        for ( int bidx = 0; bidx < thenCount; bidx++ )
-        {
-            ResultColumn    thenRC = _thenColumns.elementAt( bidx );
-            ValueNode       thenExpression = thenRC.getExpression();
-
-            _deleteColumnOffsets[ bidx ] = getSelectListOffset( selectList, thenExpression
);
-        }
-    }
-
     ////////////////
     //
     // BIND INSERT
@@ -1096,100 +1068,6 @@ public class MatchingClauseNode extends 
     }
 
 
-    ////////////////////////
-    //
-    // BIND THE THEN ROW
-    //
-    ////////////////////////
-
-    /**
-     * <p>
-     * Bind the row which will go into the temporary table at run-time.
-     * </p>
-     */
-    void    bindThenColumns( ResultColumnList selectList )
-        throws StandardException
-    {
-        if ( isDeleteClause() ) { bindDeleteThenColumns( selectList ); }
-    }
-
-    /**
-     * <p>
-     * Find a column reference in the SELECT list of the driving left join
-     * and return its 1-based offset into that list.  Returns -1 if the column
-     * can't be found.
-     * </p>
-     */
-    private int getSelectListOffset( ResultColumnList selectList, ValueNode thenExpression
)
-        throws StandardException
-    {
-        int                 selectCount = selectList.size();
-
-        if ( thenExpression instanceof ColumnReference )
-        {
-            ColumnReference thenCR = (ColumnReference) thenExpression;
-            String              thenCRName = thenCR.getColumnName();
-            int                 thenCRMergeTableID = getMergeTableID( thenCR );
-
-            // loop through the SELECT list to find this column reference
-            for ( int sidx = 0; sidx < selectCount; sidx++ )
-            {
-                ResultColumn    selectRC = selectList.elementAt( sidx );
-                ValueNode       selectExpression = selectRC.getExpression();
-                ColumnReference selectCR = selectExpression instanceof ColumnReference ?
-                    (ColumnReference) selectExpression : null;
-
-                if ( selectCR != null )
-                {
-                    if (
-                        ( getMergeTableID( selectCR ) == thenCRMergeTableID) &&
-                        thenCRName.equals( selectCR.getColumnName() )
-                        )
-                    {
-                        return sidx + 1;
-                    }
-                }
-            }
-            
-            if (SanityManager.DEBUG)
-            {
-                SanityManager.THROWASSERT
-                    (
-                     "Can't find select list column corresponding to " + thenCR.getSQLColumnName()
+
-                     " with merge table id = " + thenCRMergeTableID
-                     );
-            }
-        }
-        else if ( thenExpression instanceof CurrentRowLocationNode )
-        {
-            //
-            // There is only one RowLocation in the SELECT list, the row location for the
-            // tuple from the target table. The RowLocation is always the last column in
-            // the SELECT list.
-            //
-            return selectCount;
-        }
-
-        return -1;
-    }
-
-    /** Find the MERGE table id of the indicated column */
-    private int getMergeTableID( ColumnReference cr )
-    {
-        int                 mergeTableID = cr.getMergeTableID();
-
-        if (SanityManager.DEBUG)
-        {
-            SanityManager.ASSERT
-                (
-                 ( (mergeTableID == ColumnReference.MERGE_SOURCE) || (mergeTableID == ColumnReference.MERGE_TARGET)
),
-                 "Column " + cr.getSQLColumnName() + " has illegal MERGE table id: " + mergeTableID
-                 );
-        }
-
-        return mergeTableID;
-    }
-
     /////////////////
     //
     // BIND MINIONS
@@ -1307,7 +1185,6 @@ public class MatchingClauseNode extends 
              refinementName,
              buildThenColumnSignature(),
              _rowMakingMethodName,
-             _deleteColumnOffsets,
              _resultSetFieldName,
              _actionMethodName,
              _dml.makeConstantAction()
@@ -1353,7 +1230,7 @@ public class MatchingClauseNode extends 
 
         adjustMatchingRefinement( selectList, generatedScan );
         
-        if ( isInsertClause() || isUpdateClause() ) { generateInsertUpdateRow( acb, selectList,
generatedScan, hojn ); }
+        generateInsertUpdateRow( acb, selectList, generatedScan, hojn );
         
         _actionMethodName = "mergeActionMethod_" + _clauseNumber;
         
@@ -1544,6 +1421,83 @@ public class MatchingClauseNode extends 
         }
     }
     
+    /**
+     * <p>
+     * Find a column reference in the SELECT list of the driving left join
+     * and return its 1-based offset into that list.  Returns -1 if the column
+     * can't be found.
+     * </p>
+     */
+    private int getSelectListOffset( ResultColumnList selectList, ValueNode thenExpression
)
+        throws StandardException
+    {
+        int                 selectCount = selectList.size();
+
+        if ( thenExpression instanceof ColumnReference )
+        {
+            ColumnReference thenCR = (ColumnReference) thenExpression;
+            String              thenCRName = thenCR.getColumnName();
+            int                 thenCRMergeTableID = getMergeTableID( thenCR );
+
+            // loop through the SELECT list to find this column reference
+            for ( int sidx = 0; sidx < selectCount; sidx++ )
+            {
+                ResultColumn    selectRC = selectList.elementAt( sidx );
+                ValueNode       selectExpression = selectRC.getExpression();
+                ColumnReference selectCR = selectExpression instanceof ColumnReference ?
+                    (ColumnReference) selectExpression : null;
+
+                if ( selectCR != null )
+                {
+                    if (
+                        ( getMergeTableID( selectCR ) == thenCRMergeTableID) &&
+                        thenCRName.equals( selectCR.getColumnName() )
+                        )
+                    {
+                        return sidx + 1;
+                    }
+                }
+            }
+            
+            if (SanityManager.DEBUG)
+            {
+                SanityManager.THROWASSERT
+                    (
+                     "Can't find select list column corresponding to " + thenCR.getSQLColumnName()
+
+                     " with merge table id = " + thenCRMergeTableID
+                     );
+            }
+        }
+        else if ( thenExpression instanceof CurrentRowLocationNode )
+        {
+            //
+            // There is only one RowLocation in the SELECT list, the row location for the
+            // tuple from the target table. The RowLocation is always the last column in
+            // the SELECT list.
+            //
+            return selectCount;
+        }
+
+        return -1;
+    }
+
+    /** Find the MERGE table id of the indicated column */
+    private int getMergeTableID( ColumnReference cr )
+    {
+        int                 mergeTableID = cr.getMergeTableID();
+
+        if (SanityManager.DEBUG)
+        {
+            SanityManager.ASSERT
+                (
+                 ( (mergeTableID == ColumnReference.MERGE_SOURCE) || (mergeTableID == ColumnReference.MERGE_TARGET)
),
+                 "Column " + cr.getSQLColumnName() + " has illegal MERGE table id: " + mergeTableID
+                 );
+        }
+
+        return mergeTableID;
+    }
+
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // Visitable BEHAVIOR

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MergeNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MergeNode.java?rev=1579937&r1=1579936&r2=1579937&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MergeNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MergeNode.java Fri Mar
21 13:07:45 2014
@@ -504,13 +504,6 @@ public final class MergeNode extends DML
             // save a copy so that we can remap column references when generating the temporary
rows
             _selectList = selectList.copyListAndObjects();
 
-            // calculate the offsets into the SELECT list which define the rows for
-            // the WHEN [ NOT ] MATCHED  actions
-            for ( MatchingClauseNode mcn : _matchingClauses )
-            {
-                mcn.bindThenColumns( _selectList );
-            }
-
             resultSet = new SelectNode
                 (
                  selectList,

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java?rev=1579937&r1=1579936&r2=1579937&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java
Fri Mar 21 13:07:45 2014
@@ -1155,7 +1155,6 @@ public class GenericConstantActionFactor
          String matchRefinementName,
          ResultDescription  thenColumnSignature,
          String rowMakingMethodName,
-         int[]  thenColumns,
          String resultSetFieldName,
          String actionMethodName,
          ConstantAction thenAction
@@ -1167,7 +1166,6 @@ public class GenericConstantActionFactor
              matchRefinementName,
              thenColumnSignature,
              rowMakingMethodName,
-             thenColumns,
              resultSetFieldName,
              actionMethodName,
              thenAction

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MatchingClauseConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MatchingClauseConstantAction.java?rev=1579937&r1=1579936&r2=1579937&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MatchingClauseConstantAction.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MatchingClauseConstantAction.java
Fri Mar 21 13:07:45 2014
@@ -74,7 +74,6 @@ public class MatchingClauseConstantActio
     private String  _matchRefinementName;
     private ResultDescription   _thenColumnSignature;
     private String  _rowMakingMethodName;
-    private int[]   _deleteColumnOffsets;
     private String  _resultSetFieldName;
     private String  _actionMethodName;
     private ConstantAction  _thenAction;
@@ -100,7 +99,7 @@ public class MatchingClauseConstantActio
      * @param   clauseType  WHEN_NOT_MATCHED_THEN_INSERT, WHEN_MATCHED_THEN_UPDATE, WHEN_MATCHED_THEN_DELETE
      * @param   matchRefinementName Name of the method which evaluates the boolean expression
in the WHEN clause.
      * @param   thenColumnSignature The shape of the row which goes into the temporary table.
-     * @param   thenColumns Column positions (1-based) from the driving left join which are
needed to execute the THEN clause.
+     * @param   rowMakingMethodName Name of the method which populates the "then" row with
expressions from the driving left join.
      * @param   resultSetFieldName  Name of the field which will be stuffed at runtime with
the temporary table of relevant rows.
      * @param   actionMethodName    Name of the method which invokes the INSERT/UPDATE/DELETE
action.
      * @param   thenAction  The ConstantAction describing the associated INSERT/UPDATE/DELETE
action.
@@ -111,7 +110,6 @@ public class MatchingClauseConstantActio
          String matchRefinementName,
          ResultDescription  thenColumnSignature,
          String rowMakingMethodName,
-         int[]  thenColumns,
          String resultSetFieldName,
          String actionMethodName,
          ConstantAction thenAction
@@ -121,7 +119,6 @@ public class MatchingClauseConstantActio
         _matchRefinementName = matchRefinementName;
         _thenColumnSignature = thenColumnSignature;
         _rowMakingMethodName = rowMakingMethodName;
-        _deleteColumnOffsets = ArrayUtil.copy( thenColumns );
         _resultSetFieldName = resultSetFieldName;
         _actionMethodName = actionMethodName;
         _thenAction = thenAction;
@@ -248,18 +245,7 @@ public class MatchingClauseConstantActio
     {
         if ( thenRows == null ) { thenRows = createThenRows( activation ); }
 
-        ExecRow thenRow;
-
-        switch( _clauseType )
-        {
-        case WHEN_MATCHED_THEN_DELETE:
-            thenRow = bufferThenRowForDelete( activation, selectRow );
-            break;
-
-        default:
-            thenRow = bufferThenRow( activation );
-            break;
-        }
+        ExecRow thenRow = bufferThenRow( activation );
 
         thenRows.insert( thenRow );
 
@@ -285,37 +271,12 @@ public class MatchingClauseConstantActio
 
     ///////////////////////////////////////////////////////////////////////////////////
     //
-    // MINIONS
+    // CONSTRUCT ROWS TO PUT INTO THE TEMPORARY TABLE
     //
     ///////////////////////////////////////////////////////////////////////////////////
 
     /**
      * <p>
-     * Construct and buffer a row for the DELETE
-     * action corresponding to this MATCHED clause. The buffered row
-     * is built from columns in the passed-in row. The passed-in row is the SELECT list
-     * of the MERGE statement's driving left join.
-     * </p>
-     */
-    private ExecRow    bufferThenRowForDelete
-        (
-         Activation activation,
-         ExecRow selectRow
-         )
-        throws StandardException
-    {
-        int             thenRowLength = _thenColumnSignature.getColumnCount();
-        ValueRow    thenRow = new ValueRow( thenRowLength );
-        for ( int i = 0; i < thenRowLength; i++ )
-        {
-            thenRow.setColumn( i + 1, selectRow.getColumn( _deleteColumnOffsets[ i ] ) );
-        }
-
-        return thenRow;
-    }
-
-    /**
-     * <p>
      * Construct and buffer a row for the INSERT/UPDATE/DELETE
      * action corresponding to this [ NOT ] MATCHED clause.
      * </p>
@@ -370,7 +331,6 @@ public class MatchingClauseConstantActio
         _matchRefinementName = (String) in.readObject();
         _thenColumnSignature = (ResultDescription) in.readObject();
         _rowMakingMethodName = (String) in.readObject();
-        _deleteColumnOffsets = ArrayUtil.readIntArray( in );
         _resultSetFieldName = (String) in.readObject(); 
         _actionMethodName = (String) in.readObject();
        _thenAction = (ConstantAction) in.readObject();
@@ -392,7 +352,6 @@ public class MatchingClauseConstantActio
         out.writeObject( _matchRefinementName );
         out.writeObject( _thenColumnSignature );
         out.writeObject( _rowMakingMethodName );
-        ArrayUtil.writeIntArray( out, _deleteColumnOffsets );
         out.writeObject( _resultSetFieldName );
         out.writeObject( _actionMethodName );
         out.writeObject( _thenAction );



Mime
View raw message