|
这个对于定长和不定长字段来说是两个结果 -- 建立测试环境 create database dbtest111 go use dbtest111 go create table t1( id char ( 10) , name char ( 10)) insert into t1 select 'a' , '1' insert into t1 select 'b' , '2' create table t2( id char ( 10) , name char ( 10)) insert into t2 select 'a' , 'jinjazz1' insert into t2 select 'b' ,null insert into t2 select 'c' ,null insert into t2 select 'd' , 'jinjazz2' go -- 运行此命令 dbcc ind( dbtest111, t2, 0) -- 得到 pagetype=1 的那个行数据的 pageid ,比如我这里是 dbcc traceon( 3604) dbcc page( dbtest111, 1, 89, 1) 运行上面的sql语句,创建测试环境和实验脚本。得到如下结果 Slot 0, Offset 0x60, Length 27, DumpStyle BYTE Record Type = PRIMARY_RECORD Record Attributes = NULL_BITMAP 00000000: 10001800 61202020 20202020 20206a69 †....a ji Slot 1, Offset 0x7b, Length 27, DumpStyle BYTE Record Type = PRIMARY_RECORD Record Attributes = NULL_BITMAP 00000000: 10001800 62202020 20202020 20206a69 †....b ji Slot 2, Offset 0x96, Length 27, DumpStyle BYTE Record Type = PRIMARY_RECORD Record Attributes = NULL_BITMAP 00000000: 10001800 63202020 20202020 20206a69 †....c ji Slot 3, Offset 0xb1, Length 27, DumpStyle BYTE Record Type = PRIMARY_RECORD Record Attributes = NULL_BITMAP 00000000: 10001800 64202020 20202020 20206a69 †....d ji 每个slot都代表一行,可以看到null的不但占用空间,而且还写入了你不要的东西,最后处理是通过红色字体部分来判断那些字段是null哪些不是null,红色部分就是null_bitmap --2 、不定长字段测试 create database dbtest111 go use dbtest111 go create table t2( id char ( 10) , name varchar ( 10)) insert into t2 select 'a' , 'jinjazz1' insert into t2 select 'b' ,null insert into t2 select 'c' ,null insert into t2 select 'd' , 'jinjazz2' go -- 运行此命令 dbcc ind( dbtest111, t2, 0) -- 得到 pagetype=1 的那个行数据的 pageid ,比如我这里是 dbcc traceon( 3604) dbcc page( dbtest111, 1, 73, 1) 运行以上SQL代码得到结果 00000000: 30000e00 61202020 20202020 20200200 †0...a .. Slot 1, Offset 0x7d, Length 17, DumpStyle BYTE Record Type = PRIMARY_RECORD Record Attributes = NULL_BITMAP 00000000: 10000e00 62202020 20202020 20200200 †....b .. Slot 2, Offset 0x8e, Length 17, DumpStyle BYTE Record Type = PRIMARY_RECORD Record Attributes = NULL_BITMAP 00000000: 10000e00 63202020 20202020 20200200 †....c .. Slot 3, Offset 0x9f, Length 29, DumpStyle BYTE Record Type = PRIMARY_RECORD Record Attributes = NULL_BITMAP VARIABLE_COLUMNS Memory Dump @0x5655C09F 00000000: 30000e00 64202020 20202020 20200200 †0...d .. varchar比char节省地方,他的rowoffset是依次写入的,null不占用空间,空间利用很好,这个比char字段的null节省地方。
update t2 set name = 'jinjazz3' where id= 'b' dbcc page( dbtest111, 1, 73, 1) /* Row - Offset 3 (0x3) - 159 (0x9f) 2 (0x2) - 142 (0x8e) 1 (0x1) - 188 (0xbc) 0 (0x0) - 96 (0x60) */ 这个只要看最后的row Offset,红色部分是update的这条,他开辟了另外一处空间把null变成了非null。 当然系统会适时回收老的废弃空间。但varchar的效率没有char高是肯定的了,这也就是说char相当于空间换时间了 (责任编辑:admin) |





骆驼户外男 真皮磨砂日常休闲鞋 低帮 2011秋冬新款 专柜正品特价