lundi 13 juin 2016

What happens when I create an index on a column?

I asked multiple question about indexes already. Something like this:

Would following queries benefit from this index? mytable(col1, col2, col3)

. . . WHERE col1 = ? AND col3 = ?
. . . WHERE col2 = ?
. . . WHERE col1 IN (?, ?)
. . . WHERE col3 = ? AND col1 NOT IN (?, ?)
. . . WHERE col1 = ? OR col2 = ?
. . . WHERE col2 = ? AND col1 = ?
. . . WHERE col1 = ? AND col2 > ?
. . . WHERE col1 = ? AND col3 > ?

-- each question was containing one of these queries ;-)

Every time I got an answer for that specific query which was mentioned in that question, and still I cannot judge such a index would be useful for such a query or not. (or how making it more optimal)

So I decided to ask this question and want to know about the backstage. What happens when I create an index on a column? An index is made of what? An multiple column index is containing what rows (because order is important)? How it works which causes a query much faster?

Actually I need some information about indexes to make me able how can I determine a proper index (multiple columns or single column) for a query.

Note: I have some experiences to work with EXPLAIN. And yes I know using EXPLAIN is really useful in these cases. Now I just need some further information.

Aucun commentaire:

Enregistrer un commentaire