#34831: Search in admin could allow issuing a query with many OR'd clauses
-------------------------------------+-------------------------------------
Reporter: Natalia Bidart | Owner: Yves
Type: | Weissig
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | 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 Nicolas Lupien):
I did benchmark with MySQL 8.0 and this model:
{{{
class Posts(models.Model):
title = models.CharField(max_length=100, db_index=True)
slug = models.TextField(db_index=True)
body = models.TextField(db_index=True)
tags = models.CharField(max_length=100, db_index=True)
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
class PostAdmin(admin.ModelAdmin):
search_fields = ["title", "slug", "tags", "body", "created_at"]
list_display = ["title", "tags"]
}}}
10 terms: 673.32 ms
25 terms: 649.94 ms
50 terms: 615.97 ms
100 terms: 543.81 ms
Notice the query is actually improving in time when increasing the terms.
I think this is ecause the query is only OR'd for each different field,
for a single field the terms are actually AND'd, which limit the results a
lot.
Here's a query with 2 terms (Hello World) :
{{{
SELECT ••• FROM `posts_posts` WHERE ((`posts_posts`.`title` LIKE '%Hello%'
OR `posts_posts`.`slug` LIKE '%Hello%' OR `posts_posts`.`tags` LIKE
'%Hello%' OR `posts_posts`.`body` LIKE '%Hello%' OR
`posts_posts`.`created_at` LIKE '%Hello%') AND (`posts_posts`.`title` LIKE
'%World%' OR `posts_posts`.`slug` LIKE '%World%' OR `posts_posts`.`tags`
LIKE '%World%' OR `posts_posts`.`body` LIKE '%World%' OR
`posts_posts`.`created_at` LIKE '%World%')) ORDER BY `posts_posts`.`id`
DESC
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34831#comment:5>
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/0107018c8805fb7f-799c6331-7cb7-4609-b773-13346a9071c0-000000%40eu-central-1.amazonses.com.