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

后端 未结 3 799
失恋的感觉
失恋的感觉 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:39

    If performance seems to become a problem, it might be a good idea to create a copy of the first eg. 255 characters of the longtext, add an index on that and use the startswith with that.

    BTW, this page says: "if you need to do case-sensitive matching, declare your column as BINARY; don't use LIKE BINARY in your queries to cast a non-binary column. If you do, MySQL won't use any indexes on that column." It's an old tip but I think this is still valid.

提交回复
热议问题