Derby
  1. Derby
  2. DERBY-4698

Simple query with HAVING clause crashes with NullPointerException

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 10.3.1.4, 10.3.2.1, 10.3.3.0, 10.4.1.3, 10.4.2.0, 10.5.1.1, 10.5.2.0, 10.5.3.0, 10.6.1.0
    • Fix Version/s: 10.5.3.1, 10.6.2.1, 10.7.1.1
    • Component/s: SQL
    • Labels:
      None
    • Environment:
      Windows, Java 1.6
    • Bug behavior facts:
      Crash, Seen in production, Wrong query result

      Description

      Running a simple SQL query containing a having clause causes a NullPointerException. I originally encountered this in 10.4.2.0, but have also reproduces this in 10.5.3.0 and the latest 10.6.1.0. I raised this on the mailing list too, and Knut said it also fails on trunk - see http://thread.gmane.org/gmane.comp.apache.db.derby.user/12782

      The query (created throw Hibernate) that causes the crash is:

      SELECT user0_.user_id AS col_0_0_,
      SUM(account2_.balance) AS col_1_0_
      FROM tbl_user user0_
      INNER JOIN tbl_user_account accountlin1_
      ON user0_.user_id = accountlin1_.user_id
      INNER JOIN tbl_account account2_
      ON accountlin1_.account_id = account2_.account_id
      WHERE user0_.deleted = 'N'
      AND ( account2_.account_type IN ( 'USER-01', 'USER' ) )
      GROUP BY user0_.user_id
      HAVING SUM(account2_.balance) >= 100.0

      However I simplified it to the following and still caused a crash (though in 10.4.2.0 I found that without the "where" clause is didn't crash but returned no results when it should have).

      SELECT u.user_id,
      SUM(a.balance)
      FROM tbl_user u
      INNER JOIN tbl_user_account al
      ON u.user_id = al.user_id
      INNER JOIN tbl_account a
      ON al.account_id = a.account_id
      GROUP BY u.user_id
      HAVING sum(a.balance) >= 10.0

      The derby log showed the following stace trace for 10.6.1.0:
      2010-06-14 04:59:24.942 GMT Thread[main,5,main] (XID = 5824013), (SESSIONID = 1), (DATABASE = C:\Development\pc-ng-branch\server\working\data\internal/derby), (DRDAID = null), Failed Statement is: SELECT u.user_id user_id,
      SUM(a.balance) acct_sum
      FROM tbl_user u
      INNER JOIN tbl_user_account al
      ON u.user_id = al.user_id
      INNER JOIN tbl_account a
      ON al.account_id = a.account_id
      GROUP BY u.user_id
      HAVING sum(a.balance) >= 1.0
      java.lang.NullPointerException
      at org.apache.derby.impl.sql.compile.ColumnReference.remapColumnReferencesToExpressions(Unknown Source)
      at org.apache.derby.impl.sql.compile.AggregateNode.getNewExpressionResultColumn(Unknown Source)
      at org.apache.derby.impl.sql.compile.GroupByNode.addAggregateColumns(Unknown Source)
      at org.apache.derby.impl.sql.compile.GroupByNode.addNewColumnsForAggregation(Unknown Source)
      at org.apache.derby.impl.sql.compile.GroupByNode.addAggregates(Unknown Source)
      at org.apache.derby.impl.sql.compile.GroupByNode.init(Unknown Source)
      at org.apache.derby.iapi.sql.compile.NodeFactory.getNode(Unknown Source)
      at org.apache.derby.impl.sql.compile.SelectNode.genProjectRestrict(Unknown Source)
      at org.apache.derby.impl.sql.compile.SelectNode.modifyAccessPaths(Unknown Source)
      at org.apache.derby.impl.sql.compile.DMLStatementNode.optimizeStatement(Unknown Source)
      at org.apache.derby.impl.sql.compile.CursorNode.optimizeStatement(Unknown Source)
      at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
      at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
      at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
      at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
      at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
      at org.apache.derby.impl.tools.ij.ij.executeImmediate(Unknown Source)
      at org.apache.derby.impl.tools.ij.utilMain.doCatch(Unknown Source)
      at org.apache.derby.impl.tools.ij.utilMain.runScriptGuts(Unknown Source)
      at org.apache.derby.impl.tools.ij.utilMain.go(Unknown Source)
      at org.apache.derby.impl.tools.ij.Main.go(Unknown Source)
      at org.apache.derby.impl.tools.ij.Main.mainCore(Unknown Source)
      at org.apache.derby.impl.tools.ij.Main.main(Unknown Source)
      at org.apache.derby.tools.ij.main(Unknown Source)
      Cleanup action completed

      1. derby.zip
        615 kB
        Matt Doran
      2. derby-4698-1.diff
        6 kB
        Dag H. Wanvik
      3. derby-4698-1.stat
        0.4 kB
        Dag H. Wanvik
      4. derby-4698-2.diff
        11 kB
        Dag H. Wanvik
      5. derby-4698-2.stat
        0.5 kB
        Dag H. Wanvik
      6. derby-crash-10.4.2.0.log
        3 kB
        Matt Doran
      7. derby-crash-10.5.3.0.log
        3 kB
        Matt Doran
      8. derby-crash-10.6.1.0.log
        3 kB
        Matt Doran

        Issue Links

          Activity

          Gavin made changes -
          Workflow jira [ 12513279 ] Default workflow, editable Closed status [ 12802813 ]
          Knut Anders Hatlen made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Knut Anders Hatlen made changes -
          Link This issue is duplicated by DERBY-4954 [ DERBY-4954 ]
          Rick Hillegas made changes -
          Fix Version/s 10.7.1.1 [ 12315564 ]
          Fix Version/s 10.7.1.0 [ 12314971 ]
          Knut Anders Hatlen made changes -
          Fix Version/s 10.6.2.1 [ 12315343 ]
          Fix Version/s 10.6.2.0 [ 12315342 ]
          Kathey Marsden made changes -
          Fix Version/s 10.6.2.0 [ 12315342 ]
          Fix Version/s 10.6.1.1 [ 12314973 ]
          Knut Anders Hatlen made changes -
          Status Reopened [ 4 ] Resolved [ 5 ]
          Fix Version/s 10.5.3.1 [ 12314182 ]
          Fix Version/s 10.5.4.0 [ 12314154 ]
          Resolution Fixed [ 1 ]
          Kathey Marsden made changes -
          Resolution Fixed [ 1 ]
          Status Resolved [ 5 ] Reopened [ 4 ]
          Kathey Marsden made changes -
          Link This issue is required by DERBY-4728 [ DERBY-4728 ]
          Mike Matrigali made changes -
          Fix Version/s 10.5.4.0 [ 12314154 ]
          Mike Matrigali made changes -
          Assignee Mike Matrigali [ mikem ] Dag H. Wanvik [ dagw ]
          Mike Matrigali made changes -
          Assignee Dag H. Wanvik [ dagw ] Mike Matrigali [ mikem ]
          Dag H. Wanvik made changes -
          Affects Version/s 10.5.2.0 [ 12314116 ]
          Affects Version/s 10.5.1.1 [ 12313771 ]
          Affects Version/s 10.4.1.3 [ 12313111 ]
          Affects Version/s 10.3.3.0 [ 12313142 ]
          Affects Version/s 10.3.2.1 [ 12312876 ]
          Affects Version/s 10.3.1.4 [ 12312590 ]
          Dag H. Wanvik made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Issue & fix info [Patch Available]
          Fix Version/s 10.6.1.1 [ 12314973 ]
          Fix Version/s 10.7.0.0 [ 12314971 ]
          Resolution Fixed [ 1 ]
          Dag H. Wanvik made changes -
          Attachment derby-4698-2.diff [ 12447084 ]
          Attachment derby-4698-2.stat [ 12447085 ]
          Dag H. Wanvik made changes -
          Link This issue is related to DERBY-3880 [ DERBY-3880 ]
          Dag H. Wanvik made changes -
          Bug behavior facts [Crash, Wrong query result] [Crash, Seen in production, Wrong query result]
          Dag H. Wanvik made changes -
          Issue & fix info [Patch Available]
          Dag H. Wanvik made changes -
          Assignee Dag H. Wanvik [ dagw ]
          Dag H. Wanvik made changes -
          Attachment derby-4698-1.diff [ 12447067 ]
          Attachment derby-4698-1.stat [ 12447068 ]
          Matt Doran made changes -
          Attachment derby.zip [ 12447004 ]
          Matt Doran made changes -
          Attachment derby-crash-10.4.2.0.log [ 12447003 ]
          Matt Doran made changes -
          Attachment derby-crash-10.5.3.0.log [ 12447002 ]
          Matt Doran made changes -
          Field Original Value New Value
          Attachment derby-crash-10.6.1.0.log [ 12447001 ]
          Matt Doran created issue -

            People

            • Assignee:
              Dag H. Wanvik
              Reporter:
              Matt Doran
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development