Hi Behzad

Your database will automatically use the appropriate indexes for given
queries, thanks to its optimizer. See
https://en.m.wikipedia.org/wiki/Query_optimization and DB specific docs
such as: https://www.postgresql.org/docs/9.0/planner-optimizer.html ,
https://dev.mysql.com/doc/internals/en/optimizer.html .

USE INDEX is only for forcing usage of particular indexes if you are *sure*
that you know better than your optimizer. You don't need it in 99% of
cases, it's a bit of a sledgehammer, and prone to bitrot into bad
performance if your tables change. However if you're sure you want to do
this, for MySQL/MariaDB, my library Django-MySQL adds a QuerySet extension
for it:
https://django-mysql.readthedocs.io/en/latest/queryset_extensions.html#django_mysql.models.use_index
. I've actually never ended up needing it myself.

Thanks,

Adam

On Wed, 20 Nov 2019 at 08:31, Behzad <behzad.bananmokht...@gmail.com> wrote:

> Hey all!
>
> I noticed a while ago that we can set indexes in the models Meta as
> described here
> <https://docs.djangoproject.com/en/2.2/ref/models/options/#indexes>. But
> I can't find any commands on the Queryset which helps us use the declared
> indexes, the equivalent of `USE INDEX` in the DB.
> Is this planned to be developed?
>
> Best
> Behzad
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/e95a9413-1c0f-48b2-ae25-5417c3a742e2%40googlegroups.com
> <https://groups.google.com/d/msgid/django-developers/e95a9413-1c0f-48b2-ae25-5417c3a742e2%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Adam

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAMyDDM3n9%2ByJNyXezcDuyv1m0WX5fLbUS4ZnTDMRAW7F3tHhkQ%40mail.gmail.com.

Reply via email to