Django version 1.2 alpha 1 SVN-12267

I'm not using select_related at all anywhere at the moment, I just
started database optimization. David's server is just a wrapper
django-toolbar-like and doesn't perform anything smart on the sql or
the like.

I haven't yet tested on a vanilla setup, but I suppose something like
this should do the trick:

Class MyModel(Model):
    field_1 = IntegerField()
    field_2 = IntegerField()
    field_3 = IntegerField()
    field_4 = IntegerField()
    field_5 = IntegerField()

class OtherModel(Model):
    my_m2m = ForeignKey(MyModel, related_name="my_relation")

>>> MyModel.objects.all()[:1][0].my_relation.exists()


J. Leclanche / Adys



On Wed, Feb 10, 2010 at 9:22 AM, Russell Keith-Magee
<freakboy3...@gmail.com> wrote:
> On Wed, Feb 10, 2010 at 3:11 PM, Jerome Leclanche <adys...@gmail.com> wrote:
>> Hi list
>>
>> Using David Cramer's really nice replacement devserver
>> (http://github.com/dcramer/django-devserver), I noticed a bunch of
>> huge queries in some table generation code. Example:
>> http://dpaste.com/156907/
>> This is from one of my smallest tables, bigger ones with 120+ish rows
>> can take multiple ms to query.
>>
>> I narrowed it down to a SomeModel.some_reverse_foreignkey.exists().
>> Using something as simple as .only("id").exists() will make the query
>> several dozen times faster.
>>
>> Is this a bug, or am I missing something in exists() behaviour? From
>> what I understood, it's supposed to be faster than count() in
>> situations where I just need to know whether there are rows present.
>
> It certainly doesn't look right; .exists() should be faster than
> .count(), and having all the extra columns in the query looks a little
> weird.
>
> However, to say for sure, we need a few more details:
>
>  * Does this only happen when using David's devserver, or does it
> happen in a normal Django shell?
>
>  * Can you give a *specific* example of a model and query that is
> causing this? Or, if it's happening in the process of running a
> management command or other Django-internal activity, what do you need
> to do to stimulate the problem?
>
>  * Are you doing anything interesting with select_related() or
> anything like that?
>
>  * What version of Django (including SVN revision, if appropriate) are
> you using?
>
> Yours,
> Russ Magee %-)
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django developers" group.
> To post to this group, send email to django-develop...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-developers+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-developers?hl=en.
>
>

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

Reply via email to