Why Does Django ORM Take Longer Than Simple SQL for Data Fetching?

Facing slow data fetching times in my Django application deployed on a server. With 350 records in my MySQL database, using ORM (Entity.objects.all().order_by(‘-entity_id’)) takes 3 times longer than a raw SQL query (1.25 sec). Even after indexing the database, the issue persists. Seeking advice on optimizing performance.

Welcome @harshitrai !

The difference between the two is that Django is creating object instances for each row with possible datatype conversions for individual fields (e.g. datetime fields). If you don’t need the data as objects, you can use either .values() or .values_list().

For more information on this and other performance-related ideas, see Database access optimization | Django documentation | Django, and in the more general case, Performance and optimization | Django documentation | Django

Thanks
i used search_related that’s reduces time