在tcl脚本中使用的慢oracle查询

时间:2014-01-21 02:49:19

标签: oracle query-performance

我已经编写了这个查询,供oclql和orafetch在tcl脚本中使用。该查询嵌套在一个proc中,该proc作为需要运行的日期范围运行多次(通常每个实例约3次)。带有$ YYYYMM的表是包含大约1300万行的完整月份表。 $ advocate变量将提取大约39个不同的account_id,这将减少大量返回的行数,但不会像claim_status_code ='4'(~460,000行)那样大。我不知道查询的当前运行时间是什么,因为我不允许它运行超过大约30分钟。我真的需要这个几秒钟,我只是对所有这一切的新方法知道如何提高速度。我已经查看了优化查询的oracle文档,并尝试将这些建议合并到我编写的内容中。任何帮助都将非常感激。

select 
    case
        when clg_payor_id
        is null
        then payor_id1
        else clg_payor_id
    end
    , count(unique era_id||invoice) count
from marge.e835_clp_$YYYYMM@e835v2
where claim_status_code='4' and payor_id1!='client'
group by case when clg_payor_id is null then payor_id1 else clg_payor_id end, era_id
having era_id 
in (
    select era_id 
    from marge.e835_checks_$YYYYMM@e835v2 
    where input_date between '$date1' and '$date2' 
    group by account_id, era_id
    having account_id 
    in (
        select ea.account_id 
        from cowboy.enrolled_submitters es
        , cowboy.enrolled_accounts ea 
        where ea.submitter_id=es.submitter_id 
        and es.advocate='$advocate'
     )
) 
order by count desc

更新:正如所建议的那样,我已将era_id移出HAVING子句并移入WHERE。当我运行此查询时,由于所有的account_id,它会返回许多不需要的结果,但我无法弄清楚原因。该查询确实运行但它只需要约9秒。这么多改进了。

select
    case
        when clg_payor_id
        is null
        then payor_id1
        else clg_payor_id
    end
    , account_id, count(unique era_id||invoice) count
from marge.e835_clp_$YYYYMM@e835v2
where claim_status_code='4' 
and payor_id1!='client' 
and era_id
in (
    select era_id
    from marge.e835_checks_$YYYYMM@e835v2
    where input_date between '$date1' and '$date2'
    group by account_id
        , era_id
    having account_id
        in (
            select ea.account_id
            from cowboy.enrolled_submitters es
            , cowboy.enrolled_accounts ea
            where ea.submitter_id=es.submitter_id
            and es.advocate='$advocate'
        )
)
group by case when clg_payor_id is null then payor_id1 else clg_payor_id end, account_id
order by count desc

0 个答案:

没有答案