BIGINT mysql performance compared to INT

后端 未结 2 1288
南方客
南方客 2020-12-08 00:37

I\'m trying to find out if my table will get less performant if I change the primary key to BIGINT(20). At the moment, I\'m using INT(7) and have about 300.000 entri

2条回答
  •  天涯浪人
    2020-12-08 00:54

    Not wishing to resurrect a zombie, but 'modern' mysql uses the column type serial, which is a bigint(20) unsigned NOT NULL AUTO_INCREMENT - and certainly suggests that mysql will be (or is) going to be optimised for using bigint as a primary key.

    Also, rather than using serial, bigint primary allows for one (we do this) to use uuid_short() for the primary key (not uuid – which is very slow to use as a primary, because it's a string) - which has the feature of ensuring that every record has a key which is unique across the entire database (indeed - network).

    But be aware - some coercion’s will degrade bigint to int with bad results. If, for instance, you are comparing a string representation with a big int - you may find that you get false positives. So one must compare using binary... eg

    where id = binary id_str
    

    Personally I would call this an unfixed bug...

提交回复
热议问题