I'm also +1 __nonezero__ -1 .exists(). Using .count() already gives us
the required functionality and makes logical sense, the only question
then is how big of a performance gain do we get by using SELECT 1
LIMIT 1.

SELECT 1 FROM [table] LIMIT 1 also feels kinda hackish to me, and I'm
guessing it's likely not supported in all database engines used by
Django and/or is not the most efficient statement in all supported
engines, in which case .exists() would only become a performance
workaround for some engines and either using .count() or simply
having .exists() as an alias to .count() for those engines where
count(*) or count(pk) is most efficient.

I'd rather petition the PostgreSQL developers to optimise count(*) and
suggest Django users implement their own changes or workaround in the
meantime if they're working with large datasets where count(*) is a
serious performance penalty.

I like Malcom's idea of just checking the first value in a queryset to
save a second SQL statement, but I'm not sure it would be appropriate
in all cases. There may be times when people *just* want to check if
records exist, without actually selecting or iterating through
records. In those cases wouldn't it be more efficient to do a
single .count() than selecting all your records and only returning the
first one?


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

Reply via email to