#35399: Reduce the "Case-When" sequence for a bulk_update when the values for a certain field are the same. -------------------------------------+------------------------------------- Reporter: Willem Van Onsem | Owner: nobody Type: New feature | Status: new Component: Database layer | Version: 5.0 (models, ORM) | Severity: Normal | Resolution: Keywords: db, bulk_update, | Triage Stage: case, when | Unreviewed Has patch: 1 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Comment (by Simon Charette):
Thank you for taking the time to perform the benchmarks, I think you missed the point brought up about hashing being expensive on non-literal values though. In other words `int.__hash__` is pretty fast but `Expression.__hash__` isn't and you need to perform an implicit one to gather values in `defaultdict(list)`. Since `bulk_update` support both expressions and literal assignment the benchmark must be run against both to be representative. Try running them with assignments of `F("scans_in") + Value(random.randint(0, m))` instead and you should see a slowdown. The need for _hashability_ also poses another problem. What should be done with values that are not hashable such as `JSONField` assignment of `dict`s? {{{#!python objects = [ Object(pk=1, data={"foo": "bar"}), Object(pk=2, data={"foo": "bar"}), ] Object.objects.bulk_update(es, fields=["data"]) }}} When all of these edge cases are accounted for (we'll need a route for non-hashable values mixed with hashable values) I still believe that time would be better spend not using `CASE` / `WHEN` at all and favor investing efforts towards #29771 and #31202. -- Ticket URL: <https://code.djangoproject.com/ticket/35399#comment:4> 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 django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107018f1116c4d5-55edef6d-5f1e-4629-bd29-3b552eb41fe6-000000%40eu-central-1.amazonses.com.