Friday, February 27, 2009

MySql Subquerys Are Molasses

Just a quick note on an issue I ran into today.

When using MySql, if you have a query that looks like this:

Select A, B
From table
where A in (Select C, D From AnotherTable)

Even when the subquery returns a very small resultset, the overall query will slow to a crawl, if it completes at all. This is because of how mysql handles the "in" statement. The only way to really get around it is just to join the two queries and filter, which isn't terrible, though I hope a situation comes up where this solution is untenable.

No comments: