如果我使用 mySQL 或 Postgresql,对属性施加限制是否会缩小数据库的大小?我想这可能是一个愚蠢的问题,但我有点不熟悉数据库大小如何增加。
使用 Rails 应用限制 SQL 数据库的大小时还有哪些其他重点?
最佳答案
我猜那就是quote from the manual @mu正在寻找:
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.
我的粗体强调。
长度说明符对 text
或 varchar
类型的存储大小没有任何影响。而且根本没有任何理由使用 char(n)
,其中 n
会对存储大小产生影响。
关于mysql - 在 Rails 中限制字符串属性的大小是否会使数据库变得更小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16246418/