[Fixed]-In terms of performance, which one is better modifying queryset or writing SQL through managers in django?

1πŸ‘

βœ…

I’d imagine its the first one – but this isn’t a fair contest.

Your second pure sql statement also has to do a grouping and an ordering which your first does not so the first is just a WHERE.

The reason it could be the second is because the first gets * rather than just the 3 items you need so you may be better off with the following:

super(DahlBookManager, self).get_queryset().filter(author='Roald Dahl').values('id',
                                                                               'question',
                                                                               'poll_date')

Now this may just be my opinion but for most queries you do in django you should use django and avoid raw queries. It will help you if you ever decide to use a different database schema and potentially create more efficient queries.

πŸ‘€Sayse

Leave a comment