Reputation: 10780
I had a friend tell me that never to declare varchar as (255) if we will be only using 20 characters. Same for an INT.
Performance wise, Is this true ? Can i achieve a performance gain by reducing the size of my columns ? What exactly happens when i declare a column as 255 ?
Upvotes: 1
Views: 74
Reputation: 4329
Using TINYINT
instead of INT
if you only need the size of a TINYINT
will save a few bytes per row.
A VARCHAR(255)
will not use more then a VARCHAR(20)
if you always only use 20 characters ( CHAR(255)
on the other hand might use more then CHAR(20)
)
Upvotes: 1
Reputation: 30111
In most cases there will be no performance gain with shorter VARCHAR
columns.
1 of the cases where there will be a performance gains, If you have a MEMORY
table - a in memory temp table, MySql will allocate memory for the length of the column.
From the docs:
MEMORY tables use a fixed-length row-storage format. Variable-length types such as VARCHAR are stored using a fixed length.
Upvotes: 2