#34262: Queryset grouped by annotation with aggregates on another annotated
expression crashes on MySQL with sql_mode=only_full_group_by.
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: mysql | Triage Stage: Accepted
only_full_group_by |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Amir Karimi):
Replying to [comment:4 Simon Charette]:
> Thanks for the analysis David, option 1. and 2. were also the conclusion
of [https://github.com/django/django/pull/16460#discussion_r1071497499 my
limited investigation on the subject] so it's great to have cross peer
validation on the subject.
>
> I think there might be a way to implement 3. by reusing
[https://github.com/django/django/blob/d3c93cdc597e0efc2815111c04dd5a427432ed37/django/db/models/sql/compiler.py#L669-L680
some of the logic used to implement masking of columns when filtering
against window functions] which requires two level of subquery wrapping.
>
> A different of approaching 3. is to think that any form of ''masking''
of annotations/aliases used for grouping purposes would result in a
subquery pushdown. So to reuse your example, instead of performing a
subquery pushdown to compute expressions used with aggregate queries we'd
do it the other way around to have MySQL group against top level `SELECT`
expressions which it's good at inferring dependencies from
>
> {{{#!sql
> SELECT LEAST(min_pages, greatest_pages) AS `least` FROM (
> SELECT
> GREATEST(`aggregation_book`.`pages`, 600) greatest_pages,
> MIN(`aggregation_book`.`pages`) min_pages
> FROM `aggregation_book`
> GROUP BY 1 ORDER BY NULL
> ) masked
> }}}
>
> This should reduce the area of impact of this change to aggregating
queries that group against a value that isn't explicitly selected and
would also happen to solve the last remaining known issue with using
server-side parameters binding for Postgres (#34255).
I'm curios to know what happened with this issue. Any updates?
--
Ticket URL: <https://code.djangoproject.com/ticket/34262#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018954ec968d-d02aff38-0f76-49df-a6fd-987e1495873d-000000%40eu-central-1.amazonses.com.