From: | Niklas Johansson <spot(at)tele2(dot)se> |
---|---|
To: | tlm <tlm1905(at)gmail(dot)com> |
Cc: | pgsql-performance(at)postgresql(dot)org |
Subject: | Re: How to speed up this "translation" query? |
Date: | 2006-08-01 18:38:38 |
Message-ID: | CCD0B1B3-697D-43F5-9054-2416FC81AE00@tele2.se |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
On 1 aug 2006, at 20.09, tlm wrote:
> SELECT q3.translation, q2.otherstuff
> FROM
> (
> SELECT INPUT.word, q1.meaning_id, INPUT.otherstuff
> FROM
> INPUT
> INNER JOIN
> (
> SELECT translation, meaning_id
> FROM TRANS
> WHERE translation IN (SELECT word FROM INPUT)
> ) AS q1
> ON INPUT.word = q1.translation
> ) AS q2
> LEFT JOIN
> (
> SELECT translation, meaning_id
> FROM TRANS
> WHERE language_id=5
> ) AS q3
> ON q2.meaning_id=q3.meaning_id;
Maybe I'm not following you properly, but I think you've made things
a little bit more complicated than they need to be. The nested sub-
selects look a little nasty.
Now, you didn't provide any explain output but I think the following
SQL will achieve the same result, and hopefully produce a better plan:
SELECT t2.translation, i.otherstuff
FROM input i INNER JOIN trans t ON i.word=t.translation
INNER JOIN trans t2 ON t.meaning_id=t2.meaning_id
WHERE t2.language_id=5;
The query will also benefit from indices on trans.meaning_id and
trans.language_id. Also make sure the tables are vacuumed and
analyzed, to allow the planner to make good estimates.
Sincerely,
Niklas Johansson
From | Date | Subject | |
---|---|---|---|
Next Message | Milen Kulev | 2006-08-01 21:49:56 | XFS filessystem for Datawarehousing |
Previous Message | tlm | 2006-08-01 18:09:54 | How to speed up this "translation" query? |