I am using MySQl database.
I know if I create a index for a column, it will be fast to query data from a table by using that column index. But, I still have the following questions:
(suppose I have a table named cars, there is a column named country, and I have created index for country column)
-
I know for example the query
SELECT * FROM cars WHERE country='japan'will use the index on column country to query data which is fast. How about!=operation? willSELECT * FROM cars WHERE country!='japan';also use index to query data? -
Does
WHERE ... IN ...operation use index to query data? For exampleSELECT * FROM cars WHERE country IN ('japan','usa','sweden');
You can use
EXPLAIN SELECTto find out if your query uses an index or not.For example:
Might yield:
In this case, the query had no
possible_keysand therefore used nokeyto do the query. It’s thekeycolumn you’d be interested in.More information here: