db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r638425 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/execute/ProjectRestrictResultSet.java testing/org/apache/derbyTesting/functionTests/master/joins.out testing/org/apache/derbyTesting/functionTests/tests/lang/joins.sql
Date Tue, 18 Mar 2008 15:59:04 GMT
Author: kmarsden
Date: Tue Mar 18 08:58:54 2008
New Revision: 638425

URL: http://svn.apache.org/viewvc?rev=638425&view=rev
Log:
DERBY-3538 NullPointerException during execution for query with LEFT OUTER JOIN whose inner
table selects all constants.

Contributed by Army Brown

Here are some of Army's comments ...
it *appears* that the problem is in the "doProjection()" method of ProjectRestrictResultSet.
During code generation we recognize that the SELECT has all constants and thus that its result
set is "reusable"; see ProjectRestrictNode.generateMinion(), esp. the call to:

  mb.push(resultColumns.reusableResult());

At execution, ProjectResrictResultSet sees that it can reuse the result set so it "caches"
the execution row in doProjection() and then just returns that on subsequent calls. However,
when returning the cached row, the method does *not* call "setCurrentRow()" with the cached
row. In some cases (esp. left outer join) that can mean that the "current execution row" corresponding
to the ProjectRestrictResultSet remains null when it should be set to the cached row. Thus
when it comes time to evaluate the ON predicate, which references the ProjectRestrictResultSet's
execution row, the predicate fails with an NPE because the "current execution row" is not
set for that PRRS. 


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ProjectRestrictResultSet.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/joins.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/joins.sql

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ProjectRestrictResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ProjectRestrictResultSet.java?rev=638425&r1=638424&r2=638425&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ProjectRestrictResultSet.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ProjectRestrictResultSet.java
Tue Mar 18 08:58:54 2008
@@ -477,6 +477,15 @@
 		// No need to use reflection if reusing the result
 		if (reuseResult && projRow != null)
 		{
+			/* Make sure we reset the current row based on the re-used
+			 * result.  Otherwise, if the "current row" for this result
+			 * set was nulled out in a previous call to getNextRow(),
+			 * which can happen if this node is the right-side of
+			 * a left outer join, the "current row" stored for this
+			 * result set in activation.row would remain null, which
+			 * would be wrong. DERBY-3538.
+			 */
+			setCurrentRow(projRow);
 			return projRow;
 		}
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/joins.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/joins.out?rev=638425&r1=638424&r2=638425&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/joins.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/joins.out
Tue Mar 18 08:58:54 2008
@@ -613,6 +613,23 @@
 DEST_ID    |SOURCE_ID_1|SOURCE_ID_2
 -----------------------------------
 1          |0          |0          
+ij> -- DERBY-3538 NullPointerException during execution for query with LEFT
+-- OUTER JOIN whose inner table selects all constants.
+create table t3538 (i int, j int);
+0 rows inserted/updated/deleted
+ij> insert into t3538 values (-1, -2), (-2, -4), (-3, -9);
+3 rows inserted/updated/deleted
+ij> select * from
+t3538 left outer join
+    (select -1 a, 1 b from t3538) x0 --DERBY-PROPERTIES joinStrategy=NESTEDLOOP
+   on x0.a = t3538.i;
+I          |J          |A          |B          
+-----------------------------------------------
+-1         |-2         |-1         |1          
+-1         |-2         |-1         |1          
+-1         |-2         |-1         |1          
+-2         |-4         |NULL       |NULL       
+-3         |-9         |NULL       |NULL       
 ij> -----------------------------------
 -- clean up
 ----------------------------------
@@ -641,5 +658,7 @@
 ij> drop table j1089_source;
 0 rows inserted/updated/deleted
 ij> drop table j1089_dest;
+0 rows inserted/updated/deleted
+ij> drop table t3538;
 0 rows inserted/updated/deleted
 ij> 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/joins.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/joins.sql?rev=638425&r1=638424&r2=638425&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/joins.sql
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/joins.sql
Tue Mar 18 08:58:54 2008
@@ -352,6 +352,17 @@
             join j1089_source as s2 on 1 = 1;
 select * from j1089_dest;
 
+
+-- DERBY-3538 NullPointerException during execution for query with LEFT
+-- OUTER JOIN whose inner table selects all constants.
+create table t3538 (i int, j int);
+insert into t3538 values (-1, -2), (-2, -4), (-3, -9);
+
+select * from
+t3538 left outer join
+    (select -1 a, 1 b from t3538) x0 --DERBY-PROPERTIES joinStrategy=NESTEDLOOP
+   on x0.a = t3538.i; 
+
 -----------------------------------
 -- clean up
 ----------------------------------
@@ -368,3 +379,4 @@
 drop table y;
 drop table j1089_source;
 drop table j1089_dest;
+drop table t3538;



Mime
View raw message