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

Strange error with Large Join Query #3016

Closed
VinaiRachakonda opened this issue Mar 16, 2022 · 5 comments · Fixed by dolthub/go-mysql-server#1352
Closed

Strange error with Large Join Query #3016

VinaiRachakonda opened this issue Mar 16, 2022 · 5 comments · Fixed by dolthub/go-mysql-server#1352
Assignees
Labels
bug Something isn't working ORM Issue caused from ORM usage

Comments

@VinaiRachakonda
Copy link
Contributor

Consider the following dump

SET FOREIGN_KEY_CHECKS = 0;
SET AUTOCOMMIT = 0;
DROP TABLE IF EXISTS `tweet`;
CREATE TABLE `tweet` (
  `id` int NOT NULL AUTO_INCREMENT,
  `user_id` int NOT NULL,
  `content` text NOT NULL,
  `timestamp` bigint NOT NULL,
  PRIMARY KEY (`id`),
  KEY `tweet_user_id` (`user_id`),
  CONSTRAINT `0qpfesgd` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `tweet` (`id`,`user_id`,`content`,`timestamp`) VALUES (1,1,'meow',1647463727);
INSERT INTO `tweet` (`id`,`user_id`,`content`,`timestamp`) VALUES (2,1,'purr',1647463727);
INSERT INTO `tweet` (`id`,`user_id`,`content`,`timestamp`) VALUES (3,2,'hiss',1647463727);
INSERT INTO `tweet` (`id`,`user_id`,`content`,`timestamp`) VALUES (4,3,'woof',1647463727);
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
  `id` int NOT NULL AUTO_INCREMENT,
  `username` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `users` (`id`,`username`) VALUES (1,'huey');
INSERT INTO `users` (`id`,`username`) VALUES (2,'zaizee');
INSERT INTO `users` (`id`,`username`) VALUES (3,'mickey');

Consider the following query:

 SELECT `t1`.`username`, COUNT(`t1`.`id`) AS `ct` FROM ((SELECT `t2`.`id`, `t2`.`content`, `t3`.`username` FROM `tweet` AS `t2` INNER JOIN `users` AS `t3` ON (`t2`.`user_id` = `t3`.`id`) WHERE (`t3`.`username` = 'u3')) UNION (SELECT `t4`.`id`, `t4`.`content`, `t5`.`username` FROM `tweet` AS `t4` INNER JOIN `users` AS `t5` ON (`t4`.`user_id` = `t5`.`id`) WHERE (`t5`.`username` IN ('u2', 'u4')))) AS `t1` GROUP BY `t1`.`username` ORDER BY COUNT(`t1`.`id`) DESC;

Dolt returns the following error

unable to push plan.Sort node below *plan.Union
@VinaiRachakonda VinaiRachakonda added bug Something isn't working ORM Issue caused from ORM usage labels Mar 16, 2022
@VinaiRachakonda
Copy link
Contributor Author

This blocks the Peewee ORM integration

@VinaiRachakonda
Copy link
Contributor Author

Skipped enginetest here

@max-hoffman
Copy link
Contributor

The union error is fixed, now blocked on an aliasing issue:

column "COUNT(t1.id)" could not be found in any table in scope

The error resolves if I manually convert COUNT(t1.id) -> ct

@timsehn
Copy link
Contributor

timsehn commented Sep 29, 2022

@fulghum one for your test suite.

@fulghum fulghum self-assigned this Sep 29, 2022
@fulghum
Copy link
Contributor

fulghum commented Oct 17, 2022

I debugged through this one on Friday and have a prototype of a fix coded up. The fix is in pushdownSort – since the sort expression is the same as an expression projected by the child, we can leave the sort node where it is and not push it down, which lets the query execute correctly. I need to clean up my tests and think through the edge cases, and will get a PR up today for this one.

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

Successfully merging a pull request may close this issue.

4 participants