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

Column ordering ASSERT when combining column references and expressions in same ORDER BY

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 10.3.1.4
    • 10.3.1.4
    • SQL
    • None

    Description

      An ORDER BY clause wihch combines both column references and expressions causes the
      sort engine to throw an ASSERT failure in sane builds.

      Here's a repro script:

      -bash-2.05b$ java org.apache.derby.tools.ij
      ij version 10.3
      ij> connect 'jdbc:derby:brydb;create=true';
      ij> create table t (a int, b int, c int, d int);
      0 rows inserted/updated/deleted
      ij> insert into t values (1, 2, 3, 4);
      1 row inserted/updated/deleted
      ij> select * from t order by a, b, c+2;
      ERROR XJ001: Java exception: 'ASSERT FAILED column ordering error: org.apache.derby.shared.common.sanity.AssertFailure'.

      As a first theory to check, I believe that when columns in the ORDER BY clause go through "pullup" processing,
      they are generated into the select statement's ResultColumnList and then are later removed at bind time because
      they are determined to duplicate the columns implicitly selected by the "*" column list. But the expression "c+2" is not
      removed from the result list because it does not duplicate any existing column in the table. During this processing,
      I think that the field "addedColumnOffset" in class OrderByColumn is not managed correctly and ends up generating
      a bogus column position for the "c+2" column (it doesn't reflect that pulled-up columns "a" and "b" have disappeared
      from the ResultColumnList), causing the sanity assertion at execution time.

      I stumbled across this problem while writing regression tests for DERBY-147, but the problem occurs
      with or without the DERBY-147 fix, so I decided to log it as a separate problem.

      Attachments

        1. dataStructureNotes.html
          10 kB
          Bryan Pendleton
        2. adjustOffsets_v1.diff
          13 kB
          Bryan Pendleton
        3. proposedPatchNotes.html
          4 kB
          Bryan Pendleton
        4. adjustOffsets_v2_moreJavaDoc.diff
          17 kB
          Bryan Pendleton

        Issue Links

          Activity

            People

              bryanpendleton Bryan Pendleton
              bryanpendleton Bryan Pendleton
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: