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

LIMIT and ORDER BY clause is ignored on a query with UNION when using brackets

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.4(EOL)
    • 10.4.0
    • Parser
    • None

    Description

      CREATE TABLE t1 (b int);
      INSERT INTO t1 VALUES(1),(2),(3),(4);
       
      CREATE TABLE t2 (b int);
      INSERT INTO t2 VALUES (4),(5),(6),(7);
       
      (select b from t1  UNION select b from t2) limit 1;
      (select b from t1  UNION select b from t2) order by b desc;
      

      MariaDB [test]> (select b from t1  UNION select b from t2) limit 1;
      +------+
      | b    |
      +------+
      |    1 |
      |    2 |
      |    3 |
      |    4 |
      |    5 |
      |    6 |
      |    7 |
      +------+
      7 rows in set (0.001 sec)
       
      MariaDB [test]> (select b from t1  UNION select b from t2) order by b desc;
      +------+
      | b    |
      +------+
      |    1 |
      |    2 |
      |    3 |
      |    4 |
      |    5 |
      |    6 |
      |    7 |
      +------+
      7 rows in set (0.001 sec)
       
      MariaDB [test]> (select b from t1  UNION select b from t2 limit 1);
      +------+
      | b    |
      +------+
      |    1 |
      |    2 |
      |    3 |
      |    4 |
      |    5 |
      |    6 |
      |    7 |
      +------+
      7 rows in set (0.002 sec)
      expected :
      MariaDB [test]> select b from t1  UNION select b from t2 limit 1;
      +------+
      | b    |
      +------+
      |    1 |
      +------+
      1 row in set (0.001 sec)
      

      Attachments

        Issue Links

          Activity

            alice Alice Sherepa created issue -
            alice Alice Sherepa made changes -
            Field Original Value New Value
            alice Alice Sherepa made changes -
            Assignee Oleksandr Byelkin [ sanja ]
            alice Alice Sherepa made changes -
            alice Alice Sherepa made changes -
            Description {code:sql}
            CREATE TABLE t1 (b int);
            INSERT INTO t1 VALUES(1),(2),(3),(4);

            CREATE TABLE t2 (b int);
            INSERT INTO t2 VALUES (4),(5),(6),(7);

            (select b from t1 UNION select b from t2) limit 1;
            (select b from t1 UNION select b from t2) order by b desc;
            {code}
            {noformat}
            MariaDB [test]> (select b from t1 UNION select b from t2) limit 1;
            +------+
            | b |
            +------+
            | 1 |
            | 2 |
            | 3 |
            | 4 |
            | 5 |
            | 6 |
            | 7 |
            +------+
            7 rows in set (0.001 sec)

            MariaDB [test]> (select b from t1 UNION select b from t2) order by b desc;
            +------+
            | b |
            +------+
            | 1 |
            | 2 |
            | 3 |
            | 4 |
            | 5 |
            | 6 |
            | 7 |
            +------+
            7 rows in set (0.001 sec)

            {noformat}
            {code:sql}
            CREATE TABLE t1 (b int);
            INSERT INTO t1 VALUES(1),(2),(3),(4);

            CREATE TABLE t2 (b int);
            INSERT INTO t2 VALUES (4),(5),(6),(7);

            (select b from t1 UNION select b from t2) limit 1;
            (select b from t1 UNION select b from t2) order by b desc;
            {code}
            {noformat}
            MariaDB [test]> (select b from t1 UNION select b from t2) limit 1;
            +------+
            | b |
            +------+
            | 1 |
            | 2 |
            | 3 |
            | 4 |
            | 5 |
            | 6 |
            | 7 |
            +------+
            7 rows in set (0.001 sec)

            MariaDB [test]> (select b from t1 UNION select b from t2) order by b desc;
            +------+
            | b |
            +------+
            | 1 |
            | 2 |
            | 3 |
            | 4 |
            | 5 |
            | 6 |
            | 7 |
            +------+
            7 rows in set (0.001 sec)

            MariaDB [test]> (select b from t1 UNION select b from t2 limit 1);
            +------+
            | b |
            +------+
            | 1 |
            | 2 |
            | 3 |
            | 4 |
            | 5 |
            | 6 |
            | 7 |
            +------+
            7 rows in set (0.002 sec)
            expected :
            MariaDB [test]> select b from t1 UNION select b from t2 limit 1;
            +------+
            | b |
            +------+
            | 1 |
            +------+
            1 row in set (0.001 sec)
            {noformat}
            alice Alice Sherepa made changes -
            Assignee Oleksandr Byelkin [ sanja ] Igor Babaev [ igor ]
            igor Igor Babaev (Inactive) made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            igor Igor Babaev (Inactive) made changes -
            Assignee Igor Babaev [ igor ] Oleksandr Byelkin [ sanja ]
            Status In Progress [ 3 ] In Review [ 10002 ]
            igor Igor Babaev (Inactive) made changes -
            Assignee Oleksandr Byelkin [ sanja ] Igor Babaev [ igor ]
            igor Igor Babaev (Inactive) made changes -
            Status In Review [ 10002 ] Stalled [ 10000 ]
            igor Igor Babaev (Inactive) made changes -
            Component/s Parser [ 10201 ]
            Fix Version/s 10.4.0 [ 23115 ]
            Fix Version/s 10.4 [ 22408 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 87598 ] MariaDB v4 [ 154455 ]

            People

              igor Igor Babaev (Inactive)
              alice Alice Sherepa
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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