标签:aci esc rom order by info char 3.2 res com
堆表通过IAM连接一起,查询时全表扫描。
结构
中间2字节有疑问?
组织结构
聚集索引表由根节点(Root Node)、中间节点(Branch Nodes)、叶子节点组成。
如果叶子节点不够多时,根节点(Root Node)、中间节点(Branch Nodes)将不存在。
1. 聚集索引键值不能超过900字节,因为生成keyhashvalue时,如果大于900字节性能会有很大影响。Keyhashvalue用于查询页的数据行
2. 聚集索引键值尽量保持短,每页只有8096字节可用。减少中间节点的层数。
3. 聚集索引键值采用递增原则,有利于数据页连续性,减少BTree调整。

避免聚集索引查找
最大键列数为 16,最大索引键大小为 900 字节
索引tree是否包含部分数据。一部分不需要建立索引,减少索引层数。
用于分析表组织和索引组织查询命令。
DBCC IND ( { ‘dbname‘ | dbid }, { ‘objname‘ | objid }, { nonclustered indid | 1 | 0 | -1 | -2 } [, partition_number] )
Select * from sys.dm_db_database_page_allocations(DB_ID(), object_id(‘TestData8000‘),NULL,NULL,‘DETAILED‘)
sys.dm_db_database_page_allocations(@DatabaseId , @TableId , @IndexId , @PartionID , @Mode)
堆表
聚集索引表
查询结果集,字段说明
| 
 列  | 
 说明  | 
| 
 PageFID  | 
 索引所在文件Id  | 
| 
 PagePid  | 
 索引所在页Id  | 
| 
 IAMFID  | 
 索引所在IAM文件Id  | 
| 
 IAMPID  | 
 索引所在IAM的页Id  | 
| 
 objectId  | 
 对象ID,表对象ID  | 
| 
 IndexId  | 
 索引类型 0堆、1聚集索引、2-250非聚集索引  | 
| 
 PartitionNumber  | 
 索引所在分区编号  | 
| 
 PartitionId  | 
 索引所在的分区Id  | 
| 
 Iam_Chain_Type  | 
 该页存放的数据类型、in-row data 数据页或索引页、Row-overflow-data 溢出数据行页 Blob data 大文件类型页  | 
| 
 PageType  | 
 数据类型见页类型  | 
| 
 IndexLevel  | 
 索引级别 null 根级,0 叶子级,其他索引级  | 
| 
 NextPageFID  | 
 双链表前级文件Id  | 
| 
 NextPagePID  | 
 双链表前级页Id  | 
| 
 PrevPageFID  | 
 双链表后级文件Id  | 
| 
 PrevPagePID  | 
 双链表后级页Id  | 
用于查看页数据信息。
DBCC PAGE
(
[‘database name‘|database id], -- can be the actual name or id of the database
file number, -- the file number where the page is found
page number, -- the page number within the file 
print option = [0|1|2|3] -- display option; each option provides differing levels of information
)
--DBCC IND(‘DataPageTestDb‘,‘TestData8000‘,-1) 先查看表在数据里页数据信息
--DBCC PAGE(DataPageTestDb,1,8,3) 以文本信息查看
--DBCC PAGE(DataPageTestDb,1,8,3) with tableresults,以表格信息查看

查看索引情况
--dbcc show_statistics ([tablename], [indexname])
--dbcc show_statistics (TestDataUnIndex, PK_TestDataUnIndex)
命令详细见
https://docs.microsoft.com/zh-cn/previous-versions/sql/sql-server-2008-r2/ms174384(v=sql.105)
-- 打开IO开销统计 set STATISTICS io ON
-- 打开执行时间统计 set STATISTICS TIME ON
-- Select * from Table
或
Sql Profiler 用于跟踪程序生成的语句。
参考文章
https://www.cnblogs.com/yx007/p/7268310.html
下图用于跟踪Net sqlclient data provider 产生的语句,net体系应用。
以下语句用于跟踪,在线运行时,SQL操作用时比较长的语句
SELECT TOP 50 total_worker_time/execution_count AS [Avg CPU Time], (SELECT SUBSTRING(text,statement_start_offset/2, (CASE WHEN statement_end_offset = -1 then LEN(CONVERT(nvarchar(max), text)) * 2 ELSE statement_end_offset end -statement_start_offset)/2) FROM sys.dm_exec_sql_text(sql_handle)) AS query_text, * FROM sys.dm_exec_query_stats ORDER BY [Avg CPU Time] DESC
select request_session_id,OBJECT_NAME(resource_associated_entity_id) tableName from sys.dm_tran_locks where resource_type=‘OBJECT‘ use master go --检索死锁进程 select spid, blocked, loginame, last_batch, status, cmd, hostname, program_name from sysprocesses where spid in ( select blocked from sysprocesses where blocked <> 0 ) or (blocked <>0) select request_session_id,OBJECT_NAME(resource_associated_entity_id) tableName from sys.dm_tran_locks where resource_type=‘OBJECT‘
| 
 类型  | 
 字节数  | 
 定长  | 
 变长  | 
 blob类型  | 
| 
 uniqueidentifier  | 
 16  | 
 1  | 
||
| 
 date  | 
 3  | 
 1  | 
||
| 
 time  | 
 5  | 
 1  | 
||
| 
 datetime2  | 
 8  | 
 1  | 
||
| 
 datetimeoffset  | 
 10  | 
 1  | 
||
| 
 tinyint  | 
 1  | 
 1  | 
||
| 
 smallint  | 
 2  | 
 1  | 
||
| 
 int  | 
 4  | 
 1  | 
||
| 
 smalldatetime  | 
 4  | 
 1  | 
||
| 
 real  | 
 4  | 
 1  | 
||
| 
 money  | 
 8  | 
 1  | 
||
| 
 datetime  | 
 8  | 
 1  | 
||
| 
 float  | 
 8  | 
 1  | 
||
| 
 sql_variant  | 
 8016  | 
 1  | 
||
| 
 bit  | 
 1  | 
 1  | 
||
| 
 decimal(18.2)  | 
 9  | 
 1  | 
||
| 
 numeric(18.2)  | 
 9  | 
 1  | 
||
| 
 varchar(max)  | 
 1  | 
|||
| 
 nvarchar(max)  | 
 1  | 
|||
| 
 varbinary(max)  | 
 1  | 
|||
| 
 XML  | 
 1  | 
|||
| 
 Image  | 
 1  | 
|||
| 
 text  | 
||||
| 
 ntext  | 
||||
| 
 varchar()  | 
 1  | 
|||
| 
 nvarchar()  | 
 1  | 
|||
| 
 varbinary()  | 
 1  | 
|||
| 
 char  | 
 1  | 
|||
| 
 nchar  | 
 1  | 
以上为本篇文章的主要内容,希望大家多提提意见,如果喜欢记得点个赞哦
标签:aci esc rom order by info char 3.2 res com
原文地址:https://www.cnblogs.com/edison0621/p/10436353.html