Uploaded image for project: 'Derby'
  1. Derby
  2. DERBY-6013

Assert failure with ORDER BY in UNION used in sub-query

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 10.6.1.0, 10.6.2.1, 10.7.1.1, 10.8.1.2, 10.8.2.2, 10.8.3.0, 10.9.1.0, 10.10.1.1
    • Fix Version/s: None
    • Component/s: SQL
    • Urgency:
      Normal
    • Issue & fix info:
      Repro attached

      Description

      I see an assert failure when executing this sequence of statements using a debug version of 10.9.1.0 or trunk:

      ij version 10.9
      ij> connect 'jdbc:derby:memory:db;create=true';
      ij> create table t(x int);
      0 rows inserted/updated/deleted
      ij> create table u(x int);
      0 rows inserted/updated/deleted
      ij> insert into t values 1,2,3,4,5;
      5 rows inserted/updated/deleted
      ij> insert into u values 4,5,6,7;
      4 rows inserted/updated/deleted
      ij> select * from sysibm.sysdummy1 where exists ((select * from t) union (select * from u where x = 4) order by x);
      ERROR XJ001: Java exception: 'ASSERT FAILED getMatchingColumn() not expected to be called for tableConstructor: false
      all: false
      nestedInParens: false
      correlation Name: null
      null
      tableNumber 3
      level 1
      resultSetNumber: 0
      referencedTableMap: null
      statementResultSet: false
      : org.apache.derby.shared.common.sanity.AssertFailure'.

      Using a non-debug build makes it fail more gracefully:

      ij> select * from sysibm.sysdummy1 where exists ((select * from t) union (select * from u where x = 4) order by x);
      ERROR 42X04: Column 'X' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE statement then 'X' is not a column in the target table.

      However, I think the error message is misleading, as X is a valid column in the query. Seen for example by executing the nested query as a top-level query:

      ij> (select * from t) union all (select * from u where x = 4) order by x;
      X
      -----------
      1
      2
      3
      4
      4
      5

      6 rows selected

      However, possibly related, if I simply add parentheses around the working query, it again fails with a complaint about the column X:

      ij> ((select * from t) union all (select * from u where x = 4) order by x);
      ERROR 42X78: Column 'X' is not in the result of the query expression.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              knutanders Knut Anders Hatlen
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: