- 論壇徽章:
- 0
|
缺省情況下,tempdb數(shù)據(jù)庫是放置在master設(shè)備上,容量為2M,而臨時(shí)數(shù)據(jù)庫是活動(dòng)最為平凡的數(shù)據(jù)庫常常被用來排序、創(chuàng)建臨時(shí)表、重格式化等操作,所以tempdb的優(yōu)化應(yīng)該受到特別的關(guān)注。
第一步:將臨時(shí)數(shù)據(jù)庫與高速緩沖進(jìn)行綁定。
由于臨時(shí)表的創(chuàng)建、使用,臨時(shí)數(shù)據(jù)庫會(huì)頻繁地使用數(shù)據(jù)緩存,所以應(yīng)為臨時(shí)數(shù)據(jù)庫創(chuàng)建高速緩存,從而可以使其常駐內(nèi)存并有助于分散I/O:
1、創(chuàng)建命名高速緩存
sp_cacheconfig “tempdb_cache”,”10m”,”mixed”
2、重新啟動(dòng)server
3、捆綁臨時(shí)數(shù)據(jù)庫到tempdb_cache高速緩存
sp_bindcache “tempdb_cache”, tempdb
4、若有大的I/O,配置內(nèi)存池
第二步:優(yōu)化臨時(shí)表
大多數(shù)臨時(shí)表的使用是簡(jiǎn)單的,很少需要優(yōu)化。但需要對(duì)臨時(shí)表進(jìn)行復(fù)雜的訪問則、
應(yīng)通過使用多個(gè)過程或批處理來把表的創(chuàng)建和索引分開。以下兩種技術(shù)可以改善臨時(shí)表的優(yōu)化
1、在臨時(shí)表上創(chuàng)建索引
1)臨時(shí)表必須存在
2)統(tǒng)計(jì)頁必須存在(即不能在空表上創(chuàng)建索引)
2、把對(duì)臨時(shí)表的復(fù)雜的使用分散到多個(gè)批處理或過程中,以便為優(yōu)化器提供信息
下面的這個(gè)過程需要進(jìn)行優(yōu)化:
create proc base_proc
as
select * into #huge_result from auths
select * from article, #huge_result where article.author_code=
#huge_result.author_code and sex=”0”
使用兩個(gè)過程可以得到更好的性能
1)
create proc base_proc
as
select *
into #huge_result
from auths
exec select_proc
2)
create proc select_proc
as
select * from article,#huge_result
where article.author_code=#huge_result.author_code and sex=”0”
說明:在同一個(gè)存儲(chǔ)過程或批處理中,創(chuàng)建并使用一個(gè)表時(shí),查詢優(yōu)化器無法決定這個(gè)表的大小。
|
|