Re: subquery vs join on 7.4.5

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: subquery vs join on 7.4.5
Дата
Msg-id 20117.1109177692@sss.pgh.pa.us
обсуждение исходный текст
Ответ на subquery vs join on 7.4.5  (David Haas <dave@modelpredictivesystems.com>)
Список pgsql-performance
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

В списке pgsql-performance по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Inefficient Query Plans
Следующее
От: G u i d o B a r o s i o
Дата:
Сообщение: Re: Problem with 7.4.5 and webmin 1.8 in grant function