On Wed, Feb 10, 2010 at 2:22 AM, Russell Keith-Magee <freakboy3...@gmail.com > wrote:
> 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? > > I can recreate with just simple shell queries and checking the sql in django.db.connection > * 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? > Every exists() query I tried shows this behavior. For example: >>> from django.contrib.auth.models import User >>> User.objects.filter(username='kmt').exists() True >>> from django.db import connection >>> connection.queries[-1] {'time': '0.001', 'sql': u'SELECT (1) AS `a`, `auth_user`.`id`, `auth_user`.`username`, `auth_user`.`first_name`, `auth_user`.`last_name`, `auth_user`.`email`, `auth_user`.`password`, `auth_user`.`is_staff`, `auth_user`.`is_active`, `auth_user`.`is_superuser`, `auth_user`.`last_login`, `auth_user`.`date_joined` FROM `auth_user` WHERE `auth_user`.`username` = kmt '} >>> > > * Are you doing anything interesting with select_related() or > anything like that? > > No. > * What version of Django (including SVN revision, if appropriate) are > you using? > I tried current trunk and backed off to the changeset where the function was added -- query was the same. Looking at the idiom it replaced, the extra select of the constant 1 value as 'a' was followed by a values('a') that turned the result into a ValuesQuerySet. I don't see where this is being done with the exists() implementation. As a result it seems to be a regular QuerySet with a query with default_cols=True, resulting in all the default columns getting pulled into the query. Karen -- 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.