[ 
https://issues.apache.org/jira/browse/DERBY-3321?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12560749#action_12560749
 ] 

Dyre Tjeldvoll commented on DERBY-3321:
---------------------------------------

HI Jørgen, 

I don't think this is the exact same problem as DERBY-3310 since that happens 
during execution, and your problem appears to happen during compilation 
(according to the call stack).
But it seems like both problems could be related to eager optimization of (NOT) 
EXISTS. In your case I think the problem is that in 
SelectNode.bindTargetExpressions:584 bindTargetListOnly is temporarily set to 
true. This will inhibit calling fromList.bindExpressions( fromListParam ); in 
SelectNode.bindExpression(). This is a problem since 
it is this call that will initialize FromSubquery.resultColumns (it is 
initially, null). Since the initialization is skipped you're all set for the 
NPE further down when  you reference resultColumns in 
FromSubquery.getMatchingColumn().

If I keep bindTargetListOnly false I get

select * from a
   where not exists
   (select bb from (select bb from b) p where a.bb=p.bb);
AA         |BB         
-----------------------
1          |2          
2          |2          

2 rows selected

bindTargetListOnly is used elsewhere as well, so this is probably not a viable 
fix. 

> NullPointerException for 'NOT EXISTS' with nested subquery
> ----------------------------------------------------------
>
>                 Key: DERBY-3321
>                 URL: https://issues.apache.org/jira/browse/DERBY-3321
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.3.2.1, 10.4.0.0
>            Reporter: Jørgen Løland
>            Priority: Minor
>         Attachments: derby.log
>
>
> Queries with 'not exists' followed by a nested subquery results in NPE:
> -----------8<--------------
> connect 'jdbc:derby:testdb;create=true';
> create table a (aa int, bb int);
> -- 0 rows inserted/updated/deleted
> create table b (bb int);
> -- 0 rows inserted/updated/deleted
> insert into a values (1, 1), (1, 2), (2, 2);
> -- 3 rows inserted/updated/deleted
> insert into b values (1);
> -- 1 row inserted/updated/deleted
> select * from a 
>    where not exists 
>    (select bb from b where a.bb=b.bb);
> -- AA         |BB
> -- ----------------------
> -- 1          |2
> -- 2          |2
> select bb from (select bb from b) p;
> -- BB
> -- -----------
> -- 1
> select * from a 
>    where not exists 
>    (select bb from (select bb from b) p where a.bb=p.bb);
> -- ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
> ------------>8----------------

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to