Frage

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)

War es hilfreich?

Lösung

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

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

Andere Tipps

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
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top