[
https://issues.apache.org/jira/browse/DERBY-6346?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Rick Hillegas updated DERBY-6346:
---------------------------------
Attachment: derby-6346-02-aa-generateNullForLeftJoins.diff
Attaching derby-6346-02-aa-generateNullForLeftJoins.diff. This patches the code
generator so that it doesn't skip creating NULL values for generated columns on
the inner side of a LEFT JOIN. I am running tests now.
The NPE occurs because the empty right row of the LEFT JOIN contains a Java
null rather than a NULL DataValueDescriptor. This happens because of a bug in
the code-generation of ResultColumnLists when generating code for generated
columns. That, in turn, happens because the code-generation of generated
columns happens elsewhere for INSERT and UPDATE statements. The fix is to try
to distinguish a ResultColumnList for a SELECT from a ResultColumnList for an
INSERT/UPDATE. If the ResultColumnList is for a SELECT, then we code-generate a
NULL DataValueDescriptor for the generated column. Otherwise, we don't.
The test for whether the ResultColumnList represents a SELECT is to check
whether the ResultColumn's source expression is a VirtualColumnNode. This is
tricky and brittle. This check can be improved if someone has a better
suggestion for how to distinguish the two kinds of lists.
Touches the following files:
---------
M java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
The fix.
---------
M
java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
Adds a regression test case for this bug.
> NPE in left join whose inner table has a generated column
> ---------------------------------------------------------
>
> Key: DERBY-6346
> URL: https://issues.apache.org/jira/browse/DERBY-6346
> Project: Derby
> Issue Type: Bug
> Components: SQL
> Affects Versions: 10.5.1.1
> Reporter: Rick Hillegas
> Attachments: derby-6346-01-aa-logJavaException.diff,
> derby-6346-02-aa-generateNullForLeftJoins.diff
>
>
> Derby trips over an NPE while processing a left join whose inner table has a
> generated column. The NPE is not printed to derby.log, indicating another
> problem. The bug goes as far back as 10.5.1.1, the release which introduced
> generated columns. The NPE does NOT crash the connection. The application can
> continue issuing statements on the connection.
> The following script shows this problem:
> connect 'jdbc:derby:memory:db;create=true';
> create table t1( c1 int, c2 int generated always as ( -c1 ) );
> create table t2( c1 int );
> insert into t1( c1 ) values ( 2 ), ( 20 );
> insert into t2( c1 ) values ( 2 ), ( 200 );
> -- raises a SQLException wrapping an NPE
> select * from t2 left join t1 on t1.c1 = t2.c1;
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira