Equals(=) vs. LIKE

后端 未结 15 2275
情书的邮戳
情书的邮戳 2020-11-22 15:19

When using SQL, are there any benefits of using = in a WHERE clause instead of LIKE?

Without any special operators, LIKE

15条回答
  •  日久生厌
    2020-11-22 15:52

    This is a copy/paste of another answer of mine for question SQL 'like' vs '=' performance:

    A personal example using mysql 5.5: I had an inner join between 2 tables, one of 3 million rows and one of 10 thousand rows.

    When using a like on an index as below(no wildcards), it took about 30 seconds:

    where login like '12345678'
    

    using 'explain' I get:

    enter image description here

    When using an '=' on the same query, it took about 0.1 seconds:

    where login ='12345678'
    

    Using 'explain' I get:

    enter image description here

    As you can see, the like completely cancelled the index seek, so query took 300 times more time.

提交回复
热议问题