Django Query Performance Filtering Vs Foreign Key Set Lookup

Viewed 687

I'm wondering which, if either, query is faster in Django. I have a Location model and a User model. Users are foreign keyed to Locations, so each Location can have a 'locationuser_set' attribute.

Which, if either, is faster if I have thousands of Users?

Query 1:

location = Location.objects.get(id=<id>)
users = location.user_set.all()

Query 2:

users = User.objects.filter(location_id=<id>)
1 Answers
Related