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?


In reply to [OT] Database row width and cargo cult programming by moritz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.