query with subquery abnormally slow?
| От | Oskar Liljeblad |
|---|---|
| Тема | query with subquery abnormally slow? |
| Дата | |
| Msg-id | 19991101194707.A7034@oskar обсуждение исходный текст |
| Ответы |
Re: [SQL] query with subquery abnormally slow?
Re: [SQL] query with subquery abnormally slow? Re: [SQL] query with subquery abnormally slow? Re: [SQL] query with subquery abnormally slow? |
| Список | pgsql-sql |
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 по дате отправления: