SQL Server 如何保留存储?以及如何推翻它?

发布于 2024-09-24 08:01:45 字数 1419 浏览 6 评论 0原文

我试图了解 SQL Server 如何分配和保留空间。

运行了“表设计如何影响 SQL Server 性能?”一文中的示例。 [1],我收到了与文章[1.1]中的结果不同的结果[我的1.1]。
为什么?

为什么在一种情况下会保留/分配过多的空间([1]中的所有情况),但在另一种情况下[My 1.1]却没有?
(请注意,在 [1] 中,两种情况下都保留了过多的空间,但在我的计算机上仅在其中一种情况下保留了空间)

SQL Server 是如何分配和保留空间的?
我该如何控制/管理它?

[1] ======
表设计如何影响 SQL Server 性能?
http://sqlserver-training.com/表设计如何影响您的 sql 服务器性能

[我的 1.1]
我的结果从[1.1]下面的

name                               rows  reserved  data     index_size  unused
---------------------------------- ----- --------- -------- ----------- ---------
Fixed_Lenght_Row_Table_Optimised   10000 40008 KB  40000 KB 8 KB        0 KB

[ 1]转移 结果 [1] 从我上面的

name                               rows  reserved  data     index_size  unused
---------------------------------- ----- --------- -------- ----------- ---------
Fixed_Lenght_Row_Table_Optimised   10000 40072 KB  40000 KB 8 KB        64 KB

[1.2] 转移
[1] 的结果与我的一致

name                                 rows  reserved  data     index_size  unused
----------------------------------   ----- --------- -------- ----------- ---------
Fixed_Lenght_Row_Table_Non_Optimised 10000 80072 KB  80000 KB 8 KB        64 KB

I am trying to understnad how SQL Server allocates and reserves space.

Having run the examples from the article "How table design can impact your SQL Server performance?" [1], I received the results [My 1.1] diverting from those in article [1.1].
Why?

Why in one case the excessive space is reserved/allocated (all cases in [1]) but not in another [My 1.1]?
(Note that in [1] in both cases the excessive space is reserved, though on my computer only in one of cases)

How is space allocated, reserved by SQL Server?
And how can I control/manage it?

[1] ======
How table design can impact your SQL Server performance?
http://sqlserver-training.com/how-table-design-can-impact-your-sql-server-performance

[My 1.1]
My results diverting from [1] below

name                               rows  reserved  data     index_size  unused
---------------------------------- ----- --------- -------- ----------- ---------
Fixed_Lenght_Row_Table_Optimised   10000 40008 KB  40000 KB 8 KB        0 KB

[1.1]
Results in [1] diverting from mine above

name                               rows  reserved  data     index_size  unused
---------------------------------- ----- --------- -------- ----------- ---------
Fixed_Lenght_Row_Table_Optimised   10000 40072 KB  40000 KB 8 KB        64 KB

[1.2]
Results from [1] coinciding with mine

name                                 rows  reserved  data     index_size  unused
----------------------------------   ----- --------- -------- ----------- ---------
Fixed_Lenght_Row_Table_Non_Optimised 10000 80072 KB  80000 KB 8 KB        64 KB

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黑凤梨 2024-10-01 08:01:45

链接中的文章充其量是可疑的。不指定要使用的 SQL Server 版本以及启用/禁用的各种选项。从 SQL Server 2005 开始,对于超出 8K 限制的列,存在行小 lob 存储(请参阅 表和索引组织),有默认的行内与行外选项(请参阅sp_tableoption),并且有许多压缩选项(行级页面级、Unicode)。

为了获得准确的信息,我会坚持使用官方产品文档,从 规划和架构 (数据库引擎)。为了更容易理解,请购买一本成熟的书籍,例如 Microsoft SQL Server 2008 Internals Microsoft SQL Server 2005 内部:存储引擎

The article in the link is dubious at best. Does not specify what SQL Server version to use, and what are the various options enabled/disabled. Since SQL Server 2005 there is row small-lob storage for columns over spilling the 8K limit (see Table and Index Organization), there are default in-row vs. out-of-row options (see sp_tableoption) and there are many compression options (row-level, page-level, Unicode).

For accurate information I would stick to the official product documentation, starting from Planning and Architecture (Database Engine). For a more digestible read, buy one of the well established books, like Microsoft SQL Server 2008 Internals or Inside Microsoft SQL Server 2005: The Storage Engine.

对你而言 2024-10-01 08:01:45

这是有道理的:您有 64k 未使用空间。您经常会看到保留空间中的细微差别,就像这样,

我也会使用第二个参数以这种方式运行它。这可能没有什么区别

EXEC [sp_spaceused][1] 'Fixed_Lenght_Row_Table_Non-Optimised', 'true'

然后从 sp_spaceused

当您删除或重建大型
索引,或者删除或截断大的
表,数据库引擎推迟
实际的页面释放,以及它们的
关联的锁,直到之后
事务提交。延迟下降
操作不会释放分配的
立即空间。因此,
sp_spaceused 返回的值
跌落后立即或
截断大对象可能不会
反映实际磁盘空间
可用的。欲了解更多信息
延迟分配,请参阅丢弃和
重建大型对象。

最后,您的表是否会包含 4000 字节以上的行?如果您想覆盖以优化,我想说您还为时过早......只需使设计的实现正确即可(它们是单独的步骤)

It makes sense: you have 64k unused space. You'll often see minor differences in reserved space like this

I'd also run it this way too with the 2nd parameter. It may make no difference

EXEC [sp_spaceused][1] 'Fixed_Lenght_Row_Table_Non-Optimised', 'true'

And then from sp_spaceused

When you drop or rebuild large
indexes, or drop or truncate large
tables, the Database Engine defers the
actual page deallocations, and their
associated locks, until after the
transaction commits. Deferred drop
operations do not release allocated
space immediately. Therefore, the
values returned by sp_spaceused
immediately after dropping or
truncating a large object may not
reflect the actual disk space
available. For more information about
deferred allocations, see Dropping and
Rebuilding Large Objects.

Finally, will you have tables that will have 4000 byte+ rows? If you want to override to optimise, I'd say you're premature... just make your implementation of the design is correct (they are separate steps)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文