Avoid unnecessary transaction in QuerySet.bulk_create
The QuerySet.bulk_create method creates an unnecessary transaction when it can perform the insert in a singe INSERT
when the following criteria are met
- There's no mix of objects with and without primary key (this could potentially be optimized to be done in a single query but that's another can of worm)
- The objects fit in a single batch with respect to the provided
batch_size
and connection.ops.bulk_batch_size
This is unnecessary overhead we've optimized in other areas of the code base (e.g. Model.save
) which seems warranted in this case particularly because bulk_create
offers a more featureful interface than create
which can be used to insert a small number of rows.
Change History
(5)
Triage Stage: |
Unreviewed → Accepted
|
Triage Stage: |
Accepted → Ready for checkin
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
In e1671278: