Derby
  1. Derby
  2. DERBY-4448

ArrayIndexOutOfBoundsException when trying to override generated column

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 10.5.3.0, 10.6.1.0
    • Fix Version/s: 10.5.3.1, 10.6.1.0
    • Component/s: SQL
    • Labels:
      None

      Description

      ij> create table t(a int, b generated always as (-a));
      0 rows inserted/updated/deleted
      ij> insert into t(b) values (default), (2);
      ERROR XJ001: Java exception: '0 >= 0: java.lang.ArrayIndexOutOfBoundsException'.

      1. forbid.diff
        1.0 kB
        Knut Anders Hatlen

        Issue Links

          Activity

          Hide
          Knut Anders Hatlen added a comment -

          I think the problem is that DMLModStatementNode.forbidGenerationOverrides() only looks at and modifies the RCL of the top-most source result set. Since it removes generated columns from both the target RCL and the source RCL, the child result sets of the UnionNode representing the multi-row VALUES clause are not processed, so all rows except the first row will end up with more columns than the target RCL.

          Show
          Knut Anders Hatlen added a comment - I think the problem is that DMLModStatementNode.forbidGenerationOverrides() only looks at and modifies the RCL of the top-most source result set. Since it removes generated columns from both the target RCL and the source RCL, the child result sets of the UnionNode representing the multi-row VALUES clause are not processed, so all rows except the first row will end up with more columns than the target RCL.
          Hide
          Knut Anders Hatlen added a comment -

          I tried a simple fix, removing the call to forbidGenerationOverrides() in InsertNode.bindStatement() and instead making sure InsertNode.enhanceAndCheckForAutoincrement() calls RCL.forbidOverrides() on all types of ResultSetNodes.

          This made the problematic statement fail gracefully, but it introduced one failure in GeneratedColumnsTest.test_005_basicInsert(). That was the same failure as was seen with the first partial patch for DERBY-4433.

          Show
          Knut Anders Hatlen added a comment - I tried a simple fix, removing the call to forbidGenerationOverrides() in InsertNode.bindStatement() and instead making sure InsertNode.enhanceAndCheckForAutoincrement() calls RCL.forbidOverrides() on all types of ResultSetNodes. This made the problematic statement fail gracefully, but it introduced one failure in GeneratedColumnsTest.test_005_basicInsert(). That was the same failure as was seen with the first partial patch for DERBY-4433 .
          Hide
          Knut Anders Hatlen added a comment -

          Unassigning since it's probably better to revisit the issue after DERBY-4433 and DERBY-4442 have been addressed. But anyone should feel free to pick it up even before that if they see how to solve it.

          Show
          Knut Anders Hatlen added a comment - Unassigning since it's probably better to revisit the issue after DERBY-4433 and DERBY-4442 have been addressed. But anyone should feel free to pick it up even before that if they see how to solve it.
          Hide
          Knut Anders Hatlen added a comment -

          One doesn't actually need to override the generated column to see this error. Just trying to insert DEFAULT in all rows also fails this way:

          ij> create table t(a int generated always as (-b), b int);
          0 rows inserted/updated/deleted
          ij> insert into t(a) values (default);
          1 row inserted/updated/deleted
          ij> insert into t(a) values (default), (default);
          ERROR XJ001: Java exception: '0 >= 0: java.lang.ArrayIndexOutOfBoundsException'.

          Show
          Knut Anders Hatlen added a comment - One doesn't actually need to override the generated column to see this error. Just trying to insert DEFAULT in all rows also fails this way: ij> create table t(a int generated always as (-b), b int); 0 rows inserted/updated/deleted ij> insert into t(a) values (default); 1 row inserted/updated/deleted ij> insert into t(a) values (default), (default); ERROR XJ001: Java exception: '0 >= 0: java.lang.ArrayIndexOutOfBoundsException'.
          Hide
          Dag H. Wanvik added a comment -

          This patch attached to DERBY-4451 also solves this issue.

          Show
          Dag H. Wanvik added a comment - This patch attached to DERBY-4451 also solves this issue.
          Hide
          Dag H. Wanvik added a comment -

          Resolving this, since the issue is fixed by the committed fix to DERBY-4451.

          Show
          Dag H. Wanvik added a comment - Resolving this, since the issue is fixed by the committed fix to DERBY-4451 .
          Hide
          Knut Anders Hatlen added a comment -

          Verified fix on trunk. Closing.

          Show
          Knut Anders Hatlen added a comment - Verified fix on trunk. Closing.
          Hide
          Lily Wei added a comment -

          Reopen to 10.5 back port.

          Show
          Lily Wei added a comment - Reopen to 10.5 back port.
          Hide
          Mike Matrigali added a comment -

          this issue was also fixed by DERBY-4451 which has already been backported to 10.5. Resolving issue as fixed in 10.5 branch.

          Show
          Mike Matrigali added a comment - this issue was also fixed by DERBY-4451 which has already been backported to 10.5. Resolving issue as fixed in 10.5 branch.
          Hide
          Knut Anders Hatlen added a comment -

          Changed 10.5 fix version to match the version on the branch.

          Show
          Knut Anders Hatlen added a comment - Changed 10.5 fix version to match the version on the branch.

            People

            • Assignee:
              Dag H. Wanvik
              Reporter:
              Knut Anders Hatlen
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development