Decimal VS Int in MySQL?

前端 未结 4 709
名媛妹妹
名媛妹妹 2020-12-31 14:00

Are there any performance difference between decimal(10,0) unsigned type and int(10) unsigned type?

4条回答
  •  感动是毒
    2020-12-31 14:23

    According to the mysql data storage your decimal will require

    DECIMAL(10,0): 4 bytes for 9 digits and 1 byte for the remaining 10th digit, so in total five bytes (assuming my reading of documentation is correct).

    INT(10): will need BIGINT which is 8 bytes.

    The differences is that the decimal is packed and some operations on such data type might be slower then on normal INT types which map directly to machine represented numbers.

    Still I would do your own tests to confirm the above reasoning.

    EDIT: I noticed that I did not elaborate on the obvious point - assuming the above logic is sound the difference in size required is 60% more space needed for BIGINT variant.

    However this does not directly translate to penalties due to the fact that data is normally not written byte by byte. In case of selects/updates of many rows you should see the performance loss/gain, but in case of selecting/updating a small number of rows the filesystem will fetch blocks from the disk(s) which will normally get/write multiple columns anyway.
    The size (and speed) of indexes might be more directly impacted. However, the question on how the packing influences various operations still remains open.

提交回复
热议问题