#33973: Performance regression when moving from 3.1 to 3.2
-------------------------------------+-------------------------------------
     Reporter:  Marc Parizeau        |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  new
    Component:  Uncategorized        |                  Version:  3.2
     Severity:  Normal               |               Resolution:
     Keywords:  performance          |             Triage Stage:
  regression                         |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Marc Parizeau):

 Here is the "explanation" for Django 4.0.7:

 {{{
 time 0.3011052919999955
 Sort  (cost=62.30..62.31 rows=1 width=1207)
   Sort Key: content_course.uid, content_version.start DESC
   ->  Nested Loop Left Join  (cost=0.41..62.29 rows=1 width=1207)
         ->  Nested Loop Left Join  (cost=0.28..40.58 rows=1 width=1202)
               ->  Nested Loop  (cost=0.14..39.68 rows=1 width=1124)
                     ->  Seq Scan on content_teacher  (cost=0.00..7.65
 rows=1 width=8)
                           Filter: (user_id = 59)
                     ->  Index Scan using content_semester_pkey on
 content_content  (cost=0.14..28.99 rows=1 width=1124)
                           Index Cond: (id = content_teacher.content_id)
                           Filter: ((id <> 58) AND GREATEST((SubPlan 3),
 false))
                           SubPlan 3
                             ->  Nested Loop Anti Join
 (cost=0.43..18547.19 rows=909 width=0)
                                   ->  Seq Scan on forum_thread v0_1
 (cost=0.00..1799.79 rows=1174 width=8)
                                         Filter: (content_id =
 content_content.id)
                                   ->  Index Only Scan using
 forum_threadentry_thread_id_user_id_cd21c4a5_uniq on forum_threadentry
 u1_1  (cost=0.43..55.66 rows=33 width=8)
                                         Index Cond: ((thread_id = v0_1.id)
 AND (user_id = 59))
               ->  Index Scan using content_course_pkey on content_course
 (cost=0.14..0.82 rows=1 width=86)
                     Index Cond: (id = content_content.course_id)
         ->  Index Scan using content_version_pkey on content_version
 (cost=0.14..0.82 rows=1 width=12)
               Index Cond: (id = content_content.version_id)
         SubPlan 1
           ->  Nested Loop Anti Join  (cost=0.43..18547.19 rows=909
 width=0)
                 ->  Seq Scan on forum_thread v0  (cost=0.00..1799.79
 rows=1174 width=8)
                       Filter: (content_id = content_content.id)
                 ->  Index Only Scan using
 forum_threadentry_thread_id_user_id_cd21c4a5_uniq on forum_threadentry u1
 (cost=0.43..55.66 rows=33 width=8)
                       Index Cond: ((thread_id = v0.id) AND (user_id = 59))
 }}}

 And the corresponding SQL:

 {{{
 SELECT "content_content"."id", "content_content"."created",
 "content_content"."description", "content_content"."disabled",
 "content_content"."modified", "content_content"."objectives",
 "content_content"."published", "content_content"."title",
 "content_content"."course_id", "content_content"."version_id",
 "content_content"."exercise_weight", "content_content"."midterm_weight",
 "content_content"."final_weight", "content_content"."project_weight",
 "content_content"."forum_weight", "content_content"."welcome_video",
 "content_content"."navigate_video", "content_content"."forum_video",
 "content_content"."lambda_fct_id", "content_content"."dl_key_version",
 "content_content"."dl_key_token", "content_content"."exam_key_token",
 "content_content"."lectures_url", GREATEST(EXISTS(SELECT (1) AS "a" FROM
 "forum_thread" V0 WHERE (V0."content_id" = ("content_content"."id") AND
 NOT (EXISTS(SELECT (1) AS "a" FROM "forum_threadentry" U1 WHERE
 (U1."user_id" = 59 AND U1."thread_id" = (V0."id")) LIMIT 1))) LIMIT 1),
 False) AS "unread" FROM "content_content" INNER JOIN "content_teacher" ON
 ("content_content"."id" = "content_teacher"."content_id") LEFT OUTER JOIN
 "content_course" ON ("content_content"."course_id" =
 "content_course"."id") LEFT OUTER JOIN "content_version" ON
 ("content_content"."version_id" = "content_version"."id") WHERE
 ("content_teacher"."user_id" = 59 AND NOT ("content_content"."id" = 58)
 AND GREATEST(EXISTS(SELECT (1) AS "a" FROM "forum_thread" V0 WHERE
 (V0."content_id" = ("content_content"."id") AND NOT (EXISTS(SELECT (1) AS
 "a" FROM "forum_threadentry" U1 WHERE (U1."user_id" = 59 AND
 U1."thread_id" = (V0."id")) LIMIT 1))) LIMIT 1), False)) ORDER BY
 "content_course"."uid" ASC, "content_version"."start" DESC
 }}}

 As for Django 4.1, I can't do it right now, because I am getting
 `Expression contains mixed types: IntegerField, SmallIntegerField` errors
 which I haven't been able to remove so far.

 But my issues definitely started with Django 3.2, not with Django 4 which
 seems to behave similarly for my specific query.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33973#comment:4>
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/01070182fa4826db-0d9b4cc3-2d46-44f0-9d0b-db19d2261e7d-000000%40eu-central-1.amazonses.com.

Reply via email to