On Mon, Jul 20, 2009 at 1:10 AM, aXqd<axqd...@gmail.com> wrote:
>
> On Mon, Jul 20, 2009 at 12:00 PM, Alex Gaynor<alex.gay...@gmail.com> wrote:
>>
>> On Sun, Jul 19, 2009 at 9:51 PM, aXqd<axqd...@gmail.com> wrote:
>>>
>>> Hi, all:
>>>
>>> I encountered another redundant SQL query problem while using django.
>>> And this time it might even cause a defect of my own program.
>>>
>>> Here is the thing. I want to do something like below:
>>> FOO.objects.filter( bar_id__exact = 5 ).delete()
>>>
>>> But what I got from mysql log are:
>>>
>>> 1 SELECT blahblahblah... FROM `foo` WHERE (`foo`.`bar_id` = 5 ) LIMIT 100
>>> 2 DELETE FROM `foo` WHERE `id` IN (7, 10, 13)
>>> 3 commit
>>> 4 SELECT blahblahblah... FROM `foo` WHERE (`foo`.`bar_id` = 5 ) LIMIT 100
>>>
>>> Questions are:
>>> 1. For Line 1, why it LIMITed the number of results to 100 while i'm
>>> hoping to delete them all?
>>> 2. For Line 1 and 2,  is there any way to do "DELETE FROM 'foo' WHERE
>>> ('foo'.'bar_id' = 5)"?
>>>    I think this is a quite common scenario.
>>> 3. For Line 4, is that a double check? Why would I need this query?
>>>
>>> I'm new to django, thanks for all your kind help.
>>>
>>> --
>>> Regards.
>>> -Tian
>>>
>>> >
>>>
>>
>> The reason for this is Django emulates DELETE ON CASCADE behavior,
>> which means doing some pure python processing.  However, I believe
>> that last SELECT query should be able to be optimized out, so I'm
>> going to look into removing it.
>>
>> Alex
>>
>> --
>> "I disapprove of what you say, but I will defend to the death your
>> right to say it." -- Voltaire
>> "The people's good is the highest law." -- Cicero
>> "Code can always be simpler than you think, but never as simple as you
>> want" -- Me
>>
>> >
>>
>
> Thanks, Alex.
>
> But even if I don't care about the performance,  can I be sure that
> the following clause will remove all the satisfied items? or just the
> first 100 ones?
>
> FOO.objects.filter( bar_id__exact = 5 ).delete()
>
>
> --
> Regards.
> -Tian
>
> >
>

Yes, it will remove all of them, it just chunks the deletes, to groups of 100.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your
right to say it." -- Voltaire
"The people's good is the highest law." -- Cicero
"Code can always be simpler than you think, but never as simple as you
want" -- Me

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

Reply via email to