Re: Speed or configuration

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Speed or configuration
Дата
Msg-id 10681.966794490@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Speed or configuration  ("Franz J Fortuny" <ffortuny@ivsol.com>)
Список pgsql-sql
"Franz J Fortuny" <ffortuny@ivsol.com> writes:
> [ this query is slow: ]
> select xx1,xx2,xx3 from tableX
> where field1 in
> (select field1 from tableY where
> field2=NNN and field3=NNN2 and field4=NNN4)

What version of Postgres are you using, and what does EXPLAIN show
as the query plan for this query?  How many tableY rows is the sub-
query likely to produce, and how many matches do you expect to get
from tableX?

The Postgres planner is not currently very smart about optimizing
sub-SELECTs.  We hope to do something about that by 7.2 or so,
but in the meantime you should look at transforming the query to
some other form.  You might find that EXISTS will help: select xx1,xx2,xx3 from tableX where exists (select 1 from
tableYwhere field1=tableX.field1 and field2=NNN and field3=NNN3 and field4=NNN4)
 
However this is unlikely to help much unless you change the index
structure for tableY.  Perhaps you could write it as a join: select xx1,xx2,xx3 from tableX, tableY where
tableX.field1=tableY.field1and field2=NNN   and field3=NNN3 and field4=NNN4
 
although this won't give quite the same results if there can be multiple
matching rows in tableY for a tableX row.  (DISTINCT might help if so.)
        regards, tom lane


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

Предыдущее
От: The Hermit Hacker
Дата:
Сообщение: Re: Speed or configuration
Следующее
От: Stephan Szabo
Дата:
Сообщение: Re: Speed or configuration