Index: java/engine/org/apache/derby/impl/sql/execute/ProjectRestrictResultSet.java =================================================================== --- java/engine/org/apache/derby/impl/sql/execute/ProjectRestrictResultSet.java (revision 635756) +++ java/engine/org/apache/derby/impl/sql/execute/ProjectRestrictResultSet.java (working copy) @@ -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; } Index: java/testing/org/apache/derbyTesting/functionTests/tests/lang/joins.sql =================================================================== --- java/testing/org/apache/derbyTesting/functionTests/tests/lang/joins.sql (revision 635756) +++ java/testing/org/apache/derbyTesting/functionTests/tests/lang/joins.sql (working copy) @@ -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; Index: java/testing/org/apache/derbyTesting/functionTests/master/joins.out =================================================================== --- java/testing/org/apache/derbyTesting/functionTests/master/joins.out (revision 635756) +++ java/testing/org/apache/derbyTesting/functionTests/master/joins.out (working copy) @@ -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 ---------------------------------- @@ -642,4 +659,6 @@ 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> \ No newline at end of file