#34811: Queryset filter Q order changed
-------------------------------------+-------------------------------------
Reporter: Edward Villegas- | Owner: nobody
Pulgarin |
Type: Bug | Status: closed
Component: Database layer | Version: 4.2
(models, ORM) | Resolution:
Severity: Normal | worksforme
Keywords: filter, Q | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):
If that can be of any help, we've observed that MySQL's query planer is
can be pretty bad at using composite indexes when `OR` conditions are
involved and had to resort to using `UNION` to target them.
Re-writing your lookup to move the `filling_id=pk` outside of the `OR`
should help MySQL at figuring out that the `filing_id` index can be used
at least.
{{{#!python
TaxInput.objects.filter(
filling_id=pk,
Q(updated_at__gt=last_engine.created_at) |
Q(deleted__gt=last_engine.created_at)
)
}}}
{{{#!sql
SELECT
*
FROM
`taxobjects_taxinput`
WHERE
`taxobjects_taxinput` . `filling_id` = ?
AND (
`taxobjects_taxinput` . `updated_at` > ?
OR `taxobjects_taxinput` . `deleted` > ?
)
LIMIT
?
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34811#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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018a58c428ff-37e250cd-a9f8-4df3-bb88-616f0d1c1854-000000%40eu-central-1.amazonses.com.