#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: | Status: closed Cleanup/optimization | Component: Database layer | Version: 5.0 (models, ORM) | Severity: Normal | Resolution: duplicate 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):
> it will raise a type error: we catch that, and then fallback on the original way of doing it, without much delay. Creating and catching exceptions is not cheap either so I'm not sure we can qualify it as ''without much delay''. I don't see any benchmark backing it is what I mean. > the idea is that this often will still pay off, since the cascade of Case - When essentially forces the database into linear search I see what you mean with the database level linear scan but my concerns is that the extra amount time we spend ''massaging'' the data on the Python side pre-emptively in hope of preventing the database level slowdown from happening is going to cause more harm than good. You benchmarked against are the ''happy path'' where a there's a single field to update, the values are all literals, the values are all hashable. I think that a proper solution should ensure that the ''Python layer tax'' of organizing the data doesn't outweigh the expected database level benefits. Having separate benchmarks for query / SQL generation in both variants of `bulk_update` vs database level execution of the SQL on supported backends would help in taking more advised decision here. All of that can take place on the forum though. -- Ticket URL: <https://code.djangoproject.com/ticket/35399#comment:7> 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/0107018f1184893c-65dbbe78-b835-470a-aee6-d7b1f46bdcbc-000000%40eu-central-1.amazonses.com.