This question is about comparing of query optimization -vs- server performance. So I hope this question could be posted at this forum as well.
As I understand, the PRIMARY (but not a single) reason to optimize queries is to make a server work faster.
So, are there any difference for the server between: query optimization, so it gives +50% of performance -vs- moving a web-site to another hosting provider with servers that are 1.5 times faster.
(of course, we can do both, but time counts as well, and moving to another hosting looks much much easier way).
It depends on what you mean by “faster”. It doesn’t matter at all if the CPUs in your faster box run at ten times the speed of the slower one if the bottleneck is actually disk.
Extreme example, say you have a table with no indexes at all so that all queries have to do a full table scan. This will almost certainly make the disk the bottleneck as you have to load the entire table into memory (though not necessarily all at the same time) to select the relevant rows.
If you transfer this inefficient query to a box with gruntier CPUs but similar disks, you won’t see much of an improvement.
However, if you add an index that allows you to only process 0.01% of the full table, you’ll get a big performance increase without faster CPUs.
By all means investigate moving to another host but I think you’ll probably find that it’s easier to analyse the slower queries and figure out which indexes to add to speed them up.
Executing an
alter table ... create index ...statement seems to me to be much simpler than shifting the workload.Just make sure that, whatever you do, you measure the impact. Without metrics before and after, optimisation is doomed to failure: in other words, measure, don’t guess!