MySQL binary against non-binary for hash IDs

前端 未结 2 1041
别跟我提以往
别跟我提以往 2021-02-02 10:05

Assuming that I want to use a hash as an ID instead of a numeric. Would it be an performance advantage to store them as BINARY over non-binary?

CREA         


        
2条回答
  •  攒了一身酷
    2021-02-02 10:15

    From the manual:

    The BINARY and VARBINARY types are similar to CHAR and VARCHAR, except
    that they contain binary strings rather than non-binary strings. That is,
    they contain byte strings rather than character strings. This means that
    they have no character set, and sorting and comparison are based on the
    numeric values of the bytes in the values. 
    

    Since CHAR(32) BINARY causes a BINARY(32) column to be created under the hood, the benefit is that it will take less time to sort by that column, and probably less time to find corresponding rows if the column is indexed.

提交回复
热议问题