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)