[Django] #29771: Support database-specific syntax for bulk_update

24 views
Skip to first unread message

Django

unread,
Sep 18, 2018, 4:29:52 PM9/18/18
to django-...@googlegroups.com
#29771: Support database-specific syntax for bulk_update
-------------------------------------+-------------------------------------
Reporter: Tom | Owner: nobody
Forbes |
Type: | Status: new
Cleanup/optimization |
Component: Database | Version: master
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/29771>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 18, 2018, 5:48:22 PM9/18/18
to django-...@googlegroups.com
#29771: Support database-specific syntax for bulk_update
-------------------------------------+-------------------------------------
Reporter: Tom Forbes | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/29771#comment:1>

Django

unread,
Sep 19, 2018, 1:28:03 PM9/19/18
to django-...@googlegroups.com
#29771: Support database-specific syntax for bulk_update
-------------------------------------+-------------------------------------
Reporter: Tom Forbes | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Vineeth Sagar):

Is anyone working on this? Can I have a go at it?

--
Ticket URL: <https://code.djangoproject.com/ticket/29771#comment:2>

Django

unread,
Oct 4, 2018, 6:08:36 PM10/4/18
to django-...@googlegroups.com
#29771: Support database-specific syntax for bulk_update
-------------------------------------+-------------------------------------
Reporter: Tom Forbes | Owner: Tom
Type: | Forbes
Cleanup/optimization | Status: assigned

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tom Forbes):

* owner: nobody => Tom Forbes
* status: new => assigned

Django

unread,
Oct 4, 2018, 7:05:21 PM10/4/18
to django-...@googlegroups.com
#29771: Support database-specific syntax for bulk_update
-------------------------------------+-------------------------------------
Reporter: Tom Forbes | Owner: Tom
Type: | Forbes
Cleanup/optimization | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tom Forbes):

* cc: Tom Forbes (added)


Comment:

I think the groundwork to this is quite difficult to lay. The current
`SQLUpdateCompiler` is not suitable for this, I think.

Also I believe we can mimic this on SQLLite:

{{{
WITH test(id) AS (SELECT 1 UNION ALL SELECT 2)
UPDATE demo
SET name=(select id from test where id=demo.id)
WHERE id IN (select id from test)
}}}

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/29771#comment:3>

Django

unread,
Oct 7, 2018, 8:49:19 AM10/7/18
to django-...@googlegroups.com
#29771: Support database-specific syntax for bulk_update
-------------------------------------+-------------------------------------
Reporter: Tom Forbes | Owner: Tom
Type: | Forbes
Cleanup/optimization | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Brillgen Developers):

* cc: Brillgen Developers (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/29771#comment:4>

Django

unread,
Nov 10, 2018, 10:30:07 AM11/10/18
to django-...@googlegroups.com
#29771: Support database-specific syntax for bulk_update
-------------------------------------+-------------------------------------
Reporter: Tom Forbes | Owner: Tom
Type: | Forbes
Cleanup/optimization | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Srinivas Reddy Thatiparthy):

* cc: Srinivas Reddy Thatiparthy (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/29771#comment:5>

Django

unread,
Mar 25, 2020, 6:52:38 PM3/25/20
to django-...@googlegroups.com
#29771: Support database-specific syntax for bulk_update
-------------------------------------+-------------------------------------
Reporter: Tom Forbes | Owner: Tom
Type: | Forbes
Cleanup/optimization | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adam (Chainz) Johnson):

* cc: Adam (Chainz) Johnson (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/29771#comment:6>

Django

unread,
May 20, 2020, 4:24:00 AM5/20/20
to django-...@googlegroups.com
#29771: Support database-specific syntax for bulk_update
-------------------------------------+-------------------------------------
Reporter: Tom Forbes | Owner: Tom
Type: | Forbes
Cleanup/optimization | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Shai Berger):

* cc: Shai Berger (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/29771#comment:7>

Django

unread,
Mar 21, 2023, 5:28:19 AM3/21/23
to django-...@googlegroups.com
#29771: Support database-specific syntax for bulk_update
-------------------------------------+-------------------------------------
Reporter: Tom Forbes | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: dev

(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: Tom Forbes => (none)
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/29771#comment:8>

Django

unread,
Oct 10, 2023, 2:47:42 AM10/10/23
to django-...@googlegroups.com
#29771: Support database-specific syntax for bulk_update
-------------------------------------+-------------------------------------
Reporter: Tom Forbes | Owner: (none)
Type: | Status: new
Cleanup/optimization |

Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Akash Kumar Sen):

* cc: Akash Kumar Sen (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/29771#comment:9>

Django

unread,
Oct 16, 2023, 8:25:57 PM10/16/23
to django-...@googlegroups.com
#29771: Support database-specific syntax for bulk_update
-------------------------------------+-------------------------------------
Reporter: Tom Forbes | Owner: Akash
Type: | Kumar Sen
Cleanup/optimization | Status: assigned

Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Akash Kumar Sen):

* owner: (none) => Akash Kumar Sen


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/29771#comment:10>

Django

unread,
Nov 10, 2023, 6:12:42 PM11/10/23
to django-...@googlegroups.com
#29771: Support database-specific syntax for bulk_update
-------------------------------------+-------------------------------------
Reporter: Tom Forbes | Owner: Akash
Type: | Kumar Sen
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by John Speno):

* cc: John Speno (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/29771#comment:11>

Reply all
Reply to author
Forward
0 new messages