query with subquery abnormally slow?

Поиск
Список
Период
Сортировка
I'm doing a SELECT query with a subquery on a table with 12K rows
but it is very slow (10 seconds+). The query looks like this:
 select *   from items   where package in     (select package        from items        where ...blah...        group by
package)

Where package is an indexed varchar field.

The subquery generates 50 rows, and completes quickly when I run
it alone. Now if I manually replace the subquery with these 50
strings - like
 select *   from items   where package in     ('r1', 'r2', 'r3', .., 'r50')

this new query completes in less than a second. The result
of the complete query is 500 rows.

Is this natural? Is there anything I can do to speed things up?
(Besides doing N+1 queries where N is the number of rows the
subquery would produce.)

Oskar Liljeblad (osk@hem.passagen.se)


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

Предыдущее
От: Darrin Crook
Дата:
Сообщение: Re: [SQL] auto datetime update on UPDATE?
Следующее
От: Oskar Liljeblad
Дата:
Сообщение: Re: [SQL] query with subquery abnormally slow?