mysql binary comparison doesnt use index

前端 未结 2 1931
我在风中等你
我在风中等你 2021-01-13 06:02

I have the following query:

EXPLAIN EXTENDED SELECT *
FROM (
`photo_data`
)
LEFT JOIN `deleted_photos` ON `deleted_photos`.`photo_id` = `photo_data`.`photo_i         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-13 07:03

    MySQL uses the collation of the column for the index. An index with a non-binary collation isn't useful for a binary lookup since the order might be different.

    You could change the column itself to binary collation:

    ALTER TABLE YourTable MODIFY
       YourColumn VARCHAR(4)
       CHARACTER SET latin1
       COLLATE latin1_bin;
    

    Then the index would be useful for a binary lookup.

提交回复
热议问题