你把这两种方法的测试顺序倒一下,再测试
正常情况下,这两种做法对性能是一样的,不过,你的写法效果可不一样,改成如下就一样了情况一:
CREATE procedure compute_s11_flowing(@pub_dt datetime = null)
as
set @pub_dt = convert(varchar(10),getdate(),126)
....
---------
情况二:
CREATE procedure compute_s11_flowing(@pub_dt datetime = null)
as
declare @pub_dt1 datetime
set @pub_dt1 = convert(varchar(10),getdate(),126)
....
---------
正常情况下,这两种做法对性能是一样的,不过,你的写法效果可不一样,改成如下就一样了情况一:
CREATE procedure compute_s11_flowing(@pub_dt datetime = null)
as
set @pub_dt = convert(varchar(10),getdate(),126)
....
---------
情况二:
CREATE procedure compute_s11_flowing(@pub_dt datetime = null)
as
declare @pub_dt1 datetime
set @pub_dt1 = convert(varchar(10),getdate(),126)
....
---------
set @pub_dt1 = convert(varchar(10),getdate(),126) ;
我没有写上帖子,是我的大意,不过它不影响执行速度.
前后修改的就是把外部参数是否传给内部参数或直接参与运算.谢谢utpcb,事实上在执行中的第一个运算的语句就已经卡住了(使用外部参数直接运算时),那个语句有一个相当大的表.所以,我仍然认为是参数的使用问题.
下面是测试数据,除了第一次有点差异以外,后面的基本上是一致的了.use [csdn]
go
if object_id(N'A') is not null
begin
drop table A
end
go
create table A(id int identity(1,1), dt datetime)
go
declare @i int
set @i =1
while (@i <=1000000)
begin
insert into A values(getdate())
set @i = @i + 1
end
goif object_id(N'user_sp1') is not null
begin
drop proc user_sp1
end
go
create proc user_sp1 (@param datetime =null)
as
begin
set @param = getdate()
update a
set dt = dt - getdate()
end
go
if object_id(N'user_sp2') is not null
begin
drop proc user_sp2
end
go
create proc user_sp2(@param datetime =null)
as
begin
declare @datet datetime
set @param =getdate()
set @datet = @param
update a
set dt = dt - getdate()
end
goexec user_sp2 ''
--00:01:19
exec user_sp1 ''
--00:00:05
/*
select top 10 * from A
*/
use [csdn]
go
drop proc user_sp1
go
drop proc user_sp2
go
drop table A
go