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

后端 未结 4 2137
不知归路
不知归路 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:56

    I will add to that also exists and subquery.

    But the performance depends on the optimizer of the given SQL engine.

    In oracle you have a lot of differences between IN and EXISTS, but not necessarily in SQL Server.

    The other thing that you have to consider is the selectivity of the column that you use. Some cases show that IN is better.


    But you have to remember that IN is non-sargable (non search argument able) so it will not use the index to resolve the query, the LIKE and = are sargable and support the index


    The best ? You should spend some time to test it in your environment

提交回复
热议问题