Does a composite index have a direction in MySQL?

When the following is required:

create index i_t_a_b on t(a,b);

create index i_t_b_a on t(b,a);
+1
source share
2 answers

If you want maximum search speed and have both columns connected or where the conditions are, BUT sometimes columns a have higher selectivity, and sometimes column b has higher selectivity, and you want to use this fact from a single index.

In addition, I think that your machine data size / performance ratio should be quite high, and at the same time you will have to (be willing) to call any improvement necessary (at least by a few percent).

, , ; .

EDIT: . wikipedia:
", , . , . ( ) , .
, , , , . , . . .

, , , ( , , ).

, .

, , , , ( , - ). , SQL-92, TOC SQL ( ). , ( ) .

, " , DISTINCT ", . ( )

, " , ", TOC

, " SELECT DML?" . ( ) , TOC DML 3 , SELECT 15 , , , , , .

, , , .:)

, , .

+2

, , .

, , a b , :

Select Max(b) From t Where a=1  --# Would use i_t_a_b

Select Max(a) From t Where b=1  --# Would use i_t_b_a

, :

a  b  c  d  e
-  -  -  -  -
0  8  x  x  x
0  9  x  x  x
1  8  x  x  x
1  9  x  x  x

i_t_a_b :

0
  8
  9
1
  8
  9

i_t_b_a :

8
  0
  1
9
  0
  1

Select Max(b) From t Where a=1

8 9 of i_t_b_a, a=1. , ( x), , i_t_a_b.

+1

Source: https://habr.com/ru/post/1738163/


All Articles