暂无图片
分享
tobeperfectman
2019-02-21
sql执行count(1) 统计行数 过慢
sql统计行数时过慢,单查询很快
select count(1) from (
 select rownum id,
       37 ad_client_id,
       27 ad_org_id,
       q.tmseason season,
       s.whs_channel,
       s.customer_group,
       s.branch,
       s.branch_cn,
       s.customer_code,
       s.customer_name,
       s.region,
       s.blr,
       s.product_channel,
       r.sta_code,
       r.article_no,
       m.division,
       m.category,
       m.theme,
       m.exc_lusive,
       r.moq,
       r.actual_num order_qty,
       decode(r.moq,0,0,decode(sign(r.moq-r.actual_num),1,round(r.actual_num/r.moq,2),1)) compliance_check,
       rt.compliance_check sta_compliance_check,
       rt.take_ratio take_ratio,
       u.id as ownerid,
       r.create_date creationdate,
       '' modifierid,
       sysdate modifieddate,
       'Y' isactive
  from rust_cluster_assor_result_info r,
       rust_cluster_assortment_result rt,
       b_qinfo                        q,
       m_product_hub                  m,
       b_sta_master                   s,
       users u
 where r.b_qinfo_id = q.id
   and r.b_qinfo_id = rt.b_qinfo_id
   and r.sta_code = rt.sta_no
   and q.tmseason = m.TM_SEASON
   and r.article_no = m.article_no
   and r.b_qinfo_id = s.b_qinfo_id(+)
   and r.sta_code = s.sta_code(+)
   and s.customer_code = u.name)

附件会上传执行计划


收藏
分享
5条回答
默认
最新
tobeperfectman
上传附件:sql plan.html
暂无图片 评论
暂无图片 有用 0
章芋文

目前的信息无法判断执行计划是否有问题,请使用sqlhc生成SQL的详细报告,包含表的数据、索引、统计信息等信息方便我们诊断。

暂无图片 评论
暂无图片 有用 0
墨天轮

在工具下载页面有SQLHC,官方一个诊断SQL语句的工具,sqlplus直接运行

工具下载

找到这条语句的SQL_ID:

select sql_id from v$sql where sql_fulltext like '%select count(1)%' or like 'select%table_name%'

运行sqlhc,生成HTML报告

@sqlhc T sql_id

暂无图片 评论
暂无图片 有用 0
tobeperfectman
好的  谢谢
暂无图片 评论
暂无图片 有用 0
Kamus
问题已关闭: 问题已经得到解决
暂无图片 评论
暂无图片 有用 0
回答交流
提交
问题信息
请登录之后查看
附件列表
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~
暂无图片墨值悬赏