[MSSQL] 查詢最佳化

來源:互聯網
上載者:User

在所有MSSQL 的指令碼前面加上 set nocount on  可以關閉訊息反饋機制,減少網路流量(用於BS模式) 特別是反饋訊息比較多的情況下。

 

用DateDiff去分析多語句的時間(用於批資料查詢,且在同一個Go塊中,如果在不同Go塊中,但在同一個session中,就要用暫存資料表。)

 

判斷執行計畫中是seek(搜尋操作)還是scan(掃描操作)?(seek操作效能要好於scan操作的效能)

 

串連查詢比子查詢效率高

查看查關資訊的語句:

SET statistics io on

SET statistics  time   on

SET showplan_text  on

SET showplan_all  on (用這個查出來的,主要看預計IO  和預計 CPU 時間 ,還有看是否走索引,並是否是Seek方式 )

如果是做存在性查詢:

IF EXISTS(select  A.id from  Base_Attachment as A where  ((A.[EntityFullName] = ''  + @SourceType  + '') and (A.[EntityID] = @SourceID)))

比select   @cnt=count(A.id) from  Base_Attachment as A where …要快好多。

源自:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.