From: | "Dann Corbit" <DCorbit(at)connx(dot)com> |
---|---|
To: | "Hegedus, Tamas (dot)" <Hegedus(dot)Tamas(at)mayo(dot)edu>, <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: TimeOf(Subselects|Joins)FromLargeTables? |
Date: | 2004-06-05 00:42:31 |
Message-ID: | D90A5A6C612A39408103E6ECDD77B829BC018E@voyager.corporate.connx.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
> -----Original Message-----
> From: Hegedus, Tamas . [mailto:Hegedus(dot)Tamas(at)mayo(dot)edu]
> Sent: Friday, June 04, 2004 5:18 PM
> To: 'pgsql-hackers(at)postgresql(dot)org'
> Subject: [HACKERS] TimeOf(Subselects|Joins)FromLargeTables?
>
>
> Dear All,
>
[snip]
> ---------------------------------------------
> What should I expect from the following (similar with joins)
> queries? How should I optimize the indexes? Which one to use?
>
> SELECT name, seq FROM prots WHERE fid in (SELECT fid FROM kwx
> WHERE kw_acc=812 AND kw_acc=215);
This query is a false tautology and hence will return zero rows. The
attribute kwx cannot be simultaneously 812 and 215.
> SELECT name, seq FROM prots
> WHERE fid in (SELECT fid FROM kwx WHERE kw_acc=812 OR kw_acc=215);
I suspect that this query would be better formulated as:
SELECT
prots.name, prots.seq
FROM
prots, kwx
WHERE
prots.fid = kwx.fid AND kwx.kw_acc IN (812, 215);
I think joins give the planner better options than subselects and also
an in-list is going to do better than a list of constants separated by
OR.
Though you should test them both and see what the planner says.
[snip]
From | Date | Subject | |
---|---|---|---|
Next Message | Lamar Owen | 2004-06-05 03:48:59 | Re: Official Freeze Date for 7.5: July 1st, 2004 |
Previous Message | Hegedus, Tamas . | 2004-06-05 00:17:50 | TimeOf(Subselects|Joins)FromLargeTables? |