#34840: Django 4.2 casts text fields when testing IS NULL, preventing use of
partial indexes
-------------------------------------+-------------------------------------
Reporter: Alex Vandiver | Owner: murtatah
Type: Bug | Status: assigned
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Florian Apolloner):
Replying to [comment:8 Mariusz Felisiak]:
> Replying to [comment:7 Florian Apolloner]:
> > This doesn't just affect `::text` but all casts?
>
> As far as I'm aware, from the lookup perspective it
[https://github.com/django/django/blob/814e7bc22062eeae4be9f189e89027e28d5dd290/django/db/backends/postgresql/operations.py#L158-L166
affects] mainly `__isnull`.
Oh right, and that is mostly a result of handling text columns as
`unknown` oids instead of `text` which has/had it's own share of problems.
Replying to [comment:5 Simon Charette]:
> What do you think of making the casting conditional to the enablement of
the `server_side_binding` option in this case?
Thinking about this more I am not sure this is a good idea; after all
people should be free to change that setting and Django should behave the
same. I feel like we are running into limitations of our ORM here, do we
really need the `::text` cast here for server side bindings? Isn't
postgresql able to properly deduce the types? After all, in the query as
well as in the index we reference the column `subgroup` which has a well
defined type (or am I mistaken here). We should only need type casts if we
involve bind parameters.
Though that begs the next question: Assume you generate an index for a
text column named `x`. Would a query with `.filter(x__startswith='test')`
use the index if the index is created on `x` but the query uses `x::text
like 'test%'`?
--
Ticket URL: <https://code.djangoproject.com/ticket/34840#comment:10>
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/0107018a9d933367-63bc4754-7103-4c53-9eeb-f9c62ee33d73-000000%40eu-central-1.amazonses.com.