0

My question is really simple:

Is there any performance penalization if I use a (VAR)CHAR (let's say 5) instead of an INT in a MySQL + InnoDB database. If there is, why?

Extra question: If I had to use (VAR)CHAR as PK, what should I use: CHAR or VARCHAR? And why?

alexandernst
  • 14,352
  • 22
  • 97
  • 197
  • @rambocoder No, my question is absolutely not the same. I'm not asking about a natural key. I'm asking about the usage of VARCHAR with completely random data. – alexandernst May 05 '14 at 00:09
  • a varchar with random data vs a random int? at the simplest form, you have a data size penalty for character data 5 bytes for 5 non-Unicode characters or 4 bytes for an integer. The more rows that can fit onto a page, the better it should perform. My experience is more with SQL Server, so I will leave the answering up to a MySQL expert. – attila May 05 '14 at 00:34
  • CHAR(5) would easily fit in a 3 byte `MEDIUMINT`. If the data gets large, more of the binary representation would stay in memory at a time. – Joshua Martell May 05 '14 at 01:49

0 Answers0