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
sortBy and take/drop resulting in wrong SQL #1160
Comments
does it produce different results? what is the sub query? |
Currently the Query that will be generated is:
The result is correct it's just that the Query is way slower due to the subquery.. |
That's a known issue when using Slick with MySQL. Neither Slicks nor MySQL's optimizers currently optimize this away. Works well with other dbs AFAIK. Slick 3.1 will come with an improved optimizer that produces the SQL you expected. |
"wrong" isn't really the case by the way. the produced query is semantically correct. SQL doesn't have execution semantics in the language, that's for the database to decide. The MySQL optimizer however didn't chose a good execution plan for this case and it is indeed possible to affect that by changing the structure of the query. but that is db and optimizer dependent and could even depend on runtime profiling data. |
Good that I use PostgreSQL and still having a wrong query. |
whats the performance difference? |
I guess we disagree on the definition of semantics :). Anyways fixed in upcoming 3.1 or should already be in recent builds from master if I am not mistaken |
Hello when running a sortBy(_.id.desc).take(1) the resulting sql will be totally wrong.
It will be a SELECT columns FROM (SUBQUERY) instead of the wished SELECT columns FROM table ORDER BY x LIMIT 1;
The text was updated successfully, but these errors were encountered: