Setup:
Django 1.1.2, MySQL 5.1
Problem:
Blob.objects.filter(foo = foo) \
.filter(status = Blob.PLEASE_DELETE) \
.delete()
This snippet results in the ORM first generating a SELECT * from xxx_blob where ...
query, then doing a DELETE from xxx_blob where id in (BLAH);
where BLAH is a ridiculously long list of id's. Since I'm deleting a large amount of blobs, this makes both me and the DB very unhappy.
Is there a reason for this? I don't see why the ORM can't convert the above snippet into a single DELETE query. Is there a way to optimize this without resorting to raw SQL?
bulk_delete
, isn't it? Why is it not done? Any high level reasons? And those who usebulk_create
is well aware that signals won't work. May be just for cascade delete? – Reggie