Skip site navigation (1) Skip section navigation (2)

Re: subquery vs join on 7.4.5

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: subquery vs join on 7.4.5
Date: 2005-02-23 16:54:52
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-performance
David Haas <dave(at)modelpredictivesystems(dot)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

In response to

pgsql-performance by date

Next:From: G u i d o B a r o s i oDate: 2005-02-23 17:50:16
Subject: Re: Problem with 7.4.5 and webmin 1.8 in grant function
Previous:From: Tom LaneDate: 2005-02-23 16:44:15
Subject: Re: Inefficient Query Plans

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group