db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r988204 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Mon, 23 Aug 2010 16:59:59 GMT
Author: dag
Date: Mon Aug 23 16:59:58 2010
New Revision: 988204

URL: http://svn.apache.org/viewvc?rev=988204&view=rev
Log:
DERBY-4695 Internal assignment of tablenumer, columnnumber looks wrong in query tree, although
no ill effects are seen

Patch derby-4695-fixcolumnno-1b, which moves the assignment of
ColumnReference#columnnumber from ColumnReference to the underlying
FromTable, i.e. the same place as where the table number is
assigned. This assures that the two are in synch, and the columnNumber
assignment is no longer thwarted by the (re)assignment of the
ColumnReference#source for "JoinNode"s to one of the result columns of
the Join itself (needed for code generation: the source for the
ColumnReference need to be to the correct ResultSet at generate time,
cf the comment in JoinNode#getMatchingColumn).


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnReference.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CurrentOfNode.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/FromList.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromSubquery.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/JoinTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnReference.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnReference.java?rev=988204&r1=988203&r2=988204&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnReference.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnReference.java
Mon Aug 23 16:59:58 2010
@@ -58,12 +58,30 @@ public class ColumnReference extends Val
 	** when the column is bound as it is only used in binding.
 	*/
 	TableName	tableName;
-	/* The table this column reference is bound to */
-	private int			tableNumber;	
-	/* The column number in the underlying base table */
-	private int			columnNumber;	
-	/* This is where the value for this column reference will be coming from */
-	private ResultColumn	source;
+
+    /**
+     * The FromTable this column reference is bound to.
+     */
+    private int tableNumber;
+
+    /**
+     * The column number in the underlying FromTable. But note {@code source}.
+     * @see #source
+     */
+    private int columnNumber;
+
+    /**
+     * This is where the value for this column reference will be coming from.
+     * Note that for join nodes, {@code tableNumber}/{@code columnNumber} will
+     * point to the column in the left or right join participant {@code
+     * FromTable}, whereas {@code source} will be bound to the RC in the result
+     * column list of the join node. See also the comment at the end of
+     * JoinNode#getMatchingColumn.
+     * @see JoinNode#getMatchingColumn
+     * @see #columnNumber
+     * @see #tableNumber
+     */
+    private ResultColumn source;
 
 	/* For unRemapping */
 	ResultColumn	origSource;
@@ -387,11 +405,6 @@ public class ColumnReference extends Val
 			throw StandardException.newException(SQLState.LANG_COLUMN_NOT_FOUND, getSQLColumnName());
 		}
 
-		/* Set the columnNumber from the base table.
- 		 * Useful for optimizer and generation.
-		 */
-		columnNumber = matchingRC.getColumnPosition();
-
 		return this;
 	}
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CurrentOfNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CurrentOfNode.java?rev=988204&r1=988203&r2=988204&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CurrentOfNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CurrentOfNode.java Mon
Aug 23 16:59:58 2010
@@ -349,6 +349,8 @@ public final class CurrentOfNode extends
 				// suggests that we should always set the table number
 				// if we've found the ResultColumn.  So we do that here.
 				columnReference.setTableNumber( tableNumber );
+                columnReference.setColumnNumber(
+                   resultColumn.getColumnPosition());
 
 				// If there is a result column, are we really updating it?
 				// If so, verify that the column is updatable as well

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=988204&r1=988203&r2=988204&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
Aug 23 16:59:58 2010
@@ -2562,6 +2562,9 @@ public class FromBaseTable extends FromT
 			if (resultColumn != null)
 			{
 				columnReference.setTableNumber(tableNumber);
+                columnReference.setColumnNumber(
+                    resultColumn.getColumnPosition());
+
 				if (tableDescriptor != null)
 				{
 					FormatableBitSet referencedColumnMap = tableDescriptor.getReferencedColumnMap();

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromList.java?rev=988204&r1=988203&r2=988204&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromList.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromList.java Mon Aug
23 16:59:58 2010
@@ -591,12 +591,12 @@ public class FromList extends QueryTreeN
 			{
 				if (! columnNameMatch)
 				{
-					/* TableNumbers are set in the CR in the underlying
-					 * FromTable.  This ensures that they get the table
-					 * number from the underlying table, not the join node.
-					 * This is important for beging able to push predicates 
-					 * down through join nodes.
-					 */
+                    /* TableNumbers and column numbers are set in the CR in the
+                     * underlying FromTable.  This ensures that they get the
+                     * table number/column number from the underlying table,
+                     * not the join node.  This is important for beging able to
+                     * push predicates down through join nodes.
+                     */
 					matchingRC = resultColumn;
 					columnReference.setSource(resultColumn);
 					/* Set the nesting level at which the CR appears and the nesting level

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromSubquery.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromSubquery.java?rev=988204&r1=988203&r2=988204&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromSubquery.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromSubquery.java Mon
Aug 23 16:59:58 2010
@@ -333,6 +333,7 @@ public class FromSubquery extends FromTa
 		if (resultColumn != null)
 		{
 			columnReference.setTableNumber(tableNumber);
+            columnReference.setColumnNumber(resultColumn.getColumnPosition());
 		}
 
 		return resultColumn;

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=988204&r1=988203&r2=988204&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 Mon Aug
23 16:59:58 2010
@@ -1055,6 +1055,8 @@ public class FromVTI extends FromTable i
 			if (resultColumn != null)
 			{
 				columnReference.setTableNumber(tableNumber);
+                columnReference.setColumnNumber(
+                    resultColumn.getColumnPosition());
 			}
 		}
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/JoinTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/JoinTest.java?rev=988204&r1=988203&r2=988204&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/JoinTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/JoinTest.java
Mon Aug 23 16:59:58 2010
@@ -1999,4 +1999,56 @@ public class JoinTest extends BaseJDBCTe
         rollback();
     }
 
+    /**
+     * This test works prior to applying the patch for DERBY-4695, but the
+     * corrected (internal, intermediate) behavior can be observed by applying
+     * the patch {@code trace-remapping.diff} attached to this issue in JIRA and
+     * copmparing the results before and after the rest of the patch is
+     * applied.
+     * 
+     */
+    public void testDerby_4695() throws SQLException {
+        setAutoCommit(false);
+        Statement s = createStatement();
+
+        // Test case reused from DERBY-2526
+
+        s.executeUpdate("create table b2 (c1 int, c2 int, c3 char(1), " +
+                        "                 c4 int, c5 int, c6 int)");
+        s.executeUpdate("create table b4 (c7 int, c4 int, c6 int)");
+        s.executeUpdate("create table b3 (c1 int, c9 int, c5 int, c6 int)");
+        s.executeUpdate("create table b (c1 int, c2 int, c3 char(1), " +
+                        "                c4 int, c5 int, c6 int)");
+        s.executeUpdate("create view bvw (c5, c1 ,c2 ,c3 ,c4) as " +
+                        "select c5, c1 ,c2 ,c3 ,c4 from b2 union " +
+                        "select c5, c1 ,c2 ,c3 ,c4 from b");
+        s.executeUpdate("insert into b4 (c7,c4,c6) values (4, 42, 31)");
+        s.executeUpdate("insert into b2 (c5,c1,c3,c4,c6) " +
+                        "    values (3,4, 'F',43,23)");
+        s.executeUpdate("insert into b3 (c5,c1,c9,c6) values (2,3,19,28)");
+        s.executeUpdate("insert into b values (4, 10, 'x', 10, 10, 10)");
+
+        ResultSet rs = s.executeQuery(
+            "select b3.* from b3 join bvw on (b3.c1 = bvw.c5) " +
+            "                    join b4 on (bvw.c1 = b4.c7) " +
+            "    where b4.c4 = 42");
+
+        JDBC.assertFullResultSet(
+            rs,
+            new String[][]{{"3", "19", "2", "28"}});
+
+        rs = s.executeQuery(
+            "select b3.*, bvw.c1 from b3 inner join bvw on (b3.c1 = bvw.c5) " +
+            "                            inner join b4  on (bvw.c1 = b4.c7) " +
+            "                            inner join b  on  (bvw.c1 = b.c1)" +
+            "                            inner join b bcorr on " +
+            "                                               bvw.c1 = bcorr.c1" +
+            "    where b4.c4 = 42");
+
+        JDBC.assertFullResultSet(
+            rs,
+            new String[][]{{"3", "19", "2", "28", "4"}});
+
+        rollback();
+    }
 }



Mime
View raw message