sql调整一

一个查询:

open outcurlist for
      select t.*
      from  tbcharge t
      where t.state=-1
      and not exists
      (
        select 1 from
          (
                select t13.ptid  from tbcharge t13
                where
                t13.inserttime>sysdate-5/1440
                group by t13.ptid
                having count(t13.ptid)>2
          union all
              SELECT distinct t1.PTID
                FROM AccountRecharge t1
                WHERE
                 t1.ip in (
                  SELECT t12.ip
                  FROM AccountRecharge t12
                  WHERE
                  t12.inserttime>sysdate-5/1440
                  GROUP BY t12.ip
                  HAVING COUNT(1)>30)
          )a where a.ptid=t.ptid
      );

 

 

问题点:每次查询的时候都要进行过滤

 

调整思路一:单独执行过滤部分

 

for c1 in (
        SELECT   t13.ptid
                FROM tbcharge t13
                WHERE t13.inserttime > SYSDATE - 5 / 1440
        GROUP BY t13.ptid
        HAVING COUNT (t13.ptid) > 2
        UNION ALL
        SELECT DISTINCT t1.ptid
                        FROM accountrecharge t1
                WHERE  t1.ip IN (SELECT   t12.ip
                                        FROM tbcharge t12
                                        WHERE t12.inserttime > SYSDATE - 5 / 1440
                                GROUP BY t12.ip
                                        HAVING COUNT (1) > 30)
        ) loop

 update tbprohibitcharge t
  set updatetime = sysdate
 where t.prohibitptid = c1.ptid;
 if SQL%rowcount =0 then
 insert into tbprohibitcharge
  (prohibitptid,prohibitdesc ,updatetime)
  values
  (c1.ptid,c1.prohitbitdesc,sysdate)  ;
 end if;    
 commit;
end loop;

 

    open outcurlist for
      select t.*
      from  tbcharge t
      where t.state=-1
        and not exists
         (select 1
            from tbcharge t1
           where t.ptid=t1.prohibitptid);

 

 

调整思路继续: 单独通过作业实现过滤部分,避免每次查询都调用过滤

 

调整思路继续:观察分析state字段索引

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值