Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UNION does not respect ORDER BY or LIMIT #3020

Closed
VinaiRachakonda opened this issue Mar 17, 2022 · 4 comments
Closed

UNION does not respect ORDER BY or LIMIT #3020

VinaiRachakonda opened this issue Mar 17, 2022 · 4 comments
Labels
bug Something isn't working ORM Issue caused from ORM usage

Comments

@VinaiRachakonda
Copy link
Contributor

Consider the following setup:

DROP TABLE IF EXISTS `c_file`;
CREATE TABLE `c_file` (
  `filename` varchar(255) NOT NULL,
  `data` text NOT NULL,
  `timestamp` bigint NOT NULL,
  PRIMARY KEY (`filename`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `c_file` (`filename`,`data`,`timestamp`) VALUES ('huey.txt','huey task queue',1515225600);
INSERT INTO `c_file` (`filename`,`data`,`timestamp`) VALUES ('peewee.txt','peewee orm',1515052800);
INSERT INTO `c_file` (`filename`,`data`,`timestamp`) VALUES ('walrus.txt','walrus redis toolkit',1515139200);
DROP TABLE IF EXISTS `c_note`;
CREATE TABLE `c_note` (
  `id` int NOT NULL AUTO_INCREMENT,
  `content` text NOT NULL,
  `timestamp` bigint NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `c_note` (`id`,`content`,`timestamp`) VALUES (1,'note-a',1514793600);
INSERT INTO `c_note` (`id`,`content`,`timestamp`) VALUES (2,'note-b',1514880000);
INSERT INTO `c_note` (`id`,`content`,`timestamp`) VALUES (3,'note-c',1514966400);

Consider the following query

 (SELECT `t1`.`content`, `t1`.`timestamp` FROM `c_note` AS `t1`) UNION (SELECT `t2`.`filename`, `t2`.`timestamp` FROM `c_file` AS `t2`) ORDER BY timestamp DESC LIMIT 4;

Dolt incorrectly returns

+------------+------------+
| content    | timestamp  |
+------------+------------+
| note-a     | 1514793600 |
| note-b     | 1514880000 |
| note-c     | 1514966400 |
| huey.txt   | 1515225600 |
| peewee.txt | 1515052800 |
| walrus.txt | 1515139200 |
+------------+------------+

Mysql correctly returns

+------------+------------+
| content    | timestamp  |
+------------+------------+
| huey.txt   | 1515225600 |
| walrus.txt | 1515139200 |
| peewee.txt | 1515052800 |
| note-c     | 1514966400 |
+------------+------------+
@VinaiRachakonda VinaiRachakonda added ORM Issue caused from ORM usage feature bug Something isn't working and removed feature labels Mar 17, 2022
@VinaiRachakonda
Copy link
Contributor Author

This currently blocks the Peewee ORM

@VinaiRachakonda
Copy link
Contributor Author

Skipped enginetest here

@reltuk
Copy link
Contributor

reltuk commented Aug 8, 2022

Going to iterate here: dolthub/go-mysql-server#1169

@timsehn
Copy link
Sponsor Contributor

timsehn commented Oct 4, 2022

Looks like @reltuk fixed this and did not resolve.

@timsehn timsehn closed this as completed Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ORM Issue caused from ORM usage
Projects
None yet
Development

No branches or pull requests

3 participants