MySQL: the difference between `... ADD INDEX (a); ... ADD INDEX (b); `and` ... ADD INDEX (a, b); `?

Can someone tell me what is the difference between the two:

ALTER TABLE x1 ADD INDEX(a);
ALTER TABLE x1 ADD INDEX(b);

and

ALTER TABLE x1 ADD INDEX(a,b);

I know that it boils down to the very basics, but sometimes I find that the former seems a little faster than the latter. Is it just my feeling or is there some actual reason for this?

+2
source share
3 answers

When using the second option, the following query will not use the index:

SELECT * FROM x1 WHERE b = 'something';

, . , . ( ) , .

: - :

+2

INDEX "a" "b" . , "a" "a" AND "b" .

, "b" SQL.

- .

"a" "b" "b" , .

, , , . . , .

: , INDEX (a, b) INDEX (b, a), . , . .

, NAME SEX INDEX (NAME, SEX), , (es?).

+4

INDEX(a,b)will speed up the search aor aand b, but not b, while the first ( INDEX(a)... INDEX(b)) will work in all cases.

+3
source

All Articles