pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Eric <emayo@pozicom.net>
To: pgsql-sql@postgresql.org
Subject: 2 Selects 1 is faster, why?
Date: Tue, 25 Jun 2002 15:25:32 -0400
Message-ID: <afag3c$kce$1@news.hub.org> (raw)

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







view thread (5+ messages)  latest in thread

Message-ID: <afag3c$kce$1@news.hub.org>
Permalink:  ../afag3c$kce$1@news.hub.org/
Also on:    postgresql.org/message-id/afag3c$kce$1@news.hub.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: emayo@pozicom.net
  Subject: Re: 2 Selects 1 is faster, why?
  In-Reply-To: <afag3c$kce$1@news.hub.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox