2 Selects 1 is faster, why? - Mailing list pgsql-sql

From Eric
Subject 2 Selects 1 is faster, why?
Date
Msg-id afag3c$kce$1@news.hub.org
Whole thread Raw
Responses Re: 2 Selects 1 is faster, why?  (Alvar Freude <alvar@a-blast.org>)
List 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






pgsql-sql by date:

Previous
From: "Ian Cass"
Date:
Subject: Quickest way to insert unique records?
Next
From: "Eric"
Date:
Subject: Performance Ideas