2016-07-25 16 views
0

テーブルxには何百万もの行が含まれており、関数ベースのインデックス(trunc)を使用して単一の日付のデータをフェッチする必要があります。 たとえば、22-07-16の場合は単一の日付データ、3000000行ある場合。私はまた、列の合計の場合を使用しています。 18秒を要するクエリ。どのように私は時間を減らすことができます。単一の日付のオラクルで3000000のクエリの最適化

EDIT QUERY:

SELECT SUM(
    CASE 
    WHEN cssgoldenc1_.impact='Low' 
    THEN 1 
    ELSE 0 
    END) AS col_0_0_, 
    SUM(
    CASE 
    WHEN cssgoldenc1_.impact='High' 
    THEN 1 
    ELSE 0 
    END) AS col_1_0_ 
FROM CSSCOMPLIANCEDETAIL csscomplia0_, 
    CSSGoldenConfiguration cssgoldenc1_, 
    CSS css7_ 
WHERE csscomplia0_.cssGoldenConfigurationID_FK=cssgoldenc1_.CSSGoldenConfigurationId_PK 
AND csscomplia0_.cssID_FK      =css7_.cssId_PK 
AND (cssgoldenc1_.cmcategory     IN ('Access List','Application of QoS Policy','Archive','BFD','BGP', 'CPU','Clock','Debug','Default settings','Entity Check','IGP Routing','Inclusion in VRF', 'Interface Parameters','LDP','LDP Establishment','License','Logging/Syslog/Debug','MTU Size', 'Multicast','Multilink','NodeReadiness','Nomenclature Related','Performance Optimization', 'QoS','Router OAM','Routing','SNMP','Security','Services','System Recovery', 'Type of Interface','Unicast','Unrequired Services','mBGP')) 
AND TRUNC(csscomplia0_.creationDate)   =to_Date('22-07-16','dd-mm-yy') 
AND (css7_.softwareVersion     IN ('/asr920-universalk9.V155_1S2_SR635680903_6.bin', '/asr920-universalk9_npe.03.13.00.S.154-3.S-ext.bin','/asr920-universalk9_npe.03.14.02.S.155-1.S2-std.bin', '/asr920-universalk9_npe.V155_1_S2_SR635680903_2.bin','/asr920-universalk9_npe.V155_1_S2_SR635680903_6.bin', '/bootflash','asr901-universalk9-mz.155-3.S1a.bin','asr903rsp1-universalk9_npe.V155_1_S2_SR635680903_10.bin', 'asr920-universalk9.V155_1S2_SR635680903_6.bin','asr920-universalk9_npe.03.13.00.S.154-3.S-ext.bin', 'asr920-universalk9_npe.03.13.00z.S.154-3.S0z-ext.bin','asr920-universalk9_npe.03.14.02.S.155-1.S2-', 'asr920-universalk9_npe.03.14.02.S.155-1.S2-std.bin','asr920-universalk9_npe.03.15.01.S.155-2.S1-std.bin', 'asr920-universalk9_npe.03.16.01a.S.155-3.S1a-ext.bin','asr920-universalk9_npe.2016-05-10_07.53_saappuku.bin' ,'asr920-universalk9_npe.V155_1_S2_SR635680903_2.bin','asr920-universalk9_npe.V155_1_S2_SR635680903_6.bin', 
    'asr920-universalk9_npe.V155_1_S2_SR635680903_6.binn','bootflash')); 

インデックス:

create index idx_fnc on CSSCOMPLIANCEDETAIL(trunc(creationDate));

+3

を使用するためにクエリを変更します。プランの質問と説明。 – vercelli

+0

インデックスとパートティーンを試しましたか? –

+0

編集部分の質問を確認してください – Aamir

答えて

0

これを試してみてください。基本的にはCASEをサブクエリにしました。この方法で3M回評価するべきではありません。私はまた、インデックスを含むテーブル定義を投稿してくださいJOIN

with cssgoldenc1_ as 
    (select /*+ Materialize */ CASE WHEN impact='Low' THEN 1 
                 ELSE 0 END AS col_0_0_, 
           CASE WHEN impact='High' THEN 1 
                 ELSE 0 END AS col_1_0_, 
           CSSGoldenConfigurationId_PK 
     from CSSGoldenConfiguration 
     where cssgoldenc1_.cmcategory IN ('Access List','Application of QoS Policy','Archive','BFD','BGP', 'CPU','Clock','Debug','Default settings','Entity Check','IGP Routing','Inclusion in VRF', 'Interface Parameters','LDP','LDP Establishment','License','Logging/Syslog/Debug','MTU Size', 'Multicast','Multilink','NodeReadiness','Nomenclature Related','Performance Optimization', 'QoS','Router OAM','Routing','SNMP','Security','Services','System Recovery', 'Type of Interface','Unicast','Unrequired Services','mBGP') 
    ) 
SELECT SUM(col_0_0_) AS col_0_0_, 
     SUM(col_1_0_) AS col_1_0_ 
FROM CSSCOMPLIANCEDETAIL csscomplia0_ join cssgoldenc1_ on csscomplia0_.cssGoldenConfigurationID_FK = cssgoldenc1_.CSSGoldenConfigurationId_PK 
             join CSS css7_ on csscomplia0_.cssID_FK      = css7_.cssId_PK 
WHERE TRUNC(csscomplia0_.creationDate)   =to_Date('22-07-16','dd-mm-yy') 
    AND css7_.softwareVersion     IN ('/asr920-universalk9.V155_1S2_SR635680903_6.bin', '/asr920-universalk9_npe.03.13.00.S.154-3.S-ext.bin','/asr920-universalk9_npe.03.14.02.S.155-1.S2-std.bin', '/asr920-universalk9_npe.V155_1_S2_SR635680903_2.bin','/asr920-universalk9_npe.V155_1_S2_SR635680903_6.bin', '/bootflash','asr901-universalk9-mz.155-3.S1a.bin','asr903rsp1-universalk9_npe.V155_1_S2_SR635680903_10.bin', 'asr920-universalk9.V155_1S2_SR635680903_6.bin','asr920-universalk9_npe.03.13.00.S.154-3.S-ext.bin', 'asr920-universalk9_npe.03.13.00z.S.154-3.S0z-ext.bin','asr920-universalk9_npe.03.14.02.S.155-1.S2-', 'asr920-universalk9_npe.03.14.02.S.155-1.S2-std.bin','asr920-universalk9_npe.03.15.01.S.155-2.S1-std.bin', 'asr920-universalk9_npe.03.16.01a.S.155-3.S1a-ext.bin','asr920-universalk9_npe.2016-05-10_07.53_saappuku.bin' ,'asr920-universalk9_npe.V155_1_S2_SR635680903_2.bin','asr920-universalk9_npe.V155_1_S2_SR635680903_6.bin', 
    'asr920-universalk9_npe.V155_1_S2_SR635680903_6.binn','bootflash'); 
関連する問題