Home  >  Q&A  >  body text

php - In mysql, is it more efficient to use int type as a primary key field than char type?

In mysql, is it more efficient to use int type as a primary key field than char type?

Due to business requirements, it is necessary to use a timestamp and a 2-digit random number to form the ID.
For example: 149561542040, a total of 12 digits.
If the ID field uses integer bigint, will it be more efficient than using char?

黄舟黄舟2705 days ago758

reply all(2)I'll reply

  • 黄舟

    黄舟2017-05-25 15:10:20

    In terms of space, BIGINT occupies 8 bytes and CHAR occupies 12 bytes.
    The difference is obvious in massive data. In terms of efficiency, INT is more efficient

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-25 15:10:20

    Personally, I feel there is a difference in efficiency.
    Integer types have efficient methods for sorting and searching.
    Char should be much weaker

    reply
    0
  • Cancelreply