Muhammad Imran Tariq
Muhammad Imran Tariq

Reputation: 23352

DB2 Varchar field length

I am confused whether to choose varchar length of 255 or 256 for a varchar field in DB2.

What will be a good size for performance? From my search on google it looks like 255 is best because it's equal to 1 byte. Which is right? Does varchar(255) require 1 byte or does varchar(256) require 1 byte.

Upvotes: 3

Views: 4736

Answers (1)

AngocA
AngocA

Reputation: 7693

Personally, I think that reading one byte or two bytes for a variable length column will not create a lot of impact. The fact that this length will be used to analyze how many characters to read in a row is more penalizing (two operations, one for quantity and one for data).

You could think that one extra byte in for example a table with one million records is a lot of unnecessary disk space, but with the compression feature activated this is not really a concern related to Storage (IO) nor with processing (CPU).

By the way: 255 = 11111111 (one byte) 256 = 100000000 (two bytes)

The only recommendation is to use a varchar for columns with more that 30 characters, otherwise the best is to use a fix length column CHAR, because the overhead of reading the length plus the data is a lot comparing the quantity of data to read when few characters. ( http://www.ibm.com/developerworks/data/library/techarticle/dm-0404mcarthur/ )

Upvotes: 6

Related Questions