Why is this LEFT JOIN running slowly?
This LEFT JOIN portion of a PostgreSQL query is running quite slowly, and
I can't figure out why.
SELECT t.id FROM tests t
LEFT JOIN tests c
ON c.parent_id IN (t.id, t.parent_id)
There are indexes on tests.id and tests.parent_id.
Tests contains 28876 rows (of those, there are 1282 WHERE parent_id IS NOT
NULL).
The query is producing 32098 rows, and takes about 700ms.
Any ideas as to why it might be slow, or a better way to achieve the same
thing?
Thank you!
No comments:
Post a Comment