且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在数据库表中存储整数或字符串之间的差异

更新时间:2022-05-01 01:59:36

我认为你***的赌注是更快的性能,更少的存储空间和可读性是使用CHAR(1) - (p)发布,挂起(r)eview和(d)raft。您可以使用CHECK约束或外键引用验证数据。

I think your best bet for faster performance, less storage space, and readability is to use CHAR(1)--(p)ublished, pending (r)eview, and (d)raft. You can validate that data with either a CHECK constraint or a foreign key reference.

CHAR(1)比整数占用的空间少得多。它是直接可读的人类,所以它不需要一个连接来了解它。由于它既小又立即可读,因此即使在数千万行的表上,也能获得比整数连接更快的检索。

CHAR(1) takes substantially less space than an integer. It's directly readable by humans, so it doesn't need a join to understand it. Since it's both smaller and immediately readable, you'll get faster retrieval than a join on an integer even on a table of tens of millions of rows.