SQL 'LIKE BINARY' any slower than plain 'LIKE'?

后端 未结 3 798
失恋的感觉
失恋的感觉 2021-01-05 17:07

I\'m using a django application which does some \'startswith\' ORM operations comparing longtext columns with a unicode string. This results in a LIKE BI

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-05 17:26

    A trick: If you don't want to change the type of your column to binary, try to write your ‍WHERE statement like this:

    WHERE field = 'yourstring' AND field LIKE BINARY 'yourstring'
    

    instead of:

    WHERE field LIKE BINARY 'yourstring'
    

    Indeed, it will check the first condition very quickly, and try the second one only if the first one is true.

    It worked well on my project for this test of equality, and I think you can adapt this to the "starts with" test.

提交回复
热议问题