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.