行大小计算测试

news/2024/7/24 11:34:08 标签: 数据库

数据库中每一行到底占用多少空间,在这里,做个小测试~~~这里只做了堆表的计算,如果包含索引,按照文档把索引的列也加上就OK啦~

 

建个测试表,然后用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

 

 

转载于:https://www.cnblogs.com/Gin-23333/p/4115396.html


http://www.niftyadmin.cn/n/1180406.html

相关文章

[iphone]XML 解析 之 TBXML 介绍

总的来说,iphone 上可用的解析XML的方式大概有2种类型的。1.Tree-based API:这种API的处理方式是将XML的结构看成是树,然后把树的各部分看成一个对象来处理,这就是我们说的DOM (Document Object Model)方式。在iPhone的SDK里包含了…

vue-element-admin源码解读——项目启动过程

vue-element-admin源码解读——项目组件布局及状态管理vue-element-admin源码解读——项目启动过程vue-element-admin源码解读——数据Mock vue-element-admin是一款优秀的前端框架,使用了最新的前端技术,内置了(Vue-i18)国际化解决方案,动态…

三大平衡树(Treap + Splay + SBT)总结+模板

Treap树 核心是 利用随机数的二叉排序树的各种操作复杂度平均为O(lgn) Treap模板&#xff1a; #include <cstdio> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <cstdlib> #include <cmath…

View与Control间的数据交互

View与Control间的数据交互 1.ViewBag.Name "Name1" 2.ViewData["VD"] "view data"; 3.TempData["TD"] "temp data"; 4.Model ViewBag和ViewData只在当前的Action中有效&#xff0c;生命周期和 View 相同&#xff1b; Tem…

vue-element-admin源码解读——数据Mock

vue-element-admin源码解读——项目组件布局及状态管理vue-element-admin源码解读——项目启动过程vue-element-admin源码解读——数据Mock MOCK是指模拟服务器按照一定的规则或者设定的数据&#xff0c;对客户端的请求进行响应。换个说法就是可以不用搭建后台服务器&#xff0…

JQuery Easy Ui dataGrid 数据表格

2019独角兽企业重金招聘Python工程师标准>>> 数据表格 - DataGrid 内容 概况 使用方法 数据表格属性 数据列属性 编辑 数据视图 事件 方法 继承$.fn.panel.defaults&#xff0c;使用$.fn.datagrid.defaults重载默认值。. 数据表格显示的数据以表格的形式&#xff0c…

vue-element-admin源码解读——项目组件布局及状态管理

vue-element-admin源码解读——项目组件布局及状态管理vue-element-admin源码解读——项目启动过程vue-element-admin源码解读——数据Mock vue-element-admin作为一款优秀的前端解决方案&#xff0c;整个框架的结构非常清晰&#xff0c;同时利用Vuex和Vue Router来实现SPA(单页…

影随心动

好久没进园子了&#xff0c;今天看到一位叫yingsuixindong的博主的随笔&#xff0c;发现他从2012年开始立志写随笔后&#xff0c;接下来几乎每天都坚持写一篇。突然感觉自己也有写的冲动&#xff01;&#xff01;总得留下点痕迹不是&#xff1f; 转载于:https://www.cnblogs.co…