Your skill will accomplish what the force of many cannot |
|
PerlMonks |
[OT] Database row width and cargo cult programmingby moritz (Cardinal) |
on Apr 06, 2011 at 10:25 UTC ( [id://897723]=perlquestion: print w/replies, xml ) | Need Help?? |
moritz has asked for the wisdom of the Perl Monks concerning the following question: This is a bit off-topic here, because it has no Perl contents, but I still hope you find the question interesting. I've seen many database column definitions using VARCHAR(255), or other powers-of-two-minus-1 values as the column width. I even caught myself writing this. I presume this is because then length fits into one unsigned byte, and thus think it's significantly less wasteful in terms of space than when using VARCHAR(256). Is that actually still the case in modern RDMBs? Or are there are other good reasons for chosing numbers of the form 2**$int - 1? The longer I think about it, the more I expect it to be just cargo cult programming, carried over from the early days of relational databases. After all, when a VARCHAR allows arbitrary Unicode characters, the maximal byte width is four times the character count (for UTF-8, UTF-16 and UTF-32), so a character length of 255 won't lead to a byte length that fits into a byte. Also I'd expect postgresql, sqlite and consorts to just store the widht in a native (or maybe 64bit) unsigned it. So, is it a cargo cult? Or is there still a deeper reason for those special widths?
Back to
Seekers of Perl Wisdom
|
|