许雅涵吸毒,莱州天气在线,黄色小说阅读
在sql server中,tempdb主要负责供下述三类情况使用:
内部使用(排序、hash join、work table等)
外部使用(临时表,表变量等)
行版本控制(乐观并发控制)
而对于内部使用,一些比较复杂的查询中由于涉及到了大量的并行、排序等操作时就需要大量的内存空间,每一个查询在开始时都会由sql server预估需要多少内存,在具体的执行过程中,如果授予的内存不足,则需要将多出来的部分由tempdb处理,这也就是所谓的spill to tempdb。
通过下述语句可以观察到某个查询对tempdb造成了多少读写:
declare @read bigint, @write bigint ; select @read = sum(num_of_bytes_read), @write = sum(num_of_bytes_written) from tempdb.sys.database_files as dbf join sys.dm_io_virtual_file_stats(2, null) as fs on fs.file_id = dbf.file_id where dbf.type_desc = 'rows' --这里放入需要测量的语句 select tempdb_read_mb = (sum(num_of_bytes_read) - @read) / 1024. / 1024., tempdb_write_mb = (sum(num_of_bytes_written) - @write) / 1024. / 1024., internal_use_mb = ( select internal_objects_alloc_page_count / 128.0 from sys.dm_db_task_space_usage where session_id = @@spid ) from tempdb.sys.database_files as dbf join sys.dm_io_virtual_file_stats(2, null) as fs on fs.file_id = dbf.file_id where dbf.type_desc = 'rows'
最近在一个客户那里看到的烂查询所导致的tempdb使用结果如下:
使用该查询就可以帮助了解某个语句使用了多少tempdb。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
数据库SQL---数据库、基本表、视图、索引的定义、修改、删除
在 Azure CentOS VM 中配置 SQL Server 2019 AG - (上)
在 Azure CentOS VM 中配置 SQL Server 2019 AG - (下)
网友评论