Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-30472

Unresolvalble column reference in ORDER BY clause of union ignored

    XMLWordPrintable

Details

    Description

      If an unresolvalble column reference occurs in ORDER BY clause of an union contained in an EXISTs subquery of in the left part of a subquery predicand then it is ignored and no error message is reported.

      Here is a test case demonstrating the problem:

      create table t1 (a int, b int);
      insert into t1 values (3,8), (7,2), (1,4), (5,9);
       
      create table t2 (a int, b int);
      insert into t2 values (9,1), (7,3), (2,6);
       
      create table t3 (c int, d int);
      insert into t3 values (7,8), (1,2), (3,8), (9,1);
       
      select * from t3 as t
      where 
        (t.c,t.d) in 
        (
          select a,b from t1 where t1.a > 3
          union
          select a,b from t2 where t2.b < 6
          order by (a - b/x)
        )
      ;
       
      drop table t1,t2,t3;
      

      When executing the above query we have

      MariaDB [test]> select * from t3 as t
          -> where 
          ->   (t.c,t.d) in 
          ->   (
          ->     select a,b from t1 where t1.a > 3
          ->     union
          ->     select a,b from t2 where t2.b < 6
          ->     order by (a - b/x)
          ->   )
          -> ;
      +------+------+
      | c    | d    |
      +------+------+
      |    9 |    1 |
      +------+------+
      

      However the same error message as from the query

          select a,b from t1 where t1.a > 3
          union
          select a,b from t2 where t2.b < 6
          order by (a - b/x)
      

      is expected

      MariaDB [test]>     select a,b from t1 where t1.a > 3
          ->     union
          ->     select a,b from t2 where t2.b < 6
          ->     order by (a - b/x)
          -> ;
      ERROR 1054 (42S22): Unknown column 'x' in 'order clause'
      

      Attachments

        Activity

          People

            igor Igor Babaev
            igor Igor Babaev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.