db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r824694 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/PredicateList.java testing/org/apache/derbyTesting/functionTests/master/union.out testing/org/apache/derbyTesting/functionTests/tests/lang/union.sql
Date Tue, 13 Oct 2009 11:14:30 GMT
Author: kahatlen
Date: Tue Oct 13 11:14:29 2009
New Revision: 824694

URL: http://svn.apache.org/viewvc?rev=824694&view=rev
Log:
DERBY-4391: NullPointerException when comparing indexed column with result from a set operation

Prevent PredicateList.markReferencedColumns() from walking down to the
source of a ColumnReference if it is null.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/PredicateList.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/union.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/union.sql

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/PredicateList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/PredicateList.java?rev=824694&r1=824693&r2=824694&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/PredicateList.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/PredicateList.java Tue
Oct 13 11:14:29 2009
@@ -1638,7 +1638,16 @@
 		for (Enumeration e = colRefs.elements(); e.hasMoreElements(); )
 		{
 			ColumnReference ref = (ColumnReference)e.nextElement();
-			ref.getSource().markAllRCsInChainReferenced();
+			ResultColumn source = ref.getSource();
+
+            // DERBY-4391: Don't try to call markAllRCsInChainReferenced() if
+            // source is null. This can happen if the ColumnReference is
+            // pointing to a column that is not from a base table. For instance
+            // if we have a VALUES clause like (VALUES (1, 2), (3, 4)) V1(I, J)
+            // then a column reference to V1.I won't have a source.
+			if (source != null) {
+				source.markAllRCsInChainReferenced();
+			}
 		}
 	}
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/union.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/union.out?rev=824694&r1=824693&r2=824694&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/union.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/union.out
Tue Oct 13 11:14:29 2009
@@ -1217,4 +1217,38 @@
 0 rows inserted/updated/deleted
 ij> drop table t2;
 0 rows inserted/updated/deleted
+ij> -- Regression test for DERBY-4391. These UNION queries used to throw a
+-- NullPointerException during compilation. Now all of them should compile
+-- successfully, but some of them fail during execution if their subqueries
+-- return more than one row.
+create table d4391(a int not null primary key, b int);
+0 rows inserted/updated/deleted
+ij> insert into d4391 values (0, 4), (1, 3), (2, 2), (3, 1), (4, 0);
+5 rows inserted/updated/deleted
+ij> select * from d4391 where a < (values 2 union values 2);
+A          |B          
+-----------------------
+0          |4          
+1          |3          
+ij> select * from d4391 where a < (select 4 from d4391 union select b from d4391);
+ERROR 21000: Scalar subquery is only allowed to return a single row.
+ij> select * from d4391 where a < (select a+b from d4391 union select 4 from d4391);
+A          |B          
+-----------------------
+0          |4          
+1          |3          
+2          |2          
+3          |1          
+ij> select * from d4391 where a < (select a+b from d4391 union select a from d4391);
+ERROR 21000: Scalar subquery is only allowed to return a single row.
+ij> select * from d4391 where a < (select sum(a) from d4391 union select sum(b) from
d4391);
+A          |B          
+-----------------------
+0          |4          
+1          |3          
+2          |2          
+3          |1          
+4          |0          
+ij> drop table d4391;
+0 rows inserted/updated/deleted
 ij> 
\ No newline at end of file

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/union.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/union.sql?rev=824694&r1=824693&r2=824694&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/union.sql
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/union.sql
Tue Oct 13 11:14:29 2009
@@ -489,3 +489,16 @@
 -- cleanup.
 drop table t1;
 drop table t2;
+
+-- Regression test for DERBY-4391. These UNION queries used to throw a
+-- NullPointerException during compilation. Now all of them should compile
+-- successfully, but some of them fail during execution if their subqueries
+-- return more than one row.
+create table d4391(a int not null primary key, b int);
+insert into d4391 values (0, 4), (1, 3), (2, 2), (3, 1), (4, 0);
+select * from d4391 where a < (values 2 union values 2);
+select * from d4391 where a < (select 4 from d4391 union select b from d4391);
+select * from d4391 where a < (select a+b from d4391 union select 4 from d4391);
+select * from d4391 where a < (select a+b from d4391 union select a from d4391);
+select * from d4391 where a < (select sum(a) from d4391 union select sum(b) from d4391);
+drop table d4391;



Mime
View raw message