Some optimizations can be done independently of whether indexes are used. A simple but effective technique is to reduce the amount of output a query produces. One way to eliminate unnecessary output is by using a LIMIT clause. If you don't need the entire result set, specify how many rows the server should return by including LIMIT in your query. This helps two ways:
Another way to limit query output is by selecting only the columns you need, rather than using SELECT * to retrieve all columns. Suppose you want information about countries having names that begin with M. The following query produces that information: SELECT * FROM Country WHERE Name LIKE 'M%'; However, if all you really want to know is the country names, don't write the query like that. Most of the information retrieved will be irrelevant to what you want to know, resulting in unnecessary server effort and network traffic. Instead, select only the Name column: SELECT Name FROM Country WHERE Name LIKE 'M%'; The second query is faster because MySQL has to return less information to the client when you select just one column rather than all of them. In addition, if an index on Name exists, you get even more improvement for two reasons:
blog comments powered by Disqus |