SQL efficiency - [=] vs [in] vs [like] vs [matches]

后端 未结 4 2138
不知归路
不知归路 2021-02-19 09:11

Just out of curiosity, I was wondering if there are any speed/efficiency differences in using [=] versus [in] versus [like] versus [

4条回答
  •  攒了一身酷
    2021-02-19 09:35

    normally the "in" statement is used when there are several values to be compared. The engine walks the list for each value to see if one matches. if there is only one element then there is no difference in time vs the "=" statement.

    the "like" expression is different in that is uses pattern matching to find the correct values, and as such requires a bit more work in the back end. For a single value, there wouldn't be a significant time difference because you only have one possible match, and the comparison would be the same type of comparison that would occur for "=" and "in".

    basically, no, or at least the difference is so insignificant that you wouldn't notice.

提交回复
热议问题