The use of multi-column index

 

index

  * Multiple separate index, the index can only use one of them

  1, the index btree Common Mistakes

    In the commonly used where conditions columns plus index

    Example: where cat_id = 3 and price> 100; // query third columns, more than $ 100 of goods

    Error: cat_id on price and still are indexed and

    Wrong: You can only spend cat_id or price index, because a separate index, while only spend 1

 

  2, after the index on multiple columns, the query which column, the index will play a role

  Error: the multi-column index, which play a role, need to meet the requirements of left-prefix

Statement The index is to play a role
Where a=3 Yes
Where a=3 and b=5 Yes
Where a=3 and b=5 and c=4 Yes
Where b=3 或 where c=4 no
Where a=3 and c=4 can play a column index, c is not
Where a=3 and b>10 and c=7 A can use, b can use, c can not use
同上,where a=3 and b like 'xxxx%' and c=7 Available A, B can, C can not be used

    Example:

      A: where c1 = x and c2 = x and c4> x and c3 = x // all spend

      B:where c1=x and c2=x and c4=x order by c3  // c1,c2,c3用上了

      C: where c1 = x and c4 = x group by c3, c2 // c1 spend

      D: where c1 = and c5 = order by c2, c3 // c1, c2, c3 spend??

      E: where c1 = and c2 = and c5 = order by c2, c 3 // c1, c2, c3 spend???

Guess you like

Origin www.cnblogs.com/longqin/p/11655686.html