We need to pull out the ids since deletes can occur across multiple
tables in various situations. We only do deletes in chunks since there
are maximum lengths of SQL queries. 100 isn't a bad number. If you're
needing to do tens of thousands of deletes regularly, use raw SQL.
[...]
> I think some optimization is needed,
We take patches. :-)
Just make sure the changes have a chance of working on all our database
backends.
Seriously, I'm a little surprised your database is only able to do less
than 2.5 queries per second. Be that as it may, if you're needing to do
mass deletes, do them directly. Django is never intended to be a
complete replacement for SQL and typical "delete" usage for a web
framework is a record or two, not thousands and thousands. Although it
should still be able to handle the latter case comfortably (I just
tested a 10,000 object delete and it only took a few minutes) unless
your models are quite complicated or there are lots and lots of indexes
to update or something. In other words, there are going to be
circumstance-specific exceptions, so testing and profiling is a good
idea. If this is a big problem for you, by all means look at what
changes might be possible. The code in question is in
django/db/models/base.py and django/db/models/query.py. It's a little
complex, but not horribly scary.
Regards,
Malcolm
Well, like I said, we take patches. All contributions to Django come
from volunteers who want to solve a particular problem. I'm not going to
drop the few dozen things I'm working on to do this particular thing,
because it simply isn't high enough priority for me. If it's high
priority for you, by all means, go for it. There are no problems we
aren't interested in having solutions for. There are problems that are
much lower priority than others, though.
Malcolm