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

Queries with subqueries containing UNION are not parsed

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Critical
    • Resolution: Fixed
    • 10.4
    • 10.4.9, 10.5.0
    • Parser
    • None

    Description

      The following query

      SELECT ((SELECT a FROM t1 LIMIT 2) UNION (SELECT a FROM t2 LIMIT 2) LIMIT 1) AS r FROM t1 AS t;
      

      returns syntax error message in 10.4:

      ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UNION (SELECT a FROM t2 LIMIT 2) LIMIT 1) AS r FROM t1 AS t' at line 1
      

      Reprodicible in with the following test case

      CREATE TABLE t1 (a int);
      INSERT INTO t1 VALUES(1),(2),(3),(4);
      CREATE TABLE t2 (a int);
      INSERT INTO t2 VALUES (4),(5),(6),(7);
      SELECT ((SELECT a FROM t1 LIMIT 2) UNION (SELECT a FROM t2 LIMIT 2) LIMIT 1) AS r FROM t1 AS t;
      

      10.3 and probably all prior versions return the same error message.
      MySQL-8.0 returns a proper result:

      mysql> SELECT ((SELECT a FROM t1 LIMIT 2) UNION (SELECT a FROM t2 LIMIT 2) LIMIT 1) AS r FROM t1 AS t;
      +------+
      | r    |
      +------+
      |    1 |
      |    1 |
      |    1 |
      |    1 |
      +------+
      

      This query with a subquery in the WHERE clause also failed to be parsed:

      MariaDB [test]> SELECT * FROM t1 WHERE t1.a IN ((SELECT a FROM t1) UNION (SELECT a FROM t2));
      ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UNION (SELECT a FROM t2))' at line 1
      

      10.3 returns the same error message.

      MySQL-8.0 is ok with the above query:

      mysql> SELECT * FROM t1 WHERE t1.a IN ((SELECT a FROM t1) UNION (SELECT a FROM t2));
      +------+
      | a    |
      +------+
      |    1 |
      |    2 |
      |    3 |
      |    4 |
      +------+
      

      Attachments

        Issue Links

          Activity

            People

              igor Igor Babaev
              igor Igor Babaev
              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.