-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Fixed #36490 -- Avoided unnecessary transaction in bulk_create. #19614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I glossed over finer details but generally seems good 🏆
This comment was marked as spam.
This comment was marked as spam.
When dealing with an heterogeneous set of object with regards to primary key assignment that fits in a single batch there's no need to wrap the single INSERT statement in a transaction.
…andling. Whether or not returning_fields should be specified to _insert is not a function of each batches so the conditional can be moved outside of the loop.
Asserting an upper bound for the number of executed queries can be achieved by using CaptureQueriesContext instead of enabling the whole DEBUG machinery.
FWIW recent improvements in |
@@ -800,7 +801,11 @@ def bulk_create( | |||
fields = [f for f in opts.concrete_fields if not f.generated] | |||
objs = list(objs) | |||
objs_with_pk, objs_without_pk = self._prepare_for_bulk_create(objs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears that this whole primary key assignment partition logic can also be elided if we'd like to go further
Trac ticket number
ticket-36490
Branch description
When bulk_create deals with an heterogeneous set of object with regards to primary key assignment that fits in a single batch there's no need to wrap the resulting single INSERT statement in a transaction.
Checklist
main
branch.