Order of index on multiple columns

前端 未结 3 871
我在风中等你
我在风中等你 2021-02-12 11:29

Just a simple question, but does the order of your index matter when it spans over multiple columns?

For example, taking the query:

SELECT * FROM my_table WHE         


        
3条回答
  •  攒了一身酷
    2021-02-12 12:30

    In the example you give, the column order does not matter.

    It would matter if you order on a column; an index on (col1,col2) can be used for ORDER BY col1, col2 but not for ORDER BY col2, col1.

    For WHERE clauses, an index on (col1, col2) works for WHERE col1 = 1 AND col2 = 1. It also works for WHERE col1 = 1. But it can't help with WHERE col2 = 1.

提交回复
热议问题