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

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

    For the next person who runs across this - in our relatively small database the query:

    SELECT * FROM table_name WHERE field LIKE 'some-field-search-value';
    
    ... Result row
    
    Returns 1 row in set (0.00 sec)
    

    Compared to:

    SELECT * FROM table_name WHERE field LIKE BINARY 'some-field-search-value';
    
    ... Result row
    
    Returns 1 row in set (0.32 sec)
    

    Long story short, at least for our database (MySQL 5.5 / InnoDB) there is a very significant difference in performance between the two lookups.

    Apparently though this is a bug in MySQL 5.5: http://bugs.mysql.com/bug.php?id=63563 and in my testing against the same database in MySQL 5.1 the LIKE BINARY query still uses the index (while in 5.5 it does a full table scan.)

提交回复
热议问题