db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1579950 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile: MatchingClauseNode.java MergeNode.java
Date Fri, 21 Mar 2014 14:59:50 GMT
Author: rhillegas
Date: Fri Mar 21 14:59:49 2014
New Revision: 1579950

URL: http://svn.apache.org/r1579950
Log:
DERBY-3155: Improve comments for compilation of MERGE statements; commit derby-3155-51-aa-cleanup2.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

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=1579950&r1=1579949&r2=1579950&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 14:59:49 2014
@@ -72,23 +72,27 @@ public class MatchingClauseNode extends 
     //
     ///////////////////////////////////////////////////////////////////////////////////
 
-    // filled in by the constructor
+    //
+    // Filled in by the constructor.
+    //
     private ValueNode           _matchingRefinement;
     private ResultColumnList    _updateColumns;
     private ResultColumnList    _insertColumns;
     private ResultColumnList    _insertValues;
 
     //
-    // filled in at bind() time
+    // Filled in at bind() time.
     //
 
-    /** the INSERT/UPDATE/DELETE statement of this WHEN [ NOT ] MATCHED clause */
+    // the INSERT/UPDATE/DELETE statement of this WHEN [ NOT ] MATCHED clause
     private DMLModStatementNode _dml;
 
-    /** the columns in the temporary conglomerate which drives the INSERT/UPDATE/DELETE */
+    // the columns in the temporary conglomerate which drives the INSERT/UPDATE/DELETE
     private ResultColumnList        _thenColumns;
 
-    // Filled in at generate() time
+    //
+    // Filled in at generate() time.
+    //
     private int                             _clauseNumber;
     private String                          _actionMethodName;
     private String                          _resultSetFieldName;
@@ -347,7 +351,7 @@ public class MatchingClauseNode extends 
 
     /**
      * <p>
-     * Due to discrepancies on how names are resolved in SELECT and UPDATE,
+     * Due to discrepancies in how names are resolved by SELECT and UPDATE,
      * we have to force the left side of SET clauses to use the same table identifiers
      * as the right sides of the SET clauses.
      * </p>
@@ -385,9 +389,9 @@ public class MatchingClauseNode extends 
     /**
      * <p>
      * Get the bound SELECT node under the dummy UPDATE node.
-     * This may not be the source result set of the UPDATE node. That is because a ProjectRestrictResultSet
+     * This may not be the source result set of the UPDATE node. That is because a ProjectRestrictNode
      * may have been inserted on top of it by DEFAULT handling. This method
-     * exists to make the UPDATE actions of MERGE statement behave like ordinary
+     * exists to make the UPDATE actions of MERGE statements behave like ordinary
      * UPDATE statements in this situation. The behavior is actually wrong. See
      * DERBY-6414. Depending on how that bug is addressed, we may be able
      * to remove this method eventually.

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=1579950&r1=1579949&r2=1579950&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 14:59:49 2014
@@ -108,6 +108,20 @@ import org.apache.derby.shared.common.sa
  * </ul>
  *
  * <p>
+ * The driving left join's selectList then looks like this...
+ * </p>
+ *
+ * <pre>
+ * sc1, ..., scN, tc1, ..., tcM, targetTable.RowLocation
+ * </pre>
+ *
+ * <p>
+ * Where sc1...scN are the columns we need from the source table (in alphabetical
+ * order) and tc1...tcM are the columns we need from the target table (in alphabetical
+ * order).
+ * </p>
+ *
+ * <p>
  * The matchingRefinement expressions are bound and generated against the
  * FromList of the driving left join. Dummy DeleteNode, UpdateNode, and InsertNode
  * statements are independently constructed in order to bind and generate the DELETE/UPDATE/INSERT
@@ -124,6 +138,25 @@ import org.apache.derby.shared.common.sa
  * the DELETE/UPDATE/INSERT actions are run in order, each taking its corresponding
  * temporary table as its source ResultSet.
  * </p>
+ *
+ * <p>
+ * Name resolution was a particularly thorny problem. This is because name resolution
+ * behaves differently for SELECTs and UPDATEs. In particular, while processing UPDATEs,
+ * the compiler throws away name resolution information; this happens as a consequence
+ * of work done on DERBY-1043. In the end, I had to invent more name resolution machinery
+ * in order to compensate for the differences in the handling of SELECTs and UPDATEs.
+ * If we are to allow subqueries in matching refinement clauses and in the values expressions
+ * of INSERT and UPDATE actions, then we probably need to remove this special name
+ * resolution machinery. And that, in turn, probably means revisiting DERBY-1043.
+ * </p>
+ *
+ * <p>
+ * The special name resolution machinery involves marking source and target column references
+ * in order to make it clear which table they belong to. This is done in associateColumn().
The markers
+ * are consulted at code-generation time in order to resolve column references when we
+ * generate the expressions needed to populate the rows which go into the temporary tables.
+ * That resolution happens in MatchingClauseNode.getSelectListOffset().
+ * </p>
  */
 
 public final class MergeNode extends DMLModStatementNode
@@ -145,18 +178,24 @@ public final class MergeNode extends DML
     //
     ///////////////////////////////////////////////////////////////////////////////////
 
-    // constructor args
+    //
+    // Filled in by the constructor.
+    //
     private FromBaseTable   _targetTable;
     private FromTable   _sourceTable;
     private ValueNode   _searchCondition;
     private ArrayList<MatchingClauseNode>   _matchingClauses;
 
-    // filled in at bind() time
+    //
+    // Filled in at bind() time.
+    //
     private ResultColumnList    _selectList;
     private FromList                _leftJoinFromList;
     private HalfOuterJoinNode   _hojn;
 
-    // filled in at generate() time
+    //
+    // Filled in at generate() time.
+    //
     private ConstantAction      _constantAction;
     private CursorNode          _leftJoinCursor;
 
@@ -200,7 +239,13 @@ public final class MergeNode extends DML
     /** Get the target table for the MERGE statement */
     FromBaseTable   getTargetTable() { return _targetTable; }
 
-    /** Associate a column with the SOURCE or TARGET table */
+    /**
+     * <p>
+     * Associate a column with the SOURCE or TARGET table. This is
+     * part of the special name resolution machinery which smooths over
+     * the differences between name resolution for SELECTs and UPDATEs.
+     * </p>
+     */
     void    associateColumn( FromList fromList, ColumnReference cr, int mergeTableID )
         throws StandardException
     {
@@ -253,7 +298,12 @@ public final class MergeNode extends DML
         }
     }
 
-    /** Add the columns in the matchingRefinement clause to the evolving map */
+    /**
+     * <p>
+     * Add the columns in the matchingRefinement clause to the evolving map.
+     * This is called when we're building the SELECT list for the driving left join.
+     * </p>
+     */
     void    getColumnsInExpression
         ( HashMap<String,ColumnReference> map, ValueNode expression, int mergeTableID
)
         throws StandardException
@@ -265,7 +315,12 @@ public final class MergeNode extends DML
         getColumnsFromList( map, colRefs, mergeTableID );
     }
 
-    /** Add a list of columns to the the evolving map */
+    /**
+     * <p>
+     * Add a list of columns to the the evolving map.
+     * This is called when we're building the SELECT list for the driving left join.
+     * </p>
+     */
     void    getColumnsFromList
         ( HashMap<String,ColumnReference> map, ResultColumnList rcl, int mergeTableID
)
         throws StandardException
@@ -728,7 +783,7 @@ public final class MergeNode extends DML
     ///////////////////////////////
     //
     // BUILD THE SELECT LIST
-    // FOR THE DRIVING LEFT JOIN
+    // FOR THE DRIVING LEFT JOIN.
     //
     ///////////////////////////////
 



Mime
View raw message