Difference between 2 indexes with columns defined in reverse order

后端 未结 5 1957
梦毁少年i
梦毁少年i 2021-01-02 04:07

Are there any differences between following two indexes?

  • IDX_IndexTables_1
  • IDX_IndexTables_2

If there are any, what are the difference

5条回答
  •  误落风尘
    2021-01-02 04:39

    Other folk have answered that they are different, and I agree.

    I'll add some other thoughts though...

    • the (col1, col2) index means you don't need an index on col1 alone
    • the (col2, col1) index means you don't need an index on col2 alone
    • the order matters if this is covering (eg WHERE on col1, SELECT col2)
    • the direction (ASC/DESC) also matters (Other question 1, Other question 2)

提交回复
热议问题