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
Only group by if using having clauses #1750
Conversation
How sure are you that every query which is affected by this change is using |
Well, just tested it: SELECT DISTINCT id, performer_id FROM scenes INNER JOIN performers_scenes ON performers_scenes.scene_id = scenes.id GROUP BY id; This does return a single row per (scene) id containing a random performer_id (for that scene). While a compliant DB would result in an error stating that When dropping the |
As far as I could tell, |
👍 When I'm at my development computer I'll try to verify that as well so that two people confirmed it's the case. |
Should we perhaps add a comment to one of these now indicating that DISTINCT is a hard requirement? |
Just wondering. IIRC the "includes all" modifier for the multi / hierarchical criterion does add a |
Found an issue, which might show up in multiple areas. Applying "Image Count" sorting on the tags page results in a SQL error:
Obviously meaning the Note I did use "Image Count" sorting on the performers page already which did work fine. So it seems to depend on "something else" which does add the group by then, or it uses So I guess there needs to be some other means to indicate to the query (builder) that the Edit: |
So: So that leaves the issue of aggregates being used (in other words, at least the issue with the "* count" sorting on the /tags page). |
I've changed the tag sorting code to be consistent with the other sorting code. This eliminates the necessity of using I've also added integration tests exercising the sorting code.. |
Only group by ids if
having
is used in the query. This results in significant performance improvement on the images query, since it potentially eliminates a table scan. On a contrived database with 4m images, it results in 200ms for the query, down from 4 seconds for a page size of 40.