Indexes are optional in MySQL, but they can improve performance.
Currently, MySQL can use only one index to select a table, so with this query, if you have an index for columns1 and column2, MySQL will try to determine the index that will be most useful and use only one.
The general solution, if speed of choice is paramount, is to create an index with multiple columns that includes both columns.
Thus, while MySQL can only use one index per table, it will use a multi-column index that is indexed by both columns, which allows MySQL to quickly filter both criteria in the WHERE clause.
In an index with multiple columns, you must first put the column with the highest power (the largest number of different values).
For even greater optimization, in some cases, covering indexes can be used.
Note that indexes can improve performance, but at some cost. Indexes increase memory and storage requirements. In addition, when updating or inserting records into a table, the corresponding indexes require maintenance. All of these factors should be considered when implementing indexes.
Update: MySQL 5.0 can now use an index in more than one column, combining the results of each index with several caveats.
The following query is a good candidate for optimizing index merging :
SELECT * FROM t1 WHERE key1=1 AND key2=1