From: | "Josh Berkus" <josh(at)agliodbs(dot)com> |
---|---|
To: | pgsql-performance(at)postgresql(dot)org |
Subject: | Re: Which of the solution is better? |
Date: | 2002-12-11 21:53:38 |
Message-ID: | web-2277358@davinci.ethosmedia.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
Wei,
> I have two tables A and B where A is a huge table with thousands of
> rows, B is a small table with only a couple of entries.
>
> I want to do something like
>
> SELECT
> A.ID
> A.Name
> FROM
> A JOIN B ON (A.ID = B.ID)
You might consider:
SELECT A.ID
A.Name
FROM A
WHERE EXISTS (SELECT ID FROM B WHERE B.ID = A.ID)
This lets the parser know that you are not interested in retrieving
entire records from B, just those rows from A which correspond to B.
Run that, and compare the EXPLAIN ANALYZE plan against one which lets
the that parser have free reign:
SELECT A.ID, A.Name
FROM A, B
WHERE A.ID = B.ID
Chances are, the parser will do a better job on the query than you can
do by making stuff explicit.
Give it a try.
-Josh Berkus
From | Date | Subject | |
---|---|---|---|
Next Message | Justin Clift | 2002-12-11 22:06:00 | Re: Good/Bad RAID and SCSI controllers? |
Previous Message | Josh Berkus | 2002-12-11 21:49:20 | Good/Bad RAID and SCSI controllers? |