Derby
  1. Derby
  2. DERBY-4425

NullPointerException with INSERT INTO ... from UNION and columns generated from expressions

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 10.5.1.1, 10.5.3.0, 10.6.1.0
    • Fix Version/s: 10.5.3.1, 10.6.1.0
    • Component/s: SQL
    • Labels:
      None
    • Issue & fix info:
      Repro attached

      Description

      This bug is similar to DERBY-4419, only that it uses columns that are auto-generated from expressions and not identity columns. The proposed fix for DERBY-4419 only addresses the case with an identity column.

      ij> create table t1(x int);
      0 rows inserted/updated/deleted
      ij> create table t2(x int);
      0 rows inserted/updated/deleted
      ij> create table t3(x int, y generated always as (2*x));
      0 rows inserted/updated/deleted
      ij> insert into t3 select * from t1 union select * from t2;
      ERROR XJ001: Java exception: ': java.lang.NullPointerException'.

        Issue Links

          Activity

          Knut Anders Hatlen created issue -
          Hide
          Knut Anders Hatlen added a comment -

          java.lang.NullPointerException
          at org.apache.derby.iapi.types.DataTypeDescriptor.isExactTypeAndLengthMatch(DataTypeDescriptor.java:954)
          at org.apache.derby.impl.sql.compile.ResultColumn.columnTypeAndLengthMatch(ResultColumn.java:1020)
          at org.apache.derby.impl.sql.compile.ResultColumnList.columnTypesAndLengthsMatch(ResultColumnList.java:1696)
          at org.apache.derby.impl.sql.compile.ResultSetNode.columnTypesAndLengthsMatch(ResultSetNode.java:934)
          at org.apache.derby.impl.sql.compile.UnionNode.addNewNodes(UnionNode.java:411)
          at org.apache.derby.impl.sql.compile.UnionNode.modifyAccessPaths(UnionNode.java:361)
          at org.apache.derby.impl.sql.compile.DMLStatementNode.optimizeStatement(DMLStatementNode.java:323)
          at org.apache.derby.impl.sql.compile.DMLStatementNode.optimizeStatement(DMLStatementNode.java:302)
          at org.apache.derby.impl.sql.compile.DMLModStatementNode.optimizeStatement(DMLModStatementNode.java:1736)
          at org.apache.derby.impl.sql.GenericStatement.prepMinion(GenericStatement.java:381)
          at org.apache.derby.impl.sql.GenericStatement.prepare(GenericStatement.java:90)
          at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(GenericLanguageConnectionContext.java:828)
          at org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:606)
          at org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:555)

          Show
          Knut Anders Hatlen added a comment - java.lang.NullPointerException at org.apache.derby.iapi.types.DataTypeDescriptor.isExactTypeAndLengthMatch(DataTypeDescriptor.java:954) at org.apache.derby.impl.sql.compile.ResultColumn.columnTypeAndLengthMatch(ResultColumn.java:1020) at org.apache.derby.impl.sql.compile.ResultColumnList.columnTypesAndLengthsMatch(ResultColumnList.java:1696) at org.apache.derby.impl.sql.compile.ResultSetNode.columnTypesAndLengthsMatch(ResultSetNode.java:934) at org.apache.derby.impl.sql.compile.UnionNode.addNewNodes(UnionNode.java:411) at org.apache.derby.impl.sql.compile.UnionNode.modifyAccessPaths(UnionNode.java:361) at org.apache.derby.impl.sql.compile.DMLStatementNode.optimizeStatement(DMLStatementNode.java:323) at org.apache.derby.impl.sql.compile.DMLStatementNode.optimizeStatement(DMLStatementNode.java:302) at org.apache.derby.impl.sql.compile.DMLModStatementNode.optimizeStatement(DMLModStatementNode.java:1736) at org.apache.derby.impl.sql.GenericStatement.prepMinion(GenericStatement.java:381) at org.apache.derby.impl.sql.GenericStatement.prepare(GenericStatement.java:90) at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(GenericLanguageConnectionContext.java:828) at org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:606) at org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:555)
          Knut Anders Hatlen made changes -
          Field Original Value New Value
          Link This issue relates to DERBY-4419 [ DERBY-4419 ]
          Bryan Pendleton made changes -
          Assignee Bryan Pendleton [ bryanpendleton ]
          Hide
          Bryan Pendleton added a comment -

          Attached is a patch proposal. This patch is quite similar to the idea in DERBY-4419, but
          this patch uses resultColumn.isGeneratedForUnmatchedColumnInInsert() rather than
          the isAutoincrementGenerated() method.

          The patch includes a regression test, but I haven't run the entire suite, just the GeneratedColumnsTest.

          It appears that the use of isGeneratedForUnmanagedColumnInsert not only fixes
          this problem, but also fixes DERBY-4419, so I'm going to return to that issue and
          see if I can get a single code patch (although with different regression tests) that fixes both problems.

          Show
          Bryan Pendleton added a comment - Attached is a patch proposal. This patch is quite similar to the idea in DERBY-4419 , but this patch uses resultColumn.isGeneratedForUnmatchedColumnInInsert() rather than the isAutoincrementGenerated() method. The patch includes a regression test, but I haven't run the entire suite, just the GeneratedColumnsTest. It appears that the use of isGeneratedForUnmanagedColumnInsert not only fixes this problem, but also fixes DERBY-4419 , so I'm going to return to that issue and see if I can get a single code patch (although with different regression tests) that fixes both problems.
          Bryan Pendleton made changes -
          Attachment checkIsGenerated.diff [ 12423531 ]
          Hide
          Bryan Pendleton added a comment -

          Committed the regression test change to the trunk as revision 831319.

          The code change was committed as part of revision 831304, for DERBY-4419.

          Show
          Bryan Pendleton added a comment - Committed the regression test change to the trunk as revision 831319. The code change was committed as part of revision 831304, for DERBY-4419 .
          Bryan Pendleton made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Fix Version/s 10.6.0.0 [ 12313727 ]
          Resolution Fixed [ 1 ]
          Dag H. Wanvik made changes -
          Link This issue relates to DERBY-4442 [ DERBY-4442 ]
          Hide
          Knut Anders Hatlen added a comment -

          DERBY-4442 fixed a family of INSERT bugs, including this one, making the original fix for this issue unnecessary. The fix was therefore backed out in revision 888311, but the tests are still part of the regression test suite.

          Show
          Knut Anders Hatlen added a comment - DERBY-4442 fixed a family of INSERT bugs, including this one, making the original fix for this issue unnecessary. The fix was therefore backed out in revision 888311, but the tests are still part of the regression test suite.
          Hide
          Knut Anders Hatlen added a comment -

          Verified on trunk. Closing.

          Show
          Knut Anders Hatlen added a comment - Verified on trunk. Closing.
          Knut Anders Hatlen made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Lily Wei made changes -
          Link This issue is required by DERBY-4728 [ DERBY-4728 ]
          Hide
          Lily Wei added a comment -

          Reopen to 10.5 back port

          Show
          Lily Wei added a comment - Reopen to 10.5 back port
          Lily Wei made changes -
          Resolution Fixed [ 1 ]
          Status Closed [ 6 ] Reopened [ 4 ]
          Hide
          Mike Matrigali added a comment -

          working on backporting this issue to 10.5. DERBY-4419, DERBY-4413, DERBY-4425, and DERBY-4442 all seem related. I am going to apply and checkin the backported changes to these issues in order. I think the changes necessary are:
          DERBY-4413 #829410
          DERBY-4419 #831304
          DERBY-4425 #831319
          DERBY-4442 #885421
          DERBY-4413 #885659
          DERBY-4442 #888311

          Show
          Mike Matrigali added a comment - working on backporting this issue to 10.5. DERBY-4419 , DERBY-4413 , DERBY-4425 , and DERBY-4442 all seem related. I am going to apply and checkin the backported changes to these issues in order. I think the changes necessary are: DERBY-4413 #829410 DERBY-4419 #831304 DERBY-4425 #831319 DERBY-4442 #885421 DERBY-4413 #885659 DERBY-4442 #888311
          Mike Matrigali made changes -
          Assignee Bryan Pendleton [ bryanpendleton ] Mike Matrigali [ mikem ]
          Hide
          Mike Matrigali added a comment -

          backported change #831319 from trunk to 10.5.

          m105_jdk16:60>svn commit
          Sending .
          Sending java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
          Transmitting file data .
          Committed revision 960617.

          Show
          Mike Matrigali added a comment - backported change #831319 from trunk to 10.5. m105_jdk16:60>svn commit Sending . Sending java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java Transmitting file data . Committed revision 960617.
          Hide
          Mike Matrigali added a comment -

          backported all changes for this fix from trunk to 10.5 branch, resolving as fixed in 10.5, and resetting orignal owner.

          Show
          Mike Matrigali added a comment - backported all changes for this fix from trunk to 10.5 branch, resolving as fixed in 10.5, and resetting orignal owner.
          Mike Matrigali made changes -
          Status Reopened [ 4 ] Resolved [ 5 ]
          Fix Version/s 10.5.3.1 [ 12314182 ]
          Resolution Fixed [ 1 ]
          Mike Matrigali made changes -
          Assignee Mike Matrigali [ mikem ] Bryan Pendleton [ bryanpendleton ]
          Knut Anders Hatlen made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Gavin made changes -
          Workflow jira [ 12480416 ] Default workflow, editable Closed status [ 12799995 ]

            People

            • Assignee:
              Bryan Pendleton
              Reporter:
              Knut Anders Hatlen
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development