You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Knut Anders Hatlen (JIRA)" <ji...@apache.org> on 2014/05/06 08:53:14 UTC

[jira] [Updated] (DERBY-6563) NOT elimination for CASE expressions is broken

     [ https://issues.apache.org/jira/browse/DERBY-6563?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Knut Anders Hatlen updated DERBY-6563:
--------------------------------------

    Attachment: d6563-1a.diff

There are actually two problems with ConditionalNode.eliminateNots():

# It's incomplete because
#* a) it doesn't descend into the testCondition field (the expression in the WHEN clause)
#* b) it doesn't do anything if the top-level node is not under a NOT node
# When it actually does something, it changes the tree in a way that alters the meaning

The former is not causing any wrong results. It's just that an optimization is skipped so that some NOT nodes that could have been eliminated from the child expressions, are not eliminated.

The latter is causing wrong results.

The attached patch [^d6563-1a.diff] fixes both of the issues. The method now always descends into the THEN and ELSE clauses, and inverts them if (and only if) the node is under a NOT node. It now also descends into the WHEN clause to eliminate unnecessary NOT nodes below it, but it never inverts that clause, since that would alter the meaning of the expression.

The regression tests passed with the patch.

> NOT elimination for CASE expressions is broken
> ----------------------------------------------
>
>                 Key: DERBY-6563
>                 URL: https://issues.apache.org/jira/browse/DERBY-6563
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.10.2.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>         Attachments: d6563-1a.diff
>
>
> NOT elimination for CASE expressions seems to be broken. Take this example:
> {noformat}
> ij> select * from sysibm.sysdummy1 where not ( case when ibmreqd = 'Y' then true else true end );
> IBM&
> ----
> Y   
> 1 row selected
> {noformat}
> Both branches of the CASE expression evaluate to TRUE, so one would expect the predicate "not ( case ... )" to evaluate to FALSE, and the query should return an empty result.



--
This message was sent by Atlassian JIRA
(v6.2#6252)