diff options
| author | daniel a rios <misterrios@gmail.com> | 2019-07-26 15:11:48 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-07-29 10:09:53 +0200 |
| commit | b4139ed6eaa430874360a3a98e85bd2c91e19bc7 (patch) | |
| tree | b17dee7b8665acc96d7969664b5433abd9673ea2 /docs/topics/db/optimization.txt | |
| parent | ea57c8a345c73d17d5ac3a504d8f1c1bd47a7572 (diff) | |
[2.2.x] Refs #30656 -- Reorganized bulk methods in the database optimization docs.
Backport of fe33fdc049df75f9dd8e2eecc8c94aefc0132cb8 from master
Diffstat (limited to 'docs/topics/db/optimization.txt')
| -rw-r--r-- | docs/topics/db/optimization.txt | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/docs/topics/db/optimization.txt b/docs/topics/db/optimization.txt index 671f57a8ae..0f39fae103 100644 --- a/docs/topics/db/optimization.txt +++ b/docs/topics/db/optimization.txt @@ -341,8 +341,13 @@ it on a ``QuerySet`` by calling Adding an index to your database may help to improve ordering performance. -Insert in bulk -============== +Use bulk methods +================ + +Use bulk methods to reduce the number of SQL statements. + +Create in bulk +-------------- When creating objects, where possible, use the :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 <django.db.models.query.QuerySet.bulk_create>`, so make sure it's appropriate for your use case. -This also applies to :class:`ManyToManyFields -<django.db.models.ManyToManyField>`, so doing:: +Insert in bulk +-------------- + +When inserting objects into :class:`ManyToManyFields +<django.db.models.ManyToManyField>`, use +:meth:`~django.db.models.fields.related.RelatedManager.add` with multiple +objects to reduce the number of SQL queries. For example:: my_band.members.add(me, my_friend) |
