db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Knut Anders Hatlen (JIRA)" <j...@apache.org>
Subject [jira] Commented: (DERBY-4391) NullPointerException when comparing indexed column with result from a set operation
Date Mon, 12 Oct 2009 12:55:31 GMT

    [ https://issues.apache.org/jira/browse/DERBY-4391?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12764670#action_12764670

Knut Anders Hatlen commented on DERBY-4391:

Thanks for looking at the patch, Dag.

> I wonder if it is meaningful for the visitor in
> PredicateList.markReferencedColumns() to go down into subqueries.

If the sub-query is correlated, I think we'll need to go down into it to see if
it references any of the columns in the index. Now, it doesn't look like
markReferencedColumns() is called if we have a correlated sub-query. It is only
called when bulk-fetching from a non-covering index, and perhaps bulk-fetching
is disabled when we have a correlated sub-query in the predicate list?

> At the corresponding place (column reference) in a query tree for
>    select * from (select * from t union select * from t) x
> I see that the column reference source actually points to a result column of
> the PRN wrapping the base table in the *left* query tree of the UNION. (That
> also seems a bit arbitrary, why not the right?  :)

I had the same feeling that it was somewhat arbitrary when I looked at the
logic in ResultColumnList.setUnionResultExpression(). For EXCEPT queries, it
may make sense, since all the rows in the result come from the left side. For
UNION and INTERSECT, they could just as well come from the right side, though.

> If it is sound for the VALUE case to have an empty column reference, I can't
> answer that, because I don't fully understand how the column references are
> used in later phases.

Neither do I. BaseTableNumbersVisitor.visit() says this about the case where
getSource() returns null:

        if (rc == null) {
        // this can happen if column reference is pointing to a column
        // that is not from a base table.  For example, if we have a
        // VALUES clause like
        //    (values (1, 2), (3, 4)) V1 (i, j)
        // and then a column reference to VI.i, the column reference
        // won't have a source.
            return node;

This is actually just a variant of the case we're looking at, since a multi-row
value statement is rewritten to a union internally. So it's possible to
reproduce the NPE without explicitly using a set operation, as seen here:

ij(CONNECTION2)> select * from t where a < (values 1,2,3);
ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
ij(CONNECTION2)> select * from t where a < (select max(x) from (values 1,2,3) v(x));
ERROR XJ001: Java exception: ': java.lang.NullPointerException'.

Although I'm still not 100% convinced it is correct that the CR is null in the
first place, I'm inclined to go for the 1a patch, but with a comment like the
one in BTNV.visit() added to markReferencedColumns(). Since such a change only
affects statements that previously raised a NPE, it should at least not make
the situation worse for queries that used to work.

> NullPointerException when comparing indexed column with result from a set operation
> -----------------------------------------------------------------------------------
>                 Key: DERBY-4391
>                 URL: https://issues.apache.org/jira/browse/DERBY-4391
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions:,,,,
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>         Attachments: d4391-1a.diff, d4391-1a.stat
> I'm reporting this issue on behalf of Bernt M. Johnsen.
> If an indexed column is compared with a UNION query (or some other set operation), a
NullPointerException is raised, as can be seen by this sequence of statements in ij:
> ij> create table t(a int not null primary key, b int);
> 0 rows inserted/updated/deleted
> ij> select * from t where a < (values 4 union values 4);
> ERROR XJ001: Java exception: ': java.lang.NullPointerException'.

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

View raw message