Queryset.explain() in Django


Django tip:

If you want to know how the database would execute a given query, you can use explain().

Knowing this can be helpful when you're trying to improve the performance of slow queries.

>>> print(Payment.objects.filter(created_at__gt=datetime.date(2021, 1, 1)).explain())

Seq Scan on payments_payment  (cost=0.00..14.25 rows=113 width=212)
    Filter: (created_at > '2021-01-01 00:00:00+00'::timestamp with time zone)