评论

收藏

[Sybase] 1.sybase进阶操作

数据库 数据库 发布于:2021-12-17 18:55 | 阅读数:551 | 评论:0



    • 预估表插入多少行需要的空间大小

使用命令sp_estspace,语法如下:
USAGE:
sp_estspace table_name, no_of_rows, fill_factor, cols_to_max, textbin_len, iosec
where
table_name  is the name of the table,
no_of_rows  is the number of rows in the table (>0),
fill_factor is the index fill factor. Values range from
0 to 100. (default = 0,in which case internal
fill factor will be used)
cols_to_max is a list of the variable length columns for which
to use the maximum length instead of the average
(default = null)
textbin_len is length of all the text and binary fields per
row ( default =  0).
iosec       is the number of I/Os per second on this machine
(default = 30)
Examples: sp_estspace titles, 10000, 50, "title, notes", null, 25
sp_estspace titles, 50000
sp_estspace titles, 50000, null, null, null, 40
(return status = 0)
具体执行如下:
1> sp_estspace table1,500000
2> go
table1 has no indexes
name   type idx_level Pages        Kbytes
------ ---- --------- ------------ ------------
table1 data         0         1969         7878
(1 row affected)
Total_Mbytes
-----------------
7.69
(return status = 0)


    • 为已存在的表估计大小

2> dbcc checktable (table1)
3> go
Checking table 'table1' (object ID 736002622): Logical page size is 4096 bytes.
Checking partition 'table1_736002622' (partition ID 736002622) of table
'table1'. The logical page size of this table is 4096 bytes.
The total number of data pages in partition 'table1_736002622' (partition ID
736002622) is 2.
Partition 'table1_736002622' (partition ID 736002622) has 3 data rows.
The total number of data pages in this table is 2.
Table has 3 data rows.
DBCC execution completed. If DBCC printed error messages, contact a user with
System Administrator (SA) role.


    • 估计性能

表扫描是对一个表中的每一个数据页进行顺序读取的过程。为得到精确的逻辑计数,运行之前运行set statistics io on命令
了解表扫描将花费的时间长度对于索引选择是有用的,可以决定最大的查询执行期望时间。
因为有些页面可能被缓存住了,所以需要重启服务器,然后执行如下:
4> set statistics io on
5> set statistics time on
6> select count(*) from table1
7> go
Total writes for this command: 0
Total writes for this command: 0
Execution Time 0.
Adaptive Server cpu time: 0 ms.  Adaptive Server elapsed time: 0 ms.
-----------
3
Table: table1 scan count 1, logical reads: (regular=2 apf=0 total=2), physical
reads: (regular=0 apf=0 total=0), apf IOs used=0
Total writes for this command: 0
Execution Time 0.
Adaptive Server cpu time: 9 ms.  Adaptive Server elapsed time: 9 ms.
(1 row affected)


关注下面的标签,发现更多相似文章