#35124: Could bulk_update() aggregate the primary keys in CASE clauses?
-------------------------------------+-------------------------------------
Reporter: Vlada | Owner: nobody
Macek |
Type: | Status: new
Cleanup/optimization |
Component: Database | Version: dev
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 |
-------------------------------------+-------------------------------------
I'd like to ask if there's a reason why instead of this
{{{#!python
when_statements = []
for obj in batch_objs:
attr = getattr(obj, field.attname)
if not hasattr(attr, "resolve_expression"):
attr = Value(attr, output_field=field)
when_statements.append(When(pk=obj.pk, then=attr))
}}}
this code isn't used
{{{#!python
when_updates = defaultdict(list)
for obj in batch_objs:
attr = getattr(obj, field.attname)
if not hasattr(attr, "resolve_expression"):
attr = Value(attr, output_field=field)
when_updates[attr].append(obj.pk)
when_statements = [
When(pk__in=pks, then=attr) if len(pks) > 1 else
When(pk=pks[0], then=attr)
for attr, pks in when_updates.items()
]
}}}
in `bulk_update()`. Instead of having `WHEN` for each pk, aggregated `WHEN
("t"."id" IN (14679095, 14679134, 14679335, ...)) THEN ...` would be
produced.
That could massively reduce the query length.
--
Ticket URL: <https://code.djangoproject.com/ticket/35124>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018d1c81221a-8f05bfab-693c-4674-ac3d-1d1caf4953b6-000000%40eu-central-1.amazonses.com.