db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r911315 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/SubqueryNode.java testing/org/apache/derbyTesting/functionTests/master/subquery.out testing/org/apache/derbyTesting/functionTests/tests/lang/subquery.sql
Date Thu, 18 Feb 2010 10:30:26 GMT
Author: kahatlen
Date: Thu Feb 18 10:30:26 2010
New Revision: 911315

URL: http://svn.apache.org/viewvc?rev=911315&view=rev
Log:
DERBY-4549: NPE in JBitSet

SubqueryNode did not preprocess its left operand, so some fields were
not initialized when the optimizer looked at it. This patch makes
SubqueryNode.preprocess() call preprocess() recursively on the left
operand.

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

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SubqueryNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SubqueryNode.java?rev=911315&r1=911314&r2=911315&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SubqueryNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SubqueryNode.java Thu
Feb 18 10:30:26 2010
@@ -625,6 +625,12 @@
 
 		resultSet = resultSet.preprocess(numTables, null, (FromList) null);
 
+        if (leftOperand != null)
+        {
+            leftOperand = leftOperand.preprocess(numTables,
+                    outerFromList, outerSubqueryList, outerPredicateList);
+        }
+
 		// Eliminate any unnecessary DISTINCTs
 		if (resultSet instanceof SelectNode)
 		{

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/subquery.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/subquery.out?rev=911315&r1=911314&r2=911315&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/subquery.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/subquery.out
Thu Feb 18 10:30:26 2010
@@ -1748,4 +1748,45 @@
 ERROR 42X07: Null is only allowed in a VALUES clause within an INSERT statement.
 ij> drop table t1;
 0 rows inserted/updated/deleted
+ij> -- DERBY-4549: NPE in JBitSet
+CREATE TABLE ABC (ID INT);
+0 rows inserted/updated/deleted
+ij> CREATE TABLE DEF (ID INT);
+0 rows inserted/updated/deleted
+ij> -- compilation of the statement used to fail with NPE
+PREPARE PS AS 'SELECT * FROM ABC t1
+WHERE (SELECT DISTINCT t2.ID FROM DEF t2) IN (SELECT t3.ID FROM DEF t3)';
+ij> -- empty tables, empty result
+EXECUTE PS;
+ID         
+-----------
+ij> -- now, test with data in the tables
+INSERT INTO ABC VALUES 1, 2;
+2 rows inserted/updated/deleted
+ij> EXECUTE PS;
+ID         
+-----------
+ij> INSERT INTO DEF VALUES 2;
+1 row inserted/updated/deleted
+ij> EXECUTE PS;
+ID         
+-----------
+1          
+2          
+ij> INSERT INTO DEF VALUES 2;
+1 row inserted/updated/deleted
+ij> EXECUTE PS;
+ID         
+-----------
+1          
+2          
+ij> INSERT INTO DEF VALUES 3;
+1 row inserted/updated/deleted
+ij> -- will fail because left operand of IN is no longer scalar
+EXECUTE PS;
+ERROR 21000: Scalar subquery is only allowed to return a single row.
+ij> DROP TABLE ABC;
+0 rows inserted/updated/deleted
+ij> DROP TABLE DEF;
+0 rows inserted/updated/deleted
 ij> 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/subquery.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/subquery.sql?rev=911315&r1=911314&r2=911315&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/subquery.sql
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/subquery.sql
Thu Feb 18 10:30:26 2010
@@ -583,3 +583,24 @@
 select * from t1 where exists (select 1 from (values null) as t2);
 select * from t1 where exists (select * from (values null) as t2);
 drop table t1;
+
+-- DERBY-4549: NPE in JBitSet
+CREATE TABLE ABC (ID INT);
+CREATE TABLE DEF (ID INT);
+-- compilation of the statement used to fail with NPE
+PREPARE PS AS 'SELECT * FROM ABC t1
+WHERE (SELECT DISTINCT t2.ID FROM DEF t2) IN (SELECT t3.ID FROM DEF t3)';
+-- empty tables, empty result
+EXECUTE PS;
+-- now, test with data in the tables
+INSERT INTO ABC VALUES 1, 2;
+EXECUTE PS;
+INSERT INTO DEF VALUES 2;
+EXECUTE PS;
+INSERT INTO DEF VALUES 2;
+EXECUTE PS;
+INSERT INTO DEF VALUES 3;
+-- will fail because left operand of IN is no longer scalar
+EXECUTE PS;
+DROP TABLE ABC;
+DROP TABLE DEF;



Mime
View raw message