I'm getting a monster query that hangs the database when a search is done 
in the admin interface.

SELECT DISTINCT `clothes_outfit`.`id` 
FROM   `clothes_outfit` 
       INNER JOIN `clothes_outfit_articles` 
               ON ( `clothes_outfit`.`id` = 
                    `clothes_outfit_articles`.`outfit_id` ) 
       INNER JOIN `clothes_article` 
               ON ( `clothes_outfit_articles`.`article_id` = 
                    `clothes_article`.`id` ) 
       INNER JOIN `clothes_outfit_articles` T4 
               ON ( `clothes_outfit`.`id` = T4.`outfit_id` ) 
       INNER JOIN `clothes_article` T5 
               ON ( T4.`article_id` = T5.`id` ) 
       INNER JOIN `clothes_outfit_articles` T6 
               ON ( `clothes_outfit`.`id` = T6.`outfit_id` ) 
       INNER JOIN `clothes_article` T7 
               ON ( T6.`article_id` = T7.`id` ) 
       INNER JOIN `clothes_outfit_articles` T8 
               ON ( `clothes_outfit`.`id` = T8.`outfit_id` ) 
       INNER JOIN `clothes_article` T9 
               ON ( T8.`article_id` = T9.`id` ) 
       INNER JOIN `clothes_outfit_articles` T10 
               ON ( `clothes_outfit`.`id` = T10.`outfit_id` ) 
       INNER JOIN `clothes_article` T11 
               ON ( T10.`article_id` = T11.`id` ) 
       INNER JOIN `clothes_outfit_articles` T12 
               ON ( `clothes_outfit`.`id` = T12.`outfit_id` ) 
       INNER JOIN `clothes_article` T13 
               ON ( T12.`article_id` = T13.`id` ) 
       INNER JOIN `clothes_outfit_articles` T14 
               ON ( `clothes_outfit`.`id` = T14.`outfit_id` ) 
       INNER JOIN `clothes_article` T15 
               ON ( T14.`article_id` = T15.`id` ) 
       INNER JOIN `clothes_outfit_articles` T16 
               ON ( `clothes_outfit`.`id` = T16.`outfit_id` ) 
       INNER JOIN `clothes_article` T17 
               ON ( T16.`article_id` = T17.`id` ) 
       INNER JOIN `clothes_outfit_articles` T18 
               ON ( `clothes_outfit`.`id` = T18.`outfit_id` ) 
       INNER JOIN `clothes_article` T19 
               ON ( T18.`article_id` = T19.`id` ) 
       INNER JOIN `clothes_outfit_articles` T20 
               ON ( `clothes_outfit`.`id` = T20.`outfit_id` ) 
       INNER JOIN `clothes_article` T21 
               ON ( T20.`article_id` = T21.`id` ) 
WHERE  ( `clothes_article`.`name` LIKE '%Express%' 
         AND T5.`name` LIKE '%Flare%' 
         AND T7.`name` LIKE '%Jeans%' 
         AND T9.`name` LIKE '%-%' 
         AND T11.`name` LIKE '%0L%' 
         AND T13.`name` LIKE '%Light%' 
         AND T15.`name` LIKE '%Hot%' 
         AND T17.`name` LIKE '%Pink%' 
         AND T19.`name` LIKE '%Tank%' 
         AND T21.`name` LIKE '%F21%' ) 
ORDER  BY `clothes_outfit`.`id` DESC 
LIMIT  21;



Here are the relevant parts of the model...

class Article(models.Model):
    name = models.CharField(max_length=200)

class Outfit(models.Model):
    articles = models.ManyToManyField(Article, related_name='outfits')

And from admin:

class OutfitAdmin(admin.ModelAdmin):
  search_fields = ['articles__name',]

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/LmiFC1Cc9Z4J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to