| From: | "Eric" <emayo(at)pozicom(dot)net> |
|---|---|
| To: | pgsql-sql(at)postgresql(dot)org |
| Subject: | 2 Selects 1 is faster, why? |
| Date: | 2002-06-25 19:25:32 |
| Message-ID: | afag3c$kce$1@news.hub.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
If I perform the following 2 selects, the first one is EXTREMELY slow where
the 2nd one is very fast.
(1) Slow
select
o.orderid,
ol.itemcode,
ol.itemname
from
orders o,
orlines ol
where
o.orderid = '1234' and
ol.orderid = o.orderid;
(2) VERY FAST
select
o.orderid,
ol.itemcode,
ol.itemname
from
orders o,
orlines ol
where
o.orderid = '1234' and
ol.orderid = '1234'
Why would 2 be so much faster? I have ran the EXPLAIN on this and index
scans are being used.
NOTE: The actual queries return more information than this, but the
fundamental change shown above seems to give me the instant response I am
looking for. (1) takes about 60 seconds to run and (2) takes 3-5 seconds to
run.
Thanks, Eric
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Eric | 2002-06-25 19:37:39 | Performance Ideas |
| Previous Message | Bruno Wolff III | 2002-06-25 18:45:58 | Re: unique index on function and column |