数据库可变长度文本字段是否为2的幂? [英] Should database variable-length text fields be powers of 2?
问题描述
我的一个朋友声称,在典型的数据库中,使用 nvarchar [256]
会比 nvarchar 200]
或 nvarchar [250]
。
A friend of mine claims that in a typical database, using (for example) nvarchar[256]
will give marginally better performance than nvarchar[200]
or nvarchar[250]
because of the granularity of page allocations.
谢谢!
推荐答案
这不是真的。表在磁盘上以8k页分配。当从磁盘读取表时,整个页在一个IO操作中读取并存储在存储器中。因此,列的长度将不会影响内存对齐。事实上,对于非可变长度的数据类型,更短的肯定更好:nchar(200)列将允许每页比nchar(256)列更多的行。这样,每个物理IO可以读取更多行,这会对数据库性能产生显着的 影响。
This is not true. Tables are allocated on disk in 8k pages. When a table is read from disk, the entire page is read in one IO operation and stored in memory. Therefore, the length of a column will not affect memory alignment at all. In fact, with non-variable length data types, shorter is definitely better: an nchar(200) column will allow more rows per page than an nchar(256) column. This allows more rows to be read per single physical IO, which can have a dramatic affect on database performance.
这篇关于数据库可变长度文本字段是否为2的幂?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!