Derby
  1. Derby
  2. DERBY-5614

NullPointerException with INSERT INTO [global temporary table] SELECT ... FROM [VTI]

    Details

    • Urgency:
      Normal
    • Issue & fix info:
      Repro attached
    • Bug behavior facts:
      Crash

      Description

      Inserting into a global temporary table (GTT) while selecting data from a VTI fails with a NullPointerException:

      Caused by: java.lang.NullPointerException
      at org.apache.derby.impl.sql.execute.WriteCursorConstantAction.getEmptyHeapRow(WriteCursorConstantAction.java:324)
      at org.apache.derby.impl.sql.execute.InsertResultSet.bulkInsertCore(InsertResultSet.java:1209)
      at org.apache.derby.impl.sql.execute.InsertResultSet.open(InsertResultSet.java:466)
      at org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(GenericPreparedStatement.java:443)
      at org.apache.derby.impl.sql.GenericPreparedStatement.execute(GenericPreparedStatement.java:324)
      at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1242)
      ... 6 more

      Investigation exposed the fact that bulk insert doesn't support a GTT as the target, and further that Derby enables bulk insert when the source is a VTI.

      1. repro.sql
        1 kB
        Dag H. Wanvik
      2. derby-5614-1b-disable_bulkinsert_gtt.diff
        16 kB
        Kristian Waagan
      3. derby-5614-1a-disable_bulkinsert_gtt.diff
        0.9 kB
        Kristian Waagan

        Issue Links

          Activity

          Hide
          Dag H. Wanvik added a comment -

          Attaching repro which should run and show NPE if you run if you set CLASSPATH to the classes dir after building Derby.

          Show
          Dag H. Wanvik added a comment - Attaching repro which should run and show NPE if you run if you set CLASSPATH to the classes dir after building Derby.
          Hide
          Kristian Waagan added a comment -

          Attaching a fix for the bug as patch 1a.
          I'lll do some more testing and see if anything else has to be done.

          Comments appreciated, I'm not familiar with this code.

          Also note that the bug isn't triggered if you use one of the VTIs in SYSCS_DIAG as they'll return false for 'tableFunctionVisitor.hasNode()'.

          Show
          Kristian Waagan added a comment - Attaching a fix for the bug as patch 1a. I'lll do some more testing and see if anything else has to be done. Comments appreciated, I'm not familiar with this code. Also note that the bug isn't triggered if you use one of the VTIs in SYSCS_DIAG as they'll return false for 'tableFunctionVisitor.hasNode()'.
          Hide
          Kristian Waagan added a comment -

          Committed an unrelated test fix to trunk with revision 1294522 (string comparison using ==). Tagging it with this issue so that it will be backported.

          Show
          Kristian Waagan added a comment - Committed an unrelated test fix to trunk with revision 1294522 (string comparison using ==). Tagging it with this issue so that it will be backported.
          Hide
          Kristian Waagan added a comment -

          Attaching patch 1b, which adds a test for this issue.
          I added the test case to lang.DeclareGlobalTempTableTest, and also added a new class SampleVTI to functionTests.util.

          Patch ready for review.

          Show
          Kristian Waagan added a comment - Attaching patch 1b, which adds a test for this issue. I added the test case to lang.DeclareGlobalTempTableTest, and also added a new class SampleVTI to functionTests.util. Patch ready for review.
          Hide
          Kristian Waagan added a comment -

          Attached the wrong patch file (git diff vs git diff --cached).

          Show
          Kristian Waagan added a comment - Attached the wrong patch file (git diff vs git diff --cached).
          Hide
          Kristian Waagan added a comment -

          suites.All ran cleanly on Solaris 11 with JDK 7.

          Show
          Kristian Waagan added a comment - suites.All ran cleanly on Solaris 11 with JDK 7.
          Hide
          Kristian Waagan added a comment -

          Committed patch 1b to trunk with revision 1295085.
          I'm leaving the issue open for backporting.

          Show
          Kristian Waagan added a comment - Committed patch 1b to trunk with revision 1295085. I'm leaving the issue open for backporting.
          Hide
          Kristian Waagan added a comment -

          I now see that StringColumnVTI is part of the public API for trunk and 10.8. SampleVTI should be rewritten to use it. I logged DERBY-5634 for this small task.

          Show
          Kristian Waagan added a comment - I now see that StringColumnVTI is part of the public API for trunk and 10.8. SampleVTI should be rewritten to use it. I logged DERBY-5634 for this small task.
          Hide
          Kristian Waagan added a comment -

          Backported fix to 10.8 with revision 1300534, and to 10.7 with revision 1300622.
          On 10.6 I got merge conflicts in InsertNode so I decided to stop there.

          Show
          Kristian Waagan added a comment - Backported fix to 10.8 with revision 1300534, and to 10.7 with revision 1300622. On 10.6 I got merge conflicts in InsertNode so I decided to stop there.
          Hide
          Kristian Waagan added a comment -

          Adjusting Affects versions. This bug may go further back than 10.7, but I'm not planning to verify that. Since nobody has reported the problem earlier, the usage scenario is probably pretty rare.

          Show
          Kristian Waagan added a comment - Adjusting Affects versions. This bug may go further back than 10.7, but I'm not planning to verify that. Since nobody has reported the problem earlier, the usage scenario is probably pretty rare.
          Hide
          Kristian Waagan added a comment -

          Closing issue.

          Show
          Kristian Waagan added a comment - Closing issue.
          Hide
          Mamta A. Satoor added a comment -

          I will look into backporting this to 10.6

          Show
          Mamta A. Satoor added a comment - I will look into backporting this to 10.6
          Hide
          Mamta A. Satoor added a comment -

          DERBY-4789 (Always apply the bulk-insert optimization when inserting from a table function.)
          DERBY-5614 (NullPointerException with INSERT INTO [global temporary table] SELECT ... FROM [VTI])

          The changes for DERBY-5614 depend on the changes for DERBY-4789.

          Backported both these jiras into 10.6.2.3 with revision 1387685.

          Show
          Mamta A. Satoor added a comment - DERBY-4789 (Always apply the bulk-insert optimization when inserting from a table function.) DERBY-5614 (NullPointerException with INSERT INTO [global temporary table] SELECT ... FROM [VTI] ) The changes for DERBY-5614 depend on the changes for DERBY-4789 . Backported both these jiras into 10.6.2.3 with revision 1387685.
          Hide
          Mamta A. Satoor added a comment -

          Reopening for backport

          Show
          Mamta A. Satoor added a comment - Reopening for backport
          Hide
          Mamta A. Satoor added a comment -

          I tried back porting the changes for this jira to 10.5 and found that the code has dependency not just on DERBY-4789(Always apply the bulk-insert optimization when inserting from a table function.)
          but also on DERBY-4397(Allow ORDER BY in subqueries). From the jira description, it sounds like DERBY-4789 is a feature and hence we probably do not want it backported to 10.5, I will go ahead and label the jira as not eligible for 10.5 backport.

          Show
          Mamta A. Satoor added a comment - I tried back porting the changes for this jira to 10.5 and found that the code has dependency not just on DERBY-4789 (Always apply the bulk-insert optimization when inserting from a table function.) but also on DERBY-4397 (Allow ORDER BY in subqueries). From the jira description, it sounds like DERBY-4789 is a feature and hence we probably do not want it backported to 10.5, I will go ahead and label the jira as not eligible for 10.5 backport.
          Hide
          Knut Anders Hatlen added a comment -

          [bulk update: close all resolved issues that haven't had any activity the last year]

          Show
          Knut Anders Hatlen added a comment - [bulk update: close all resolved issues that haven't had any activity the last year]

            People

            • Assignee:
              Kristian Waagan
              Reporter:
              Kristian Waagan
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development