On 7/14/07, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > On Fri, 2007-07-13 at 16:22 -0500, Adrian Holovaty wrote: > > I'd like to add a QuerySet.exists() method, which would return True or > > False if the given QuerySet contains at least one record. This would > > be more efficient than qs.count() or len(qs) because it would perform > > the following SQL under the hood: > > > > SELECT 1 FROM [table] WHERE [where] LIMIT 1; > > Due to Oracle inclusion, this has to be > > select count(*) from [table] where [...]
How about SELECT 1 FROM DUAL WHERE EXISTS ( SELECT 1 FROM [table] WHERE [where] ); for oracle? it is definitely better then requiring Oracle to count all the rows. > > and then check that the result is > 0, at least in the Oracle backend > (no "limit" extension in Oracle). The problem being that count(*) is not > an optimised operation in PostgreSQL, however, we haven't yet split up > those cases in a lot of the code (the recent Oracle merge moved a bunch > of similar things to the count(*) case and I keep meaning to look at > whether we can move them all to count(id_col), which is faster). > -- Honza Král E-Mail: [EMAIL PROTECTED] ICQ#: 107471613 Phone: +420 606 678585 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---