效能測試說明:
1. 資料庫伺服器重啟之後進行查詢.即第一次查詢的結果.
2. 是對資料庫查詢的效能比較.
測試情況:
1.在儲存過程中使用臨時表: (proc1)
select top 1000 *
into #t1
from somast
into #t1
from somast
insert into #t1
select top 100 * from somast
select * from #t1
---刪除表資料
TRUNCATE TABLE #t1
--刪除臨時表
drop table #t1
select * from #t1
---刪除表資料
TRUNCATE TABLE #t1
--刪除臨時表
drop table #t1
執行時間為: 1039ms
2. 在儲存過程中使用union all: (proc2)
select top 1000 * from somast
union all
select top 100 * from somast
union all
select top 100 * from somast
執行時間為5017ms
補充說明:
在以上兩個儲存過程執行過一次之後,緊接著再次執行以上兩個儲存過程,發現執行時間發生了本質的變化.
儲存過程proc1,執行時間為728ms
儲存過程proc2,執行時間為998ms
但是實際情況中,雖然說在很短的時間內,不大可能會發生同一人對同一個儲存過程查詢兩次及以上.多數情況是在不同的時間,由不同的人來執行.
而且對儲存過程優化,那麼在優化之後,再次執行的時間也會縮短,所以如果能優化,還是要進行優化.