#34845: Slow query when using exclude
-------------------------------------+-------------------------------------
Reporter: Amin Aminian | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution: duplicate
Keywords: exclude,filter | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Amin Aminian):
Replying to [comment:7 Simon Charette]:
> Amin, you haven't provided the full picture here.
>
> I'm not sure if you're using `FilteredRelation`, `extra`, or a third
party application that does so implicitly for you but the ORM won't insert
a `AND ("payment"."payable_type_id" = 30)` in the `JOIN` from a simple
Hi Simon,
You are right, I've not provided full detail.
My models is sth like this:
{{{
class Order(models.Model);
...
payment = GenericRelation(
"Payment",
related_query_name="payment",
object_id_field="payable_id",
content_type_field="payable_type",
)
class Payment(models.Model):
...
payable_type = models.ForeignKey(
ContentType, on_delete=models.PROTECT, verbose_name=_("payable
type")
)
payable_id = models.PositiveIntegerField(verbose_name=_("payable id"))
payable_object = GenericForeignKey("payable_type", "payable_id")
}}}
Also note that the ORM the I provided earlier, is not the full ORM,
because I don't know if I'm allowed to share that here or not (it's for
company).
The thing was that I had a slow query, which was taking about 15s, and
fixed that just by using `filter` instead of `exclude`, so I just provided
that section of the query.
--
Ticket URL: <https://code.djangoproject.com/ticket/34845#comment:9>
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/0107018aacb8e0ff-e778884d-32a4-4a55-8a9b-26373b6150b3-000000%40eu-central-1.amazonses.com.