行大小计算测试
2016-05-05 17:22
369 查看
数据库中每一行到底占用多少空间,在这里,做个小测试~~~这里只做了堆表的计算,如果包含索引,按照文档把索引的列也加上就OK啦~
建个测试表,然后用DBCC PAGE打印出Slot的信息
然后我就直接把slot的消息贴出来分析吧~~
-------------------------------------------------------------------------------------------------------------------------------------
Slot 0, Offset 0x60, Length 51, DumpStyle BYTE
Record Type = PRIMARY_RECORD Record Attributes = NULL_BITMAP VARIABLE_COLUMNS
Record Size = 51
Memory Dump @0x0A93C060
00000000: 30000e00 61613120 206a6f61 6e320500 †0...aa1 joan2..
00000010: 00030023 002c0033 00323232 32323232 †...#.,.3.2222222
00000020: 32323261 6f616f6e 666f656e 31313131 †222aoaonfoen1111
00000030: 313131†††††††††††††††††††††††††††††††111
4 8 12 16 20 24 28 32 36 40 44 48 52
30000e00 61613120 206a6f61 6e320500 00030023 002c0033 00323232 3232323 32323261 6f616f6e 666f656e 31313131 313131
1 2 3 4 5 6 7 8 9
1: 固定长度列结束位置
2: 固定长度第一列(col1)
3: 固定长度第二列(col3) --如果之后还有更多的列,继续往后排
4: 行包含的栏位总数,本例为5
5: 空值维护:计算方式为 2+ (可为空列数+7)/8
6: 每一个可变列的结束位置。长度计算 2 + (可变列列数*2)
7+:变长列的每一个填充列
验证了这一句话,每行的开销
ix bytes per row for status information and length information.
One bit per fixed width column, rounding up to the nearest byte.
If there are any variable length columns - four bytes for the first, plus two bytes for each additional variable length column
An additional two bytes per row for the offset pointer located at the end of the page.
-----------------------------------------------------------------------------------------------------
经过测试,无论列的顺序怎么排,首先会先把定长的字段先排出来,然后再排变长字段~好吧~测试结束
小弟不才~欢迎大家指出不足
参考:
http://technet.microsoft.com/zh-cn/library/ms189124.aspx
PS:上面2个DBCC 的语法
dbcc ind(dbname|dbid, tbname|tbid,-1)
dbcc page ( {'dbname' | dbid}, filenum, pagenum [, printopt={0|1|2|3} ])
The filenum and pagenum parameters are taken from the page IDs that come from various system tables and appear in DBCC or other system error messages. A page ID of, say, (1:354) has filenum = 1 and pagenum = 354.
The printopt parameter has the following meanings:
0 - print just the page header
1 - page header plus per-row hex dumps and a dump of the page slot array (unless its a page that doesn't have one, like allocation bitmaps)
2 - page header plus whole page hex dump
3 - page header plus detailed per-row interpretation
建个测试表,然后用DBCC PAGE打印出Slot的信息
CREATE TABLE TstA ( col1 CHAR(5) NULL, col2 CHAR(5) NULL, col3 VARCHAR(5) NULL, col4 VARCHAR(10) NULL, col5 VARCHAR(50) NULL ) INSERT INTO TstA (col1,col2,col3,col4,col5) VALUES ('aa1','2222222222','joan2','aoaonfoen','1111111') dbcc ind(TestDB, Object_id('TstA'),-1)
DBCC PAGE(TestDB,1,11957,1)
然后我就直接把slot的消息贴出来分析吧~~
-------------------------------------------------------------------------------------------------------------------------------------
Slot 0, Offset 0x60, Length 51, DumpStyle BYTE
Record Type = PRIMARY_RECORD Record Attributes = NULL_BITMAP VARIABLE_COLUMNS
Record Size = 51
Memory Dump @0x0A93C060
00000000: 30000e00 61613120 206a6f61 6e320500 †0...aa1 joan2..
00000010: 00030023 002c0033 00323232 32323232 †...#.,.3.2222222
00000020: 32323261 6f616f6e 666f656e 31313131 †222aoaonfoen1111
00000030: 313131†††††††††††††††††††††††††††††††111
4 8 12 16 20 24 28 32 36 40 44 48 52
30000e00 61613120 206a6f61 6e320500 00030023 002c0033 00323232 3232323 32323261 6f616f6e 666f656e 31313131 313131
1 2 3 4 5 6 7 8 9
1: 固定长度列结束位置
2: 固定长度第一列(col1)
3: 固定长度第二列(col3) --如果之后还有更多的列,继续往后排
4: 行包含的栏位总数,本例为5
5: 空值维护:计算方式为 2+ (可为空列数+7)/8
6: 每一个可变列的结束位置。长度计算 2 + (可变列列数*2)
7+:变长列的每一个填充列
验证了这一句话,每行的开销
ix bytes per row for status information and length information.
One bit per fixed width column, rounding up to the nearest byte.
If there are any variable length columns - four bytes for the first, plus two bytes for each additional variable length column
An additional two bytes per row for the offset pointer located at the end of the page.
-----------------------------------------------------------------------------------------------------
经过测试,无论列的顺序怎么排,首先会先把定长的字段先排出来,然后再排变长字段~好吧~测试结束
小弟不才~欢迎大家指出不足
参考:
http://technet.microsoft.com/zh-cn/library/ms189124.aspx
PS:上面2个DBCC 的语法
dbcc ind(dbname|dbid, tbname|tbid,-1)
dbcc page ( {'dbname' | dbid}, filenum, pagenum [, printopt={0|1|2|3} ])
The filenum and pagenum parameters are taken from the page IDs that come from various system tables and appear in DBCC or other system error messages. A page ID of, say, (1:354) has filenum = 1 and pagenum = 354.
The printopt parameter has the following meanings:
0 - print just the page header
1 - page header plus per-row hex dumps and a dump of the page slot array (unless its a page that doesn't have one, like allocation bitmaps)
2 - page header plus whole page hex dump
3 - page header plus detailed per-row interpretation
相关文章推荐
- Sql Server 2008R2 遇到了BCP导入各种中文乱码的问题
- 简析一下SQL Server里面Fast_Forword 和 SRROLL 的区别
- Filestream 使用简单步骤
- 将一列包含多个ID拆分多行
- Sql Server 添加外部程序集基本操作
- 使用scrapy的定制爬虫-第三章-爬虫的javascript支持
- IDENT_CURRENT ,@@identity,SCOPE_IDENTITY() 之间对比
- RestFul简介以及在springmvc中的应用
- 页面渲染——简化paint复杂程度和区域
- python实现Kmeans文本聚类,通过PCA降维和Matplotlib显示聚类3d三维图像
- 小括号与花括号小括号与花括号
- 面向对象思想的理解
- mysql自动增长的有关问题,怎么恢复从1开始
- 截取文本,区分中英文字符,中文算两个长度,英文算一个长度
- 关于linux下的分号
- js中typeof只能判断基础类型。
- C语言中数据类型之间怎样进行强制转换?
- 大数据学习笔记1
- 【HUSTOJ】1044: 字母三角形
- ok6410 3.0.1内核调用V4L接口出错解决方法