Does the order of fields in a WHERE clause affect performance in MySQL?

后端 未结 3 870
礼貌的吻别
礼貌的吻别 2020-12-04 23:17

I have two indexed fields in a table - type and userid (individual indexes, not a composite).

types field values are very lim

3条回答
  •  半阙折子戏
    2020-12-05 00:00

    It shouldn't in your small example. The query optimizer should do the right thing. You can check for sure by adding explain to the front of the query. MySQL will tell you how it's joining things together and how many rows it needs to search in order to do the join. For example:

    explain select * from table where type=1 and userid=5

    If they were not indexed it would probably change behavior.

提交回复
热议问题