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

sql_mode=ORACLE: ROWNUM is accepted in subquery, but ignored in subquery in WHERE clause

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.6.9
    • 10.6
    • None
    • None

    Description

       
      CREATE TABLE t1 (a INT);
      CREATE TABLE t2 (b INT);
       
      INSERT INTO t1 VALUES(1),(2),(3);
      INSERT INTO t2 VALUES(1),(2),(3);
       
      SET SQL_MODE=ORACLE;
      SELECT a FROM t1 WHERE a IN (SELECT b FROM t2 WHERE ROWNUM < 3);
      +------+
      | a    |
      +------+
      |    1 |
      |    2 |
      |    3 |
      +------+
      3 rows in set (0.000 sec)
      

      The result is wrong because:

      SELECT b FROM t2 WHERE ROWNUM < 3;
      +------+
      | b    |
      +------+
      |    1 |
      |    2 |
      +------+
      2 rows in set (0.001 sec)
      

      It works properly with derived table both with intended cartesian product and with ON clause:

      SELECT a, b FROM t1 JOIN (SELECT b FROM t2 WHERE ROWNUM < 3);
      +------+------+
      | a    | b    |
      +------+------+
      |    1 |    1 |
      |    1 |    2 |
      |    2 |    1 |
      |    2 |    2 |
      |    3 |    1 |
      |    3 |    2 |
      +------+------+
      6 rows in set (0.001 sec)
       
      SELECT a, b FROM t1 JOIN (SELECT b FROM t2 WHERE ROWNUM < 3) ON a = b;
      +------+------+
      | a    | b    |
      +------+------+
      |    1 |    1 |
      |    2 |    2 |
      +------+------+
      2 rows in set (0.001 sec)
      
      

      Attachments

        Activity

          People

            monty Michael Widenius
            salle Alexander Keremidarski
            Votes:
            1 Vote for this issue
            Watchers:
            3 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.