# Best perform: filtering using instance and instance.pk

**URL:** <https://forum.djangoproject.com/t/best-perform-filtering-using-instance-and-instance-pk/12099>\
**Category:** Using the ORM\
**Created:** [February 11, 2022, 5:54pm UTC](https://forum.djangoproject.com/t/best-perform-filtering-using-instance-and-instance-pk/12099 "2022-02-11T17:54:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcovelarde](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/marcovelarde/32/4087_2.png) [@marcovelarde](https://forum.djangoproject.com/u/marcovelarde)\
**Post date:** [February 11, 2022, 5:54pm UTC](https://forum.djangoproject.com/t/best-perform-filtering-using-instance-and-instance-pk/12099/1 "2022-02-11T17:54:41Z")

</div>

In these cases:

```py
qs = MyModel.objects.filter(user=user) #1

qs = MyModel.objects.filter(user_id=user.pk) #2

```

Both results in the same queryset using a sql query like to `WHERE "my_model"."user_id" = pk` but if you use `user=user` as filter, internally search for the instance pk taking a little longer than `user_id=user.pk`. Maybe the logic to make sql queries for relationships is different that i think but without that “pk searching” in the 1st filter, the 2nd is a little faster?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [February 11, 2022, 6:25pm UTC](https://forum.djangoproject.com/t/best-perform-filtering-using-instance-and-instance-pk/12099/2 "2022-02-11T18:25:00Z")

</div>

There’s not going to be a “search”, it’s an object-attribute retrieval - effectively a dictionary lookup - which is one of the most highly optimized parts of core Python.

There is not going to be any practical difference between the two - not compared to everything else that needs to occur at that time. Worrying about that difference is wasted effort.
