Лучшая ачивка месяца
Found how to force MySQL to use the right index in django
Problem was that MySQL took the wrong index for the query and did it for 500ms instead of 1ms. Django query had .filter() for 3 fields and .order_by() for another 4th field. And best index was for that 4th field – content_published_desc. But MySQL consider only indexes with fields from .filter(), took some strange index, and made the query slow. So solution was to add fake .filter(published__gte='1970-01-01') and then MySQL got that best index – content_published_desc. My query is 0-1ms now.