#30488: SearchVector lookup is generating redundent Coalesce wrapper
------------------------------------------------+------------------------
Reporter: thomasina-lee | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: contrib.postgres | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
In Django 2.2.1, in the SearchVector if we do:
{{{
>>> from django.contrib.postgres.search import SearchVector
>>> Entry.objects.annotate(
... search=SearchVector('body_text', 'summary_text'),
... ).filter(search='Cheese')
}}}
The generated SQL currently looks something like
{{{
SELECT id /*......*/
FROM "app_entry" WHERE
to_tsvector(COALESCE(COALESCE("app_entry"."body_text", ''), '') || ' '
|| COALESCE(COALESCE("app_entry"."summary_text", ''), '')) @@
(plainto_tsquery('Cheese')) = true
}}}
i.e. in the {{{WHERE}}} clause, the fields is wrapped twice with
{{{COALESCE}}}, .e.g. {{{COALESCE(COALESCE("app_entry"."body_text", ),
)}}}
While it is still possible to create a functional index with this, the
generated SQL does not feel optimal at the very least.
It will be great if the generated SQL will keep to one level of
{{{COALESCE}}}, .e.g. {{{COALESCE("app_entry"."body_text", ), )}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30488>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/056.ab12f2f6f07356dbd46a3a0ebb6912f2%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.