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

incorrect result order when reusing aliases

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 5.3.12, 10.1, 10.0, 5.5
    • Fix Version/s: 10.1, 10.0
    • Component/s: None
    • Labels:

      Description

      DROP TABLE IF EXISTS `foobar`;
      CREATE  TABLE IF NOT EXISTS `foobar` (
        `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
        `name` VARCHAR(45) NULL )
      ENGINE = InnoDB;
      
      INSERT INTO `foobar` (`name`) VALUES ('A');
      INSERT INTO `foobar` (`name`) VALUES ('B');
      INSERT INTO `foobar` (`name`) VALUES ('C');
      INSERT INTO `foobar` (`name`) VALUES ('D');
      INSERT INTO `foobar` (`name`) VALUES ('E');
      
      SELECT
        `SubQuery`.`Static` AS `Random`,
        `SubQuery`.`Name`
      FROM (
        SELECT
          RAND() AS `Random`,
          1 AS `Static`,
          `Name`
        FROM `foobar`
        ) AS `SubQuery`
      ORDER BY
      `SubQuery`.`Random`,
      `SubQuery`.`Name`;
      

      When executing in MySQL the result is sorted correctly at random. In MariaDB the result is incorrectly sorted alphabetically by name. When renaming the first alias (`SubQuery`.`Static` AS `Random`) to `Random2`, the sorting is correct in MariaDB, too.

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            elenst Elena Stepanova added a comment -

            Thanks for the report. As a workaround, you can try setting optimizer_switch=derived_merge=off.

            Show
            elenst Elena Stepanova added a comment - Thanks for the report. As a workaround, you can try setting optimizer_switch=derived_merge=off .

              People

              • Assignee:
                sanja Oleksandr Byelkin
                Reporter:
                hanswurst Hans Wurst
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: