为什么mysql有很多不同的字段类型?
既然数据被分类为 int、decimal、text(string)、date、enum,为什么 mysql 还需要将它们分类更多的组,就像文本分为 char、varchar、text、tinytext 等?我知道这会让它更快,但是分类到更多组和让它更快之间有什么关系呢?原因是什么?
抱歉我的英语不好。
Since data is categorized as int, decimal, text(string), date, enum, Why mysql still need to categorized them into more groups like text is seperated into char, varchar, text, tinytext, etc? I knew this would make it faster, but what is the relation between categorized into more groups and making it faster? What is the reason?
Sorry for my poor english.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那么背后的主要原因是内存。看到地址是一个文本信息,名称是一个文本信息,如果你想存储任何值像
yes
和no
也是一个文本值,如果你想取来自任何人的评论或帖子也是一个text
值。所有这些价值观都需要不同的记忆。当您谈论大型系统时,内存是一个重要因素。例如,如果您为所有文本信息设置text
类型,那么这是一种非常糟糕的做法。所以mysql已经分为不同的东西了。就像如果你想存储名称,你可以使用varchar(50)
,如果你想存储地址,你甚至可以使用varchar(255)
。如果您想存储帖子或评论和描述或任何内容,您可以使用text
。如果您想使用yes
和no
之类的信息,您可以使用char
。我希望你明白。Well the main reason behind is the memory. See the address is a text information, name is a text information, if you want to store any value like
yes
andno
is also a text value, If you want to take the comment or post from any one it is also atext
value. All these values needs different memories. When you talk about large system then memory is an important factor. For example if you settext
type for all text information it is highly a bad practice. So mysql has classified into different things. Like if you want to store the name you can usevarchar(50)
, if you want to store address you can even usevarchar(255)
. If you want to store the post or comment and description or any thing you can usetext
. If you want to useyes
andno
like information you can usechar
. I hope you understood.字符串类型的变体数量是进步的标志。在理想的世界中,旧的类型将被删除,新的和改进的类型将取代它们。但是,在现实世界中,传统兼容性要求字段类型的行为类似于 20 世纪 60 年代的 COBOL 字符串处理,以供需要它的应用程序使用。因此,
char(20)
类型会填充尾随空格,就像 IBM 按键卡一样。将各种子类型视为一组螺丝刀,有些小,有些大。每种方法的适用范围都很窄。如果您正在修理怀表,则不需要大螺丝刀。但如果应用是桥梁建设,那么微型精密螺丝刀就不会使用,而会使用大螺丝刀。数据库很像这样。
The number of variations for character string types is the sign of progress. In an ideal world, the old types would be removed and the new and improved types would replace them. But, in the real world, legacy compatibility requires fields types to, for example, behave like 1960s COBOL string handling for applications which expect it. So the
char(20)
type pads with trailing spaces to act like an IBM keypunch card.Think of the various subtypes as a set of screwdrivers, some small, some big. Each has a narrow range of appropriate use. If you are working on a pocket watch, the big screwdrivers won't be needed. But if the application is bridge building, then the micro precision screwdrivers remain unused and the big ones get used. Databases are a lot like that.