Question

If I make the following index on InnoDB table:

CREATE INDEX index_name on table_name (col1, col2)

and perform this select query:

SELECT col2 FROM table_name WHERE col1=some_value

will MySQL retrieve col2 straight from index?

(What I'm trying to achieve is to drastically speed up the selection process)

Was it helpful?

Solution

It should. That's called index-only scan.

But to be sure, you should examine the query execution plan.

OTHER TIPS

I don't think MySQL will use index automatically, though SQLite will do. Try:

SELECT col2 FROM table_name use index (col1,col2) WHERE col1=some_value
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top