mysql - 在 Rails 中限制字符串属性的大小是否会使数据库变得更小?

标签 mysql sql ruby-on-rails ruby-on-rails-3 postgresql

如果我使用 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.

我的粗体强调。

长度说明符对 textvarchar 类型的存储大小没有任何影响。而且根本没有任何理由使用 char(n),其中 n 会对存储大小产生影响。

关于mysql - 在 Rails 中限制字符串属性的大小是否会使数据库变得更小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16246418/

相关文章:

php - 从表中获取多个条目并添加它们

MySQL 查询返回每个月之前创建的所有行

php - MySQL 如果没有记录则添加记录

php - 如何制作 n :1 multiple tags system for a blog & which database schema is better?

ruby-on-rails - 如何在 Rails 3 中路由多级嵌套资源?

mysql - 运行 Rspec 时 ActiveRecord 无法连接到数据库服务器

ruby-on-rails - 安装 Mongoid 后使用 Active Record 生成器?

PHP日期和时间,获取一个月的第1、2、3、4周

sql - 选择过去 24(N) 个月的第一个日期

sql - 递归 SQL 给出 ORA-01790