Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Jan. 22, 2011 13:38:52

Miguel A.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

weird behavior in select_related


Hi everyone,

I have been working on reducing DB queries in my project with great results.
But I have realized that select_related in one of my models doesn't preload
all the ForeignKeys and OneToOneFields, it preloads 3 out of 5. Actually the
3 preloaded are ForeignKeys and the other 2 are OneToOneFields. Before
trying to reproduce this problem in a simplified schema, I need someone to
confirm this is unusual.

If I do a select_related('names', 'of', 'the', 'five', 'fks') everything is
loaded. Last thing I can say is that those OneToOneFields point models that
reference back to model pointing at them, for performance reasons. I reckon
this can be a bug.

Thanks, best regards

----
Miguel Araujo
@maraujop

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 28, 2011 17:02:10

Miguel A.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

weird behavior in select_related


Hi,

Please anyone confirm if this is normal, so I can report it or not.

Thanks, regards

----
Miguel Araujo
@maraujop

2011/1/22 Miguel Araujo <muchoch...@gmail.com>

> Hi everyone,
>
> I have been working on reducing DB queries in my project with great
> results. But I have realized that select_related in one of my models doesn't
> preload all the ForeignKeys and OneToOneFields, it preloads 3 out of 5.
> Actually the 3 preloaded are ForeignKeys and the other 2 are OneToOneFields.
> Before trying to reproduce this problem in a simplified schema, I need
> someone to confirm this is unusual.
>
> If I do a select_related('names', 'of', 'the', 'five', 'fks') everything is
> loaded. Last thing I can say is that those OneToOneFields point models that
> reference back to model pointing at them, for performance reasons. I reckon
> this can be a bug.
>
> Thanks, best regards
>
> ----
> Miguel Araujo
> @maraujop
>

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Jan. 28, 2011 17:16:36

Daniel R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

weird behavior in select_related


On Saturday, January 22, 2011 1:38:22 PM UTC, maraujop wrote:
>
> Hi everyone,
>
> I have been working on reducing DB queries in my project with great
> results. But I have realized that select_related in one of my models doesn't
> preload all the ForeignKeys and OneToOneFields, it preloads 3 out of 5.
> Actually the 3 preloaded are ForeignKeys and the other 2 are OneToOneFields.
> Before trying to reproduce this problem in a simplified schema, I need
> someone to confirm this is unusual.
>
> If I do a select_related('names', 'of', 'the', 'five', 'fks') everything is
> loaded. Last thing I can say is that those OneToOneFields point models that
> reference back to model pointing at them, for performance reasons. I reckon
> this can be a bug.
>
> Thanks, best regards
>
> ----
> Miguel Araujo
> @maraujop
>

It would have helped if you'd posted your model. If your relationships are
defined as null=True, then select_related() doesn't follow them unless you
specify them explicitly.
--
DR.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 Jan. 30, 2011 10:27:50

Miguel A.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

weird behavior in select_related


I didn't know that, that's why it was happening. I didn't post my models, as
I wasn't sure that would help.

Thanks for your help Daniel,

----
Miguel Araujo
@maraujop

2011/1/28 Daniel Roseman <dan...@roseman.org.uk>

> On Saturday, January 22, 2011 1:38:22 PM UTC, maraujop wrote:
>>
>> Hi everyone,
>>
>> I have been working on reducing DB queries in my project with great
>> results. But I have realized that select_related in one of my models doesn't
>> preload all the ForeignKeys and OneToOneFields, it preloads 3 out of 5.
>> Actually the 3 preloaded are ForeignKeys and the other 2 are OneToOneFields.
>> Before trying to reproduce this problem in a simplified schema, I need
>> someone to confirm this is unusual.
>>
>> If I do a select_related('names', 'of', 'the', 'five', 'fks') everything
>> is loaded. Last thing I can say is that those OneToOneFields point models
>> that reference back to model pointing at them, for performance reasons. I
>> reckon this can be a bug.
>>
>> Thanks, best regards
>>
>> ----
>> Miguel Araujo
>> @maraujop
>>
>
> It would have helped if you'd posted your model. If your relationships are
> defined as null=True, then select_related() doesn't follow them unless you
> specify them explicitly.
> --
> DR.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#5 Jan. 30, 2011 11:03:03

Ramiro M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

weird behavior in select_related


On Sun, Jan 30, 2011 at 7:27 AM, Miguel Araujo <muchoch...@gmail.com> wrote:
> I didn't know that, that's why it was happening. I didn't post my models, as
> I wasn't sure that would help.

Btw, it's documented behavior:http://docs.djangoproject.com/en/1.2/ref/models/querysets/#select-related--
Ramiro Morales

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 12th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support