﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
11082	exclude subquery executed twice	handrews	nobody	"  When excluding using a subquery, I'm seeing the subquery being 
executed first as its own query, then seeing the correct query being 
run, including the subquery.  Using filter instead of exclude, this 
does not happen.

Here's what I mean (Select fields edited out of the MySQL log for 
readability- connection 374 is from the Python prompt, 332 is me 
poking at the mysql command line in another window to make sure I 
don't confuse which queries go with which python statements).  Version 
and platform info follows:
{{{
>>> baz=Publisher.objects.all() 
>>> for s in Series.objects.filter(publisher__in=baz): 

...   pass 
... 
>>> for s in Series.objects.exclude(publisher__in=baz): 

...   pass 
... 
}}}
{{{
090509 19:30:22     332 Query       select count(*) from core_issue 
090509 19:30:28     374 Query       SELECT * FROM `core_series` WHERE `core_series`.`publisher_id` IN (SELECT U0.`id` FROM `core_publisher` U0) ORDER BY `core_series`.`name` ASC, `core_series`.`year_began` ASC 
090509 19:30:41     332 Query       select count(*) from core_issue 
090509 19:30:54     374 Query       SELECT * FROM `core_publisher` ORDER BY `core_publisher`.`name` ASC 
090509 19:30:55     374 Query       SELECT * FROM `core_series` WHERE NOT (`core_series`.`publisher_id` IN (SELECT U0.`id` FROM `core_publisher` U0)) ORDER BY `core_series`.`name` ASC, `core_series`.`year_began` ASC 
}}}
Version stuff: 
Django 1.1 beta 1 
Mac OS X 10.4.11 
MySQL 5.0.45 
Python 2.4.4 
MySQLdb 1.2.1_p2 

I checked on django-users first, where Alex Gaynor suggested that the issue is here:
http://code.djangoproject.com/browser/django/trunk/django/db/models/sql/query.py#L1622

"		new	Database layer (models, ORM)	SVN					Accepted	0	0	0	0	0	0
