Skip to content

Commit fe33fdc

Browse files
MisterRiosfelixxm
authored andcommitted
Refs #30656 -- Reorganized bulk methods in the database optimization docs.
1 parent 3c6d32e commit fe33fdc

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

docs/topics/db/optimization.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,13 @@ it on a ``QuerySet`` by calling
341341

342342
Adding an index to your database may help to improve ordering performance.
343343

344-
Insert in bulk
345-
==============
344+
Use bulk methods
345+
================
346+
347+
Use bulk methods to reduce the number of SQL statements.
348+
349+
Create in bulk
350+
--------------
346351

347352
When creating objects, where possible, use the
348353
:meth:`~django.db.models.query.QuerySet.bulk_create()` method to reduce the
@@ -362,8 +367,13 @@ Note that there are a number of :meth:`caveats to this method
362367
<django.db.models.query.QuerySet.bulk_create>`, so make sure it's appropriate
363368
for your use case.
364369

365-
This also applies to :class:`ManyToManyFields
366-
<django.db.models.ManyToManyField>`, so doing::
370+
Insert in bulk
371+
--------------
372+
373+
When inserting objects into :class:`ManyToManyFields
374+
<django.db.models.ManyToManyField>`, use
375+
:meth:`~django.db.models.fields.related.RelatedManager.add` with multiple
376+
objects to reduce the number of SQL queries. For example::
367377

368378
my_band.members.add(me, my_friend)
369379

0 commit comments

Comments
 (0)