Comment 1 for bug 734642

Robert Collins (lifeless) wrote :

SELECT TranslationMessage.COMMENT, TranslationMessage.date_created,
                                   TranslationMessage.date_reviewed,
                                   TranslationMessage.id,
                                   TranslationMessage.is_current_ubuntu,
                                   TranslationMessage.is_current_upstream,
                                   TranslationMessage.LANGUAGE, TranslationMessage.msgstr0,
                                                                TranslationMessage.msgstr1,
                                                                TranslationMessage.msgstr2,
                                                                TranslationMessage.msgstr3,
                                                                TranslationMessage.msgstr4,
                                                                TranslationMessage.msgstr5,
                                                                TranslationMessage.origin,
                                                                TranslationMessage.potemplate,
                                                                TranslationMessage.potmsgset,
                                                                TranslationMessage.reviewer,
                                                                TranslationMessage.submitter,
                                                                TranslationMessage.validation_status,
                                                                TranslationMessage.was_obsolete_in_last_import
FROM TranslationMessage
WHERE TranslationMessage.id IN
    (SELECT DISTINCT ON (COALESCE(msgstr0, -1), COALESCE(msgstr1, -1), COALESCE(msgstr2, -1), COALESCE(msgstr3, -1), COALESCE(msgstr4, -1), COALESCE(msgstr5, -1)) TranslationMessage.id
     FROM TranslationMessage
     WHERE (TranslationMessage.LANGUAGE IN (132))
       AND TranslationMessage.potmsgset <> 8171049
       AND potmsgset IN
         (SELECT POTMsgSet.id
          FROM POTMsgSet
          JOIN TranslationTemplateItem ON TranslationTemplateItem.potmsgset = POTMsgSet.id
          JOIN SuggestivePOTemplate ON TranslationTemplateItem.potemplate = SuggestivePOTemplate.potemplate
          WHERE msgid_singular = 347523)
     ORDER BY COALESCE(msgstr0, -1), COALESCE(msgstr1, -1), COALESCE(msgstr2, -1), COALESCE(msgstr3, -1), COALESCE(msgstr4, -1), COALESCE(msgstr5, -1), date_created DESC)LIMIT 2001

 Limit (cost=294364.63..296495.59 rows=200 width=76) (actual time=994.854..1063.958 rows=4 loops=1)
   -> Nested Loop (cost=294364.63..296495.59 rows=200 width=76) (actual time=994.852..1063.954 rows=4 loops=1)
         -> HashAggregate (cost=294364.63..294366.63 rows=200 width=4) (actual time=935.851..935.857 rows=4 loops=1)
               -> Unique (cost=256804.40..291860.61 rows=200322 width=36) (actual time=926.269..926.276 rows=4 loops=1)
                     -> Sort (cost=256804.40..261812.43 rows=2003212 width=36) (actual time=926.268..926.270 rows=6 loops=1)
                           Sort Key: (COALESCE(public.translationmessage.msgstr0, (-1))), (COALESCE(public.translationmessage.msgstr1, (-1))), (COALESCE(public.translationmessage.msgstr2, (-1))), (COALESCE(public.translationmessage.msgstr3, (-1))), (COALESCE(public.translationmessage.msgstr4, (-1))), (COALESCE(public.translationmessage.msgstr5, (-1))), public.translationmessage.date_created
                           Sort Method: quicksort Memory: 25kB
                           -> Nested Loop (cost=101.49..176.36 rows=2003212 width=36) (actual time=786.697..926.213 rows=6 loops=1)
                                 -> HashAggregate (cost=101.49..101.54 rows=5 width=8) (actual time=674.517..674.526 rows=6 loops=1)
                                       -> Nested Loop (cost=0.00..101.45 rows=18 width=8) (actual time=163.196..674.441 rows=24 loops=1)
                                             -> Nested Loop (cost=0.00..96.38 rows=18 width=12) (actual time=129.512..497.646 rows=25 loops=1)
                                                   -> Index Scan using potmsgset_primemsgid_idx on potmsgset (cost=0.00..18.54 rows=5 width=4) (actual time=70.511..149.530 rows=9 loops=1)
                                                         Index Cond: (msgid_singular = 347523)
                                                   -> Index Scan using translationtemplateitem__potmsgset__idx on translationtemplateitem (cost=0.00..15.52 rows=4 width=8) (actual time=24.284..38.673 rows=3 loops=9)
                                                         Index Cond: (translationtemplateitem.potmsgset = potmsgset.id)
                                             -> Index Scan using suggestivepotemplate_pkey on suggestivepotemplate (cost=0.00..0.27 rows=1 width=4) (actual time=6.910..7.068 rows=1 loops=25)
                                                   Index Cond: (suggestivepotemplate.potemplate = translationtemplateitem.potemplate)
                                 -> Index Scan using translationmessage__potmsgset__language__idx on translationmessage (cost=0.00..14.94 rows=2 width=40) (actual time=39.301..41.943 rows=1 loops=6)
                                       Index Cond: ((public.translationmessage.potmsgset = translationtemplateitem.potmsgset) AND (public.translationmessage.language = 132))
                                       Filter: (public.translationmessage.potmsgset <> 8171049)
         -> Index Scan using translationmessage_pkey on translationmessage (cost=0.00..10.63 rows=1 width=76) (actual time=32.020..32.020 rows=1 loops=4)
               Index Cond: (public.translationmessage.id = public.translationmessage.id)
 Total runtime: 1072.450 ms
(23 rows)

Time: 1413.638 ms

300ms when repeated (actual execution time)