简单测试在存储过程中临时表与union all的性能差别

机器:cpu: 2g 内存: 2g 数据库:sql 2005 根据机器配置不同,结果会有不同.
性能测试说明:
1. 数据库服务器重启之后进行查询.即第一次查询的结果.
2. 是对数据库查询的性能比较.

测试情况:
1.在存储过程中使用临时表: (proc1)
select top 1000 *
into #t1
from somast
insert into #t1
select top 100 * from somast
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

执行时间为5017ms


补充说明:
在以上两个存储过程执行过一次之后,紧接着再次执行以上两个存储过程,发现执行时间发生了本质的变化.
存储过程proc1,执行时间为728ms
存储过程proc2,执行时间为998ms

但是实际情况中,虽然说在很短的时间内,不大可能会发生同一人对同一个存储过程查询两次及以上.多数情况是在不同的时间,由不同的人来执行.
而且对存储过程优化,那么在优化之后,再次执行的时间也会缩短,所以如果能优化,还是要进行优化.
posted @ 2008-04-15 12:27  DotNet菜园  阅读(3431)  评论(2编辑  收藏  举报