Friday, August 28, 2009
MySQL views are terrible
I’ve been working with MySQL a bit lately, and that’s only because that’s the database offered by my webhost. So far, I’ve seen two huge limitations, and both involves views (my preferred process).
The first is doing a left join rather than an inner join. Even though the number of returned records were virtually identical, turning the outer into an inner changed the run time from 51 seconds to 0.3 seconds. It was a pretty basic view.
The second one is joining a table to a view. It seems that the view doesn’t use any of the underlying tables’ indexes. So, what I’m left with is merging a 100,000 row indexed table to a 3000 row view, and it’s doing the join without the use of nay index. Even MsAccess is faster.
Suggestions?


As I’m reading about MySQL, I should point out that one of the tables in the view is the same as the table it’s joining to. It looks like this:
create or replace view abc as
select ...
from a,b,c
...
select ...
from abc, a
...
It looks like I need to specify “algorithm”. Note that my view has a group by and a sum.