Opened 15 years ago
Closed 14 years ago
#13067 closed (fixed)
make bulk-deletion lots faster
Reported by: | Carl Meyer | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Model._collect_sub_objects is called separately for every individual object-to-be-deleted, and so every relation is followed and queried once for every individual object. It is possible to condense those queries down to a single bulk query per related model, which should result in massive speedups for large bulk QuerySet deletions with related objects. Even single-object deletions will be significantly faster if they have a large number of related objects to be cascade-deleted that themselves have relations.
Alex Gaynor and I have been discussing implementation ideas, including how to do this without negatively impacting the fix for #6191.
Change History (3)
comment:1 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 15 years ago
comment:3 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
(In [14507]) Fixed #7539, #13067 -- Added on_delete argument to ForeignKey to control cascade behavior. Also refactored deletion for efficiency and code clarity. Many thanks to Johannes Dollinger and Michael Glassford for extensive work on the patch, and to Alex Gaynor, Russell Keith-Magee, and Jacob Kaplan-Moss for review.
My patch in #7539 does this.