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

UNION with LIMIT ROWS EXAMINED does not require parentheses

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.1, 10.2
    • 10.2.1
    • Parser
    • None

    Description

      10.1 disallowed use of non-parenthesized UNION parts that have ORDER or LIMIT clauses, according to the SQL Standard. That was a merge from MySQL-5.6.

      This script:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (a INT);
      INSERT INTO t1 VALUES (10),(10);
      SELECT * FROM t1 LIMIT 1
      UNION
      SELECT * FROM t1 LIMIT 1;
      

      returns an error starting from 10.1:

      ERROR 1221 (HY000): Incorrect usage of UNION and LIMIT
      

      However, if I use LIMIT in combination with ROWS EXAMINED:

      SELECT * FROM t1 LIMIT ROWS EXAMINED 1
      UNION
      SELECT * FROM t1 LIMIT ROWS EXAMINED 1;
      

      it returns a result instead of an error:

      +------+
      | a    |
      +------+
      |   10 |
      +------+
      1 row in set, 1 warning (0.00 sec)
      

      It should be fixed to require parentheses as well, like in case of a "normal" LIMIT clause.

      Most likely, LIMIT ROWS EXAMINED was just forgotten during the merge.

      The documentation at:
      https://mariadb.com/kb/en/mariadb/union/
      says:

      Individual selects can contain their own ORDER BY and LIMIT clauses. In that case, the individual queries need to be wrapped between parenthesis.

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              1 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.