请邹建大哥帮我看看 存储过程执行太慢 怎样提高执行速度

scapple 2005-03-25 02:45:53
这个存储过程用来 统计每个类型对应的计费情况
有两张表
1. plat_orderservice
字段:
service_name 名称
feetype 计费类型
feecode 费率
service_id id2
2. plat_mt
字段:
app_id id
srctermid 号码
service_id id2
feetype 计费类型
morelatetomtflag_sgip 标志
occurtime 时间

存储过程如下

CREATE PROCEDURE Plat_OrderFeeAccount --统计每个单条业务类型对应的应用计费情况
@StartDate varchar(30),
@EndDate varchar(30)
AS
set nocount on
begin transaction

select success.wapp_id, success.totalNum, fail.failNum, success.wsrctermid, success.wservice_name, success.wfeecode
from
(
select count(*) as totalNum,
mt.app_id as wapp_id,
mt.srctermid as wsrctermid,
mt.service_id as wservice_id,
od.service_name as wservice_name,
od.feecode as wfeecode
from plat_mt as mt, plat_orderservice as od
where mt.occurtime >= @StartDate and mt.occurtime <= @EndDate
and mt.feetype = '02'
and mt.morelatetomtflag_sgip = 0
and mt.service_id = od.service_id
group by mt.service_id, mt.app_id, od.service_name,mt.srctermid, od.feecode
) as success
left outer join
(
select count(*) as failNum, plat_mt.service_id, plat_mt.app_id, plat_mt.srctermid
from plat_mt, plat_orderservice
where plat_mt.occurtime >= @StartDate and plat_mt.occurtime <= @EndDate
and plat_mt.feetype = '02'
and plat_mt.morelatetomtflag_sgip = 0
and plat_mt.send_status <> 0
and plat_orderservice.service_id = plat_mt.service_id
group by plat_mt.service_id, plat_mt.app_id, plat_mt.srctermid
) as fail
on success.wapp_id = fail.app_id
and success.wservice_id = fail.service_id
and success.wsrctermid = fail.srctermid

goto endpos

errorpos:
rollback transaction
return
endpos:
commit transaction
return
GO

现在plat_mt表里面的数据比较多 超过100w条记录
当执行这个存储过程的时候,通常都会超时

还有 当我用delete from plat_mt where occurtime <'×××'的时候 也提示执行超时
删除操作失败

等待高手指点迷津
...全文
290 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
doubhua 2005-04-20
  • 打赏
  • 举报
回复
建一个非聚集索引,包括以下字段:
occurtimeand
feetype
morelatetomtflag_sgip
send_status
service_id
都采用升序。
试试看。
scapple 2005-04-15
  • 打赏
  • 举报
回复
例子就是这个啊
通过不同的wapp_id, wsrctermid将统计信息分类显示出来

wapp_id total_num fail_num wsrctermid wservice_name wfeecode
2 1877 6 85185 单条1毛 10
2 2 NULL 85185114 单条1毛 10
zjcxc 2005-04-01
  • 打赏
  • 举报
回复
举例说明: 怎么统计法?
colt_mhw 2005-04-01
  • 打赏
  • 举报
回复
试试看以下措施是否有效:
一、将有关事务处理的语句去掉
二、建立游标,然后对游标进行处理
scapple 2005-04-01
  • 打赏
  • 举报
回复
另外就是在group by里面写很多列会不会影响速度
scapple 2005-04-01
  • 打赏
  • 举报
回复
邹建大哥呢 请你帮我看看啊
scapple 2005-03-29
  • 打赏
  • 举报
回复
数据库中有两张表 其中plat_mt是需要统计的数据,plat_orderservice中是记录各种计费类型
我需要通过这两张表 找出在一个时间段中的 各种计费类型的相应的总数和失败的数量

例如
wapp_id total_num fail_num wsrctermid wservice_name wfeecode
2 1877 6 85185 单条1毛 10
2 2 NULL 85185114 单条1毛 10
2 725 NULL 851854 单条1毛 10
2 420 2 851855 单条1毛 10
2 55 NULL 85185999 单条1毛 10
2 1 NULL 85185999 单条1元 100
2 348 2 851861 单条1元 100
2 1 NULL 851851121 单条2元 200
2 136 NULL 851851131 单条2元 200
2 360 1 85185999 单条2元 200
2 654 3 851861 单条2元 200
2 10450 25 85185 单条5毛 50
2 29 1 851851121 单条5毛 50
2 134 NULL 851851122 单条5毛 50
2 73 NULL 8518599 单条5毛 50
2 311 NULL 851861 单条5毛 50
2 5761 15 85185 单条2毛 20
2 1 NULL 85185998 单条2毛 20
2 8595 24 85185999 单条2毛 20
2 462 NULL 851861 单条2毛 20
7 2524 2 851999 单条1元 100
7 3 NULL 8519990 单条1元 100
7 1 NULL 8519991 单条1元 100
7 1 NULL 8519992 单条1元 100
7 9 NULL 8519996 单条1元 100
7 1 NULL 85199966 单条1元 100
7 45 NULL 8519999 单条1元 100
9 17214 20 851818 单条1元 100
9 2 NULL 8518180 单条1元 100
9 3 NULL 8518181 单条1元 100
9 1 NULL 85181818 单条1元 100

也就是说我需要根据不同的app_id 和srctermid 对数据分类显示
抱朴守拙 2005-03-25
  • 打赏
  • 举报
回复
就一个查询为什么要begin tracsation???
ypnet 2005-03-25
  • 打赏
  • 举报
回复
up
taoxuwen 2005-03-25
  • 打赏
  • 举报
回复
牛人被发现
zjcxc 2005-03-25
  • 打赏
  • 举报
回复
提供表结构,测试数据,处理要求说明

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧