Solving the select+1 problem.

88 views
Skip to first unread message

Jonathan Slenders

unread,
Jun 11, 2014, 7:15:01 AM6/11/14
to django-d...@googlegroups.com
The "select+1" problem is a problem that people often face in Django.
Usually, something like select_related solves it, but I don't think that's always possible.

Facebook released Haxl today and there's an example of their apprach to the problem.

I don't know enough Haskel to understand this code, but it could contain some very nice ideas that apply to our ORM as well.

Cheers,
Jonathan

Jacob Kaplan-Moss

unread,
Jun 11, 2014, 9:38:14 AM6/11/14
to django-developers
I'm not great at Haskell, either, but this looks to me to be very similar to prefetch_related (https://docs.djangoproject.com/en/dev/ref/models/querysets/#prefetch-related).

Jacob


--
You received this message because you are subscribed to the Google Groups "Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/f81a5db1-9777-4cd0-98b7-25b0bc44f498%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alex Gaynor

unread,
Jun 11, 2014, 10:36:45 AM6/11/14
to django-d...@googlegroups.com
I also do not really know Haskell (I'm sensing a trend...), that said, it seems to me the cool part of haxl is that it can be automatic -- analagous to if writing {{ post.author.name }} in a template caused select_related("author") to automatically be applied to the queryset that yielded post.

Alex



For more options, visit https://groups.google.com/d/optout.



--
"I disapprove of what you say, but I will defend to the death your right to say it." -- Evelyn Beatrice Hall (summarizing Voltaire)
"The people's good is the highest law." -- Cicero
GPG Key fingerprint: 125F 5C67 DFE9 4084

Stratos Moros

unread,
Jun 11, 2014, 11:12:36 AM6/11/14
to django-d...@googlegroups.com
Given their sample code, my initial impression was that it was indeed
automatic. Looking a bit closer, there seems to be hardcoded logic
inside the DataSource (the thing I'm assuming provides getAllUserIds and
getUsernameById) to specifically fetch all ids and then all names for
those ids. So they're still doing a manual prefetch_related equivalent
but at a different abstraction level.

I should note that my Haskell knowledge is also minimal, so it is quite
possible that I'm misunderstanding something.
>>> <https://groups.google.com/d/msgid/django-developers/f81a5db1-9777-4cd0-98b7-25b0bc44f498%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups
>> "Django developers" group.
>> To unsubscribe from this group and stop receiving emails from it,
>> send an
>> email to django-develop...@googlegroups.com.
>> To post to this group, send email to
>> django-d...@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-developers.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-developers/CAK8PqJFJoOXVbOX7C7NmhToVsEizD2ZvWCS1vv_LZpfdRv2ayg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-developers/CAK8PqJFJoOXVbOX7C7NmhToVsEizD2ZvWCS1vv_LZpfdRv2ayg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> "I disapprove of what you say, but I will defend to the death your
> right to
> say it." -- Evelyn Beatrice Hall (summarizing Voltaire)
> "The people's good is the highest law." -- Cicero
> GPG Key fingerprint: 125F 5C67 DFE9 4084
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django developers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-develop...@googlegroups.com.
> To post to this group, send email to
> django-d...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-developers.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/CAFRnB2UAGp%2BWPJHm_oq9WLFv5yTvtVT5%3Drs6E46WinL49Q%2B1wA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages