Query > 1000× slowdown after adding datetime comparison - Mailing list pgsql-performance

From twoflower
Subject Query > 1000× slowdown after adding datetime comparison
Date
Msg-id 1441037351126-5864045.post@n5.nabble.com
Whole thread Raw
Responses Re: Query > 1000× slowdown after adding datetime comparison
Re: [PERFORM] Query > 1000× slowdown after adding datetime comparison
List pgsql-performance
I have the following three tables:

DOCUMENT
  id (index)
  documenttype
  date_last_updated: timestamp(6) (indexed)

EXTERNAL_TRANSLATION_UNIT
  id (indexed)
  fk_id_document (indexed)

EXTERNAL_TRANSLATION
  id (indexed)
  fk_id_translation_unit (indexed)

Table sizes:
 DOCUMENT: 381 000
 EXTERNAL_TRANSLATION_UNIT: 76 000 000
 EXTERNAL_TRANSLATION: 76 000 000

Now the following query takes about 36 minutes to finish:

 SELECT u.id AS id_external_translation_unit,
    r.id AS id_external_translation,
    u.fk_id_language AS fk_id_source_language,
    r.fk_id_language AS fk_id_target_language,
    doc.fk_id_job
 FROM "EXTERNAL_TRANSLATION_UNIT" u
     JOIN "DOCUMENT" doc ON u.fk_id_document = doc.id
     JOIN "EXTERNAL_TRANSLATION" r ON u.id = r.fk_id_translation_unit
 WHERE doc.date_last_updated >= date(now() - '171:00:00'::interval)
 ORDER BY r.id LIMIT 1000

This is the query plan:

<http://postgresql.nabble.com/file/n5864045/qp1.png>

If I remove the WHERE condition, it returns immediately.

Am I doing something obviously wrong?

Thank you for any ideas.



--
View this message in context:
http://postgresql.nabble.com/Query-1000-slowdown-after-adding-datetime-comparison-tp5864045.html
Sent from the PostgreSQL - performance mailing list archive at Nabble.com.


pgsql-performance by date:

Previous
From: Tom Lane
Date:
Subject: Re: is there any way we can push join predicate into inner table
Next
From: Tomas Vondra
Date:
Subject: Re: Query > 1000× slowdown after adding datetime comparison