#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 Willem Van Onsem):

 Hi, that is already in the changeset: in case the item is not hashable, it
 will raise a type error: we catch that, and then fallback on the original
 way of doing it, without much delay. So it is more a boosting mechanism
 that when fails, is "disabled" when running through it.

 The hash of an expression indeed is take more time than the one of an
 `int`, but the idea is that this often will still pay off, since the
 cascade of Case`-`When` essentially forces the database into linear
 search, while it *might* be possible that a certain database finds a way,
 if that is not the case, it will first look at the first `When`, if that
 fails, the next one, etc. so for ~1000 `When`s, it will on average take
 500 items per row.

 I agree that a temporary table is probably more ideal.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35399#comment:6>
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/0107018f114c1448-67138b52-928c-4127-b52f-06f58f7961be-000000%40eu-central-1.amazonses.com.

Reply via email to