#34964: Reversing the order of Q objects in a CheckConstraint generates a
migration
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Jacob
Type: | Walls
Cleanup/optimization | Status: assigned
Component: Migrations | Version: dev
Severity: Normal | Resolution:
Keywords: noop | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by David Sanders):
Advice from #postgresql IRC channel is that an expression's operand order
_does_ matter, but only for check constraints.
> in most contexts ANDed and ORed terms are sliced-and-diced as the
planner sees fit. but there is one case that might matter:
> the check constraint obviously gets evaluated to check inserted rows,
and I don't believe (but would have to check) that it gets reordered there
> in which case CHECK (foo OR slowfunc(bar)) might be faster than CHECK
(slowfunc(bar) OR foo)
>
> let me check the code. sec.
> looks like check expressions are not reordered by the planner for
performance
> inside queries, lists of ANDed quals evaluated at a single node are
reordered when possible to put expensive ones last (subject to security
restrictions)
> but that doesn't apply to checking constraints on insert/update
> so I would expect CHECK (foo OR slowfunc(bar)) to be noticably faster
than CHECK (slowfunc(bar) OR foo) in the case where "foo" is usually true
>
> tested it and it looks like i am correct
Advice courtesy of RhodiumToad 💚
--
Ticket URL: <https://code.djangoproject.com/ticket/34964#comment:11>
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/0107018bd1548baf-8c70f467-14dd-44c6-a8ea-acbccfc54437-000000%40eu-central-1.amazonses.com.