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

(limit + offset) union all (...) limit = incorrect result

    XMLWordPrintable

Details

    Description

      【重现步骤】
      1、创建表 t1,插入数据

      create table t1(id int primary key auto_increment, c1 int) engine=innodb;
      insert into t1(c1) values(1),(2),(3);

      2、执行以下查询

      (select * from t1 where c1>=1 limit 2,1) union ALL (select * from t1 where c1>1 order by c1 desc);

      +----+------+
      | id | c1 |
      +----+------+
      | 3 | 3 |
      | 2 | 2 |
      | 3 | 3 |
      +----+------+

      3、加 limit ,检查结果

      (select * from t1 where c1>=1 limit 2,1) union ALL (select * from t1 where c1>1 order by c1 desc) limit 2;

      【预期结果】

      +----+------+
      | id | c1 |
      +----+------+
      | 3 | 3 |
      | 2 | 2 |
      +----+-----+

      【实际结果】

      Attachments

        Activity

          People

            serg Sergei Golubchik
            js niezhibiao
            Votes:
            0 Vote for this issue
            Watchers:
            4 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.