昨天服务器崩溃了。看了下sql进程占用了500多M存在。不太正常。
之前一直好好的。就是加了几个过程。set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
goALTER proc [dbo].[Proc_Visitor_Browser]
--查看访客的浏览信息
@visitor varchar(23),--访客标识
@pagecurrent int, --当前页
@pagesize int, --每页显示记录数
@starttime datetime, --开始时间
@endtime datetime, --结束时间
@pagecount int output --总页数
as
begin
create table #tb(id int,visitor varchar(23),website varchar(23),title nvarchar(50),page nvarchar(500)
,formpage nvarchar(500),accesstime datetime,leavetime datetime)
insert #tb select id,visitor,website,title,page,formpage,accesstime,leavetime from tz_page
where visitor = @visitor and convert(varchar(10),accesstime,120) >= @starttime and convert(varchar(10),accesstime,120) <= @endtime
select @pagecount = count(id) from #tb
set @pagecount = (@pagecount+@pagesize-1)/@pagesize
select top (@pagesize) id,visitor,website,title,page,formpage,accesstime,leavetime from #tb
where id > (select isnull(max(id),0) from
(select top (@pagesize*(@pagecurrent-1)) id from #tb order by id ) a
) order by id
end--
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
goALTER proc [dbo].[TZ_Statistics_Proc_User]
@starttime datetime,
@endtime datetime,
@type nvarchar(4),
@where varchar(300),
@id varchar(23)
as
begin
declare @sql varchar(8000),@w varchar(1000),@g varchar(1000)
declare @atype nvarchar(10)
select @atype = AccountType from Same where Id = @id
declare @registertime datetime
select @registertime = RegisterTime from same where Id = @id
if @starttime < @registertime --如果传入的开始时间大于账号注册时间
begin
set @starttime = @registertime
end
if @endtime > getdate()
begin
set @endtime = getdate()
end
--1 构建select部分
if @type='统计' or @type is null
begin
set @sql='select isnull(sum(case when type=''点击'' then 1 else 0 end),0) click,
isnull(sum(case when type=''展示'' then 1 else 0 end),0) display,'
if @atype='广告主'
begin
set @sql = @sql + 'isnull(sum(case when type=''点击'' then price else 0 end),0.00) clickprice,
isnull(sum(case when type=''展示'' then price else 0 end),0.00) displayprice,
isnull(sum(price),0.00) price,'
end
if @atype='网站主' or @atype ='合作站点'
begin
set @sql = @sql + 'isnull(substring(convert(varchar(100),sum(case when type=''点击'' then siteprice else 0 end)),0,
charindex(''.'',convert(varchar(100),sum(case when type=''点击'' then siteprice else 0 end)))+3),0.00) clickprice,
isnull(substring(convert(varchar(100),sum(case when type=''展示'' then siteprice else 0 end)),0,
charindex(''.'',convert(varchar(100),sum(case when type=''展示'' then siteprice else 0 end)))+3),0.00)
displayprice,'
set @sql = @sql + 'isnull(substring(convert(varchar(100),sum(siteprice)),0,charindex(''.'',convert(varchar(100),sum(siteprice)))+3),0.00) price,'
end
set @sql = @sql + ''''+convert(varchar(10),@starttime,120)+'~'+convert(varchar(10),@endtime,120)+'''as [Time],
(select max([time]) from tz_statisticsDetails where [type] = ''点击'''+@where+') as lastclicktime,
(select max([time]) from tz_statisticsDetails where [type] = ''展示'''+@where+') as lastshowtime
from TZ_StatisticsDetails where 1=1 and validity = 1'
set @w=''
if @starttime<>'' and @starttime is not null
set @w=' and datediff(d,'''+convert(varchar(10),@starttime,120)+''',[Time])>=0 '
if @endtime<>'' and @starttime is not null
set @w=@w+' and datediff(d,'''+convert(varchar(10),@endtime,120)+''',[Time])<=0 '
if @where<>'' and @where is not null
set @w=@w+@where
exec(@sql+@w)
end
if @type='明细'
begin
set @sql='select isnull(sum(case when TZ_StatisticsDetails.type=''点击'' then 1 else 0 end),0) click,
isnull(sum(case when TZ_StatisticsDetails.type=''展示'' then 1 else 0 end),0) display,'
if @atype='广告主'
begin
set @sql = @sql + 'isnull(sum(case when TZ_StatisticsDetails.type=''点击'' then price else 0 end),0.00) clickprice,
isnull(sum(case when TZ_StatisticsDetails.type=''展示'' then price else 0 end),0.00) displayprice,
isnull(sum(price),0.00) price,'
end
if @atype='网站主' or @atype ='合作站点'
begin
set @sql = @sql + 'isnull(substring(convert(varchar(100),sum(case when tz_statisticsDetails.type=''点击'' then siteprice else 0 end)),0,
charindex(''.'',convert(varchar(100),sum(case when tz_statisticsDetails.type=''点击'' then siteprice else 0 end)))+3),0.00) clickprice,
isnull(substring(convert(varchar(100),sum(case when tz_statisticsDetails.type=''展示'' then siteprice else 0 end)),0,
charindex(''.'',convert(varchar(100),sum(case when tz_statisticsDetails.type=''展示'' then siteprice else 0 end)))+3),0.00)
displayprice,'
set @sql = @sql + 'isnull(substring(convert(varchar(100),sum(siteprice)),0,charindex(''.'',convert(varchar(100),sum(siteprice)))+3),0.00) price,'
end
set @sql = @sql + 'dateadd(day,n.number,'''+convert(varchar(10),@starttime,120)+''') Time
from master..spt_values n left join TZ_StatisticsDetails on datediff(day,dateadd(day,n.number,'''+convert(varchar(10),@starttime,120)+'''),[time])=0
'+@where+' and validity = 1
where n.type=''p'' and n.number between 0 and datediff(day,'''+convert(varchar(10),@starttime,120)+''','''+convert(varchar(10),@endtime,120)+''')'
set @g=' group by dateadd(day,n.number,'''+convert(varchar(10),@starttime,120)+''')'
exec(@sql+@g)
end
end--表的数据大概都在100万左右.
然后请求数据库的次数很平凡。
内存只有1G。临时迁的服务器,也可能本身内存太小的问题,
但sql占了500多M也是不太正常的吧。
之前一直好好的。就是加了几个过程。set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
goALTER proc [dbo].[Proc_Visitor_Browser]
--查看访客的浏览信息
@visitor varchar(23),--访客标识
@pagecurrent int, --当前页
@pagesize int, --每页显示记录数
@starttime datetime, --开始时间
@endtime datetime, --结束时间
@pagecount int output --总页数
as
begin
create table #tb(id int,visitor varchar(23),website varchar(23),title nvarchar(50),page nvarchar(500)
,formpage nvarchar(500),accesstime datetime,leavetime datetime)
insert #tb select id,visitor,website,title,page,formpage,accesstime,leavetime from tz_page
where visitor = @visitor and convert(varchar(10),accesstime,120) >= @starttime and convert(varchar(10),accesstime,120) <= @endtime
select @pagecount = count(id) from #tb
set @pagecount = (@pagecount+@pagesize-1)/@pagesize
select top (@pagesize) id,visitor,website,title,page,formpage,accesstime,leavetime from #tb
where id > (select isnull(max(id),0) from
(select top (@pagesize*(@pagecurrent-1)) id from #tb order by id ) a
) order by id
end--
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
goALTER proc [dbo].[TZ_Statistics_Proc_User]
@starttime datetime,
@endtime datetime,
@type nvarchar(4),
@where varchar(300),
@id varchar(23)
as
begin
declare @sql varchar(8000),@w varchar(1000),@g varchar(1000)
declare @atype nvarchar(10)
select @atype = AccountType from Same where Id = @id
declare @registertime datetime
select @registertime = RegisterTime from same where Id = @id
if @starttime < @registertime --如果传入的开始时间大于账号注册时间
begin
set @starttime = @registertime
end
if @endtime > getdate()
begin
set @endtime = getdate()
end
--1 构建select部分
if @type='统计' or @type is null
begin
set @sql='select isnull(sum(case when type=''点击'' then 1 else 0 end),0) click,
isnull(sum(case when type=''展示'' then 1 else 0 end),0) display,'
if @atype='广告主'
begin
set @sql = @sql + 'isnull(sum(case when type=''点击'' then price else 0 end),0.00) clickprice,
isnull(sum(case when type=''展示'' then price else 0 end),0.00) displayprice,
isnull(sum(price),0.00) price,'
end
if @atype='网站主' or @atype ='合作站点'
begin
set @sql = @sql + 'isnull(substring(convert(varchar(100),sum(case when type=''点击'' then siteprice else 0 end)),0,
charindex(''.'',convert(varchar(100),sum(case when type=''点击'' then siteprice else 0 end)))+3),0.00) clickprice,
isnull(substring(convert(varchar(100),sum(case when type=''展示'' then siteprice else 0 end)),0,
charindex(''.'',convert(varchar(100),sum(case when type=''展示'' then siteprice else 0 end)))+3),0.00)
displayprice,'
set @sql = @sql + 'isnull(substring(convert(varchar(100),sum(siteprice)),0,charindex(''.'',convert(varchar(100),sum(siteprice)))+3),0.00) price,'
end
set @sql = @sql + ''''+convert(varchar(10),@starttime,120)+'~'+convert(varchar(10),@endtime,120)+'''as [Time],
(select max([time]) from tz_statisticsDetails where [type] = ''点击'''+@where+') as lastclicktime,
(select max([time]) from tz_statisticsDetails where [type] = ''展示'''+@where+') as lastshowtime
from TZ_StatisticsDetails where 1=1 and validity = 1'
set @w=''
if @starttime<>'' and @starttime is not null
set @w=' and datediff(d,'''+convert(varchar(10),@starttime,120)+''',[Time])>=0 '
if @endtime<>'' and @starttime is not null
set @w=@w+' and datediff(d,'''+convert(varchar(10),@endtime,120)+''',[Time])<=0 '
if @where<>'' and @where is not null
set @w=@w+@where
exec(@sql+@w)
end
if @type='明细'
begin
set @sql='select isnull(sum(case when TZ_StatisticsDetails.type=''点击'' then 1 else 0 end),0) click,
isnull(sum(case when TZ_StatisticsDetails.type=''展示'' then 1 else 0 end),0) display,'
if @atype='广告主'
begin
set @sql = @sql + 'isnull(sum(case when TZ_StatisticsDetails.type=''点击'' then price else 0 end),0.00) clickprice,
isnull(sum(case when TZ_StatisticsDetails.type=''展示'' then price else 0 end),0.00) displayprice,
isnull(sum(price),0.00) price,'
end
if @atype='网站主' or @atype ='合作站点'
begin
set @sql = @sql + 'isnull(substring(convert(varchar(100),sum(case when tz_statisticsDetails.type=''点击'' then siteprice else 0 end)),0,
charindex(''.'',convert(varchar(100),sum(case when tz_statisticsDetails.type=''点击'' then siteprice else 0 end)))+3),0.00) clickprice,
isnull(substring(convert(varchar(100),sum(case when tz_statisticsDetails.type=''展示'' then siteprice else 0 end)),0,
charindex(''.'',convert(varchar(100),sum(case when tz_statisticsDetails.type=''展示'' then siteprice else 0 end)))+3),0.00)
displayprice,'
set @sql = @sql + 'isnull(substring(convert(varchar(100),sum(siteprice)),0,charindex(''.'',convert(varchar(100),sum(siteprice)))+3),0.00) price,'
end
set @sql = @sql + 'dateadd(day,n.number,'''+convert(varchar(10),@starttime,120)+''') Time
from master..spt_values n left join TZ_StatisticsDetails on datediff(day,dateadd(day,n.number,'''+convert(varchar(10),@starttime,120)+'''),[time])=0
'+@where+' and validity = 1
where n.type=''p'' and n.number between 0 and datediff(day,'''+convert(varchar(10),@starttime,120)+''','''+convert(varchar(10),@endtime,120)+''')'
set @g=' group by dateadd(day,n.number,'''+convert(varchar(10),@starttime,120)+''')'
exec(@sql+@g)
end
end--表的数据大概都在100万左右.
然后请求数据库的次数很平凡。
内存只有1G。临时迁的服务器,也可能本身内存太小的问题,
但sql占了500多M也是不太正常的吧。
大概每天请求数据库的次数为10万次左右。
请求次数我是根据表数据来判断的。
回来再看
你一下贴这么多,业务大家又不知道,如何帮你?
有点来吓人的意思~~~