您好,我是小DAI,专注于数据库管理员相关的技术问答,请问有什么可以帮您?

sp_estspace

语法

sp_estspace <table_name>, <no_of_rows>, <fill_factor>,
	<cols_to_max>, <textbin_len>, <iosec>, <page_size>

参数

<table_name>

是表的名称。它必须已存在于当前数据库中。

<no_of_rows>

是估计的表所包含的行数。

<fill_factor>

是索引填充因子。缺省值为空值,这意味着 SAP ASE 服务器使用其缺省填充因子。

<cols_to_max>

是用逗号分隔的可变长度列的列表,您要使用其中的最大长度,而不是平均长度。缺省值是可变长度列的平均声明长度。

<textbin_len>

是所有 text 和 image 列每行的长度。缺省值为 0。只有在表存储 text 或 image 数据时,才需要提供值。text 和 image 列存储在单独的数据页集中,与其它表数据的存储位置不同。实际表行存储指向 text 或 image 值的指针。sp_estspace 另外提供一行有关行的 text 或 image 页大小的信息。

<iosec>

是此计算机上每秒磁盘 I/O 的数目。缺省值是每秒 30 次 I/O。

<pagesize>

如果将表迁移到指定页大小的服务器中,此参数允许估计给定表及其所有索引需要的空间。可以指定页大小(2048、4096、8192、16384 或 2 K、4 K、8 K、16 K)或指定 NULL 以使用当前的页大小。如果不使用“K”作为单位说明符,则 <pagesize> 的缺省单位是字节。因为页分配为各种对象分配了相同大小的页,所以 <page_size> 值适用于所有页类型(index、data、text 等)。

示例

示例 1

计算 titles 表及其索引的空间要求以及创建索引需要的时间。行数为 10,000,填充因子为 50%,使用列的最大大小计算两个可变长度的列,并且磁盘 I/O 速度为每秒 25 次 I/O:

sp_estspace titles, 10000, 50, "title,notes", 0, 25
name             type         idx_level Pages        Kbytes
---------------- ------------ --------- ------------ ------------
titles           data                 0         3364         6728
titles           text/image           0            0            0
titleidind       clustered            0           21           43
titleidind       clustered            1            1            2
titleind         nonclustered         0         1001         2002
titleind         nonclustered         1           54          107
titleind         nonclustered         2            4            8
titleind         nonclustered         3            1            2

<h2>Total_Mbytes</h2>
             8.68
 
name               type         total_pages  time_mins
------------------ ------------ ------------ ------------
titleidind         clustered            3386           13
titleind           nonclustered         1060            5
titles             data                    0            2

示例 2

使用 au_pix 表中的现有 image 数据的平均长度计算具有 1000 行的表的大小。还可以将该大小作为常量提供:

declare @i int
select @i = avg(datalength(pic)) from au_pix
exec sp_estspace au_pix, 1000, null, null, 16, @i
au_pix has no indexes
 name            type         idx_level Pages     Kbytes
 --------------- ------------ --------- --------- ---------
 au_pix          data                 0        31        63
 au_pix          text/image           0     21000     42000
 
 Total_Mbytes
 -----------------
             41.08

示例 3

计算具有 50,000 行的 titles 表的大小,所有其它值都使用缺省值:

sp_estspace titles, 50000
name             type         idx_level Pages        Kbytes
--------------- ------------ --------- ------------ ------------
titles          data                 0         4912         9824
titleidind      clustered            0           31           61
titleidind      clustered            1            1            2
titleind        nonclustered         0         1390         2780
titleind        nonclustered         1           42           84
titleind        nonclustered         2            2            4
titleind        nonclustered         3            1            2

<h2>Total_Mbytes</h2>
            12.46

name               type         total_pages  time_mins
------------------ ------------ ------------ ------------
titleidind         clustered            4943           19
titleind           nonclustered         1435            8

示例 4

将聚簇索引添加到 blurbs 表后运行:

declare @i int
select @i = avg(datalength(copy)) from blurbs
exec sp_estspace blurbs, 6, null, null, 16, @i, "16k"
name                     type        idx_level Pages        Kbytes
------------------------ ----------- --------- ---------    ------
blurbs                   data                0        8        128
blurbs                   text/image          0        6         96
blurbs_ind               clustered           0        1         16
blurbs_ind               clustered           1        1         16

<h2>Total_Mbytes</h2>
0.25

name                     type         total_pages  time_mins
------------------------ ------------ ------------ ------------
blurbs_ind               clustered             10            0
blurbs                   data                   6            0

此示例运行在 2K 服务器上,并指示在将 blurbs 表迁移到 16K 服务器后,需要 0.25 MB 空间。下面是在 16 K 服务器上运行的同一查询,它将检验 0.25 MB 的空间要求:

declare @i int
select @i = avg(datalength(copy)) from blurbs
exec sp_estspace blurbs, 6, null, null, 16, @i, "16k"
name                     type         idx_level Pages     Kbytes
------------------------ ------------ --------- --------- ------
blurbs                   data                 0         8    128
blurbs                   text/image           0         6     96
blurbs_ind               clustered            0         1     16
blurbs_ind               clustered            1         1     16

<h2>Total_Mbytes</h2>
0.25

name                    type         total_pages  time_mins
----------------------- ------------ ------------ ----------
blurbs_ind              clustered              10          0
blurbs                  data                    6          0

示例 5

如果在 2 K 的服务器上 blurbs 表有 1000 行,估计需要 1.99 MB 的空间:

declare @i int
select @i = avg(datalength(copy)) from blurbs
exec sp_estspace blurbs, 1000, null, null, 16, @i, "2k"
name                    type         idx_level Pages        Kbytes
----------------------- ------------ --------- ------------ ------
blurbs                  data                 0     16           32
blurbs                  text/image           0   1000         2000
blurbs_ind              clustered            0      1            2
blurbs_ind              clustered            1      1            2

<h2>Total_Mbytes</h2>
1.99

name                    type         total_pages  time_mins
----------------------- ------------ ------------ ---------
blurbs_ind              clustered             18          0
blurbs                  data                1000          0

用法

若要估计表及其索引要求的空间量,请执行以下操作:

1 创建表。

2 创建表上的所有索引。

3 根据需要给定表名、表的估计行数和可选参数,运行 sp_estspace。

有关表或列的信息,请使用 sp_help <tablename>

另请参见 create index、create table。

不需要将数据插入表中。sp_estspace 将使用系统表中的信息(而不是表中数据的大小)来计算表和索引的大小

估计列需要的额外空间

如果数据库中设置了 auto identity 选项,则对于创建时没有指定主键、唯一约束或 IDENTITY 列的每个新表,SAP ASE 服务器将自动在其中定义一个 10 位数字的 IDENTITY 列。若要估计该列需要的额外空间的大小,请执行以下操作:

过程

在 master 数据库中,使用 sp_dboption 打开数据库的 auto identity 选项。

创建表。

在表上运行 sp_estspace 并记录结果。

删除表。

关闭数据库的 auto identity 选项。

重新创建表。

在表上重新运行 sp_estspace 并记录结果。