Opened 7 years ago
Last modified 9 months ago
#29771 assigned Cleanup/optimization
Support database-specific syntax for bulk_update
| Reported by: | Tom Forbes | Owned by: | Akash Kumar Sen |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Tom Forbes, Brillgen Developers, Srinivas Reddy Thatiparthy, Adam Johnson, Shai Berger, Akash Kumar Sen, John Speno, Roman Donchenko | Triage Stage: | Accepted |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
As Simon points out here (https://code.djangoproject.com/ticket/23646#comment:15) specialized syntax can massively speed up bulk_update().
Postgres supports using UPDATE ... FROM (https://stackoverflow.com/questions/18797608/update-multiple-rows-in-same-query-using-postgresql) and we can possibly emulate this with MySQL and UNION ...'s.
Change History (12)
comment:1 by , 7 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 7 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:3 by , 7 years ago
| Cc: | added |
|---|
comment:4 by , 7 years ago
| Cc: | added |
|---|
comment:5 by , 7 years ago
| Cc: | added |
|---|
comment:6 by , 6 years ago
| Cc: | added |
|---|
comment:7 by , 5 years ago
| Cc: | added |
|---|
comment:8 by , 3 years ago
| Owner: | removed |
|---|---|
| Status: | assigned → new |
comment:9 by , 2 years ago
| Cc: | added |
|---|
comment:10 by , 2 years ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:11 by , 2 years ago
| Cc: | added |
|---|
comment:12 by , 9 months ago
| Cc: | added |
|---|
Note:
See TracTickets
for help on using tickets.
I think the groundwork to this is quite difficult to lay. The current
SQLUpdateCompileris not suitable for this, I think.Also I believe we can mimic this on SQLLite:
Whether or not this is faster is something I'm not sure of. I believe the MySQL syntax will be faster, and there is no SQL standard way of doing this (I believe?), so we are left with a number of pretty different workarounds. I'm not sure how to structure this nicely.
I can maybe hack Postgres support into the SQLUpdateCompiler, but it's really not nice. We have to create all the aliases ourselves, manage the different column names, etc etc.