假设:
>字符串的长度与应用程序无关.
>你不在乎有人把最大的大小放在数据库中
>你有无限的硬盘空间
它提到:
The storage requirement for a short string (up to 126 bytes) is 1 byte
plus the actual string,which includes the space padding in the case
of character. Longer strings have 4 bytes of overhead instead of 1.
Long strings are compressed by the system automatically,so the
physical requirement on disk might be less. Very long values are also
stored in background tables so that they do not interfere with rapid
access to shorter column values. In any case,the longest possible
character string that can be stored is about 1 GB. (The maximum value
that will be allowed for n in the data type declaration is less than
that. It wouldn’t be useful to change this because with multibyte
character encodings the number of characters and bytes can be quite
different.
这涉及字符串的大小,而不是字段的大小(也就是说,它听起来总是压缩大的varchar字段中的大字符串,而不是一个大的varchar字段中的一个小字符串)
我问这个问题,因为它更容易(和懒惰)指定一个更大的大小,所以你不必担心字符串太大.例如,如果我为地名指定了varchar(50),我将获得具有更多字符的位置(例如Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch),但是如果我指定varchar(100)或varchar(500),则我不太可能得到这个问题.
那么如果你最大的字符串是400字符长,你会得到varchar(500)和(任意的)varchar(5000000)或者text()之间的性能?
如果有人有这个答案也感兴趣,并且知道其他数据库的答案,请添加.
我已经google了,但没有找到一个足够的技术性的解释.
解决方法
关于这件事的一些链接
> VARCHAR(n) Considered Harmful
> CHAR(x) vs. VARCHAR(x) vs. VARCHAR vs. TEXT
> In Defense of varchar(x)