From: | Shaun Thomas <sthomas(at)townnews(dot)com> |
---|---|
To: | Martijn van Oosterhout <kleptog(at)svana(dot)org> |
Cc: | Varun Kacholia <varunk(at)cse(dot)iitb(dot)ac(dot)in>, <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Highly obscure and erratic |
Date: | 2002-06-19 14:58:30 |
Message-ID: | Pine.LNX.4.44.0206190948530.16252-100000@hamster.lee.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Wed, 19 Jun 2002, Martijn van Oosterhout wrote:
> select * from dbmedia, wdmedia a, wdmedia b
> where id = a.id and a.word='word1'
> and id = b.id and b.word='word2'
> etc
Ewww, self join. I'd actually suggest he keep the intersect, but use
the join format for each. So he'd get this:
SELECT *
FROM dbmedia d, wdmedia w
WHERE w.word = 'word1' AND d.id=w.id
INTERSECT
SELECT *
FROM dbmedia d, wdmedia w
WHERE w.word = 'word2' AND d.id=w.id
INTERSECT
...
I think you get the picture from this. If he didn't need INTERSECT to
emulate AND for his word matches, he could just use OR, and do this:
SELECT *
FROM dbmedia d, wdmedia w
WHERE w.word IN ('word1', 'word2', 'etc') AND d.id=w.id;
My guess is the OR version is faster, but he wants to restrict the data,
not add to it. Unfortunate. ^_^
> and avoid IN, INTERSECT and UNION at all costs.
Actually, if INTERSECT and UNION are done properly (which I'm guessing
they are) at most, the query has to be run once for each distinct query
between the INTERSECT/UNION clauses. On a fast/small query, an upper
bound of doubling execution time isn't too bad. Mathematical matrix
intersections and unions are pretty fast/easy, so that doesn't add much
overhead at all.
It's IN you have to avoid. The way postgres does it is just insane, and
you'll suffer greatly upon using it.
--
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
| Shaun M. Thomas INN Database Administrator |
| Phone: (309) 743-0812 Fax : (309) 743-0830 |
| Email: sthomas(at)townnews(dot)com AIM : trifthen |
| Web : www.townnews.com |
| |
| "Most of our lives are about proving something, either to |
| ourselves or to someone else." |
| -- Anonymous |
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
From | Date | Subject | |
---|---|---|---|
Next Message | Arguile | 2002-06-19 15:01:32 | Re: what different beetwen "begin work; " and "begin transaction; " ???? |
Previous Message | Roderick A. Anderson | 2002-06-19 14:54:55 | Re: Pg 7.2B5 -> 7.2.1 |