pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-performance@postgresql.org
Subject: Re: subquery vs join on 7.4.5
Date: Wed, 23 Feb 2005 11:54:52 -0500
Message-ID: <20117.1109177692@sss.pgh.pa.us> (raw)
In-Reply-To: <c679b0baf63d8583e90ef487c038e5c2@modelpredictivesystems.com>
References: <c679b0baf63d8583e90ef487c038e5c2@modelpredictivesystems.com>

David Haas <dave@modelpredictivesystems.com> writes:
> I'm comparing the speeds of the following two queries on 7.4.5.  I was  
> curious why query 1 was faster than query 2:

> query 1:
> Select layer_number
> FROM batch_report_index
> WHERE device_id = (SELECT device_id FROM device_index WHERE device_name  
> ='CP8M')
> AND technology_id = (SELECT technology_id FROM technology_index WHERE  
> technology_name = 'G12');

> query 2:
> Select b.layer_number
> FROM batch_report_index b, device_index d, technology_index t
> WHERE b.device_id = d.device_id
> AND b.technology_id = t.technology_id
> AND d.device_name = 'CP8M'
> AND t.technology_name = 'G12';

Why didn't you try a two-column index on batch_report_index(device_id,
technology_id) ?

Whether this would actually be better than a seqscan I'm not sure, given
the large number of matching rows.  But the planner would surely try it
given that it's drastically underestimating that number :-(

			regards, tom lane



view thread (2+ messages)

Message-ID: <20117.1109177692@sss.pgh.pa.us>
Permalink:  ../20117.1109177692@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/20117.1109177692@sss.pgh.pa.us

 · 

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-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: subquery vs join on 7.4.5
  In-Reply-To: <20117.1109177692@sss.pgh.pa.us>

* 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