#24044: filtering by annotation executes sql function twice
-------------------------------------+-------------------------------------
Reporter: Tim-Erwin | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: annotate filter | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by jarshwah):
Referring to aliases in the having clause is only supported by MySQL, and
only if the ONLY_FULL_GROUP_BY option is not enabled (so it's supported by
default). It is not standard SQL.
To support the SQL syntax of referring to aliases, Django would have to
detect (or document) whether or not ONLY_FULL_GROUP_BY is active, and then
only generate this kind of SQL for MySQL backend with ONLY_FULL_GROUP_BY
disabled.
Are you sure that there is a performance difference between using the
alias or using the function again? I would be extremely surprised if the
query with the alias wasn't rewritten by the query optimiser to the
standard structure anyway. I'm finding it very difficult to determine
whether or not there is a performance difference without doing some tests
- google-fu isn't turning anything up.
If we can determine a performance difference, then this ticket will be
worth following up. If there is no performance difference though, we
should close as wontfix, because the style of SQL used shouldn't matter in
this case.
Tim-Erwin, are you able to share any concrete performance figures or
execution plans?
--
Ticket URL: <https://code.djangoproject.com/ticket/24044#comment:2>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.65a0cc7779b360e28278c27d93671d5e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.