由于oracle中不存在慢查询性能

问题描述 投票:0回答:1

这是我的查询,执行它需要更多的时间,任何人都可以让它更快!我认为不存在导致更多的时间消耗,但我不知道如何将它转换为左外连接更多条件我已经多次改变它但结果随之改变。

提前致谢。

select count(1) from(
        SELECT distinct   t.tax_payer_no,taxestab.estab_no 
          from tax_period tp, 
               imposition_base impb ,tax_acct_base_imp tabi, tax_account ta, tax_payer t , tax_form tf,tax_Type tt, tax_estab taxestab, establishment est
         where
           t.tax_payer_no=ta.tax_payer_no
           and tp.form_no=tf.form_NO
           and tf.tax_Type_no=tt.tax_Type_No
           and ta.tax_Type_no=tt.tax_type_no

        and (( tabi.tax_account_No=ta.tax_account_no and tt.tax_Type_No!=2) OR( tt.tax_Type_No=2))
        and impb.imposition_base_no(+) = tp.imposition_base_no
           AND impb.imposition_base_no = tabi.imposition_base_no(+)
           and ta.tax_Account_No=taxestab.tax_account_no(+)
           and taxestab.estab_no=est.estab_no(+)
        and ta.tax_account_no={0}
        and ta.close_date is null


        and not exists ( SELECT 1  
                                      FROM  assessment ass
                                      WHERE tax_account_no = ta.tax_account_No
                                      AND ass.tax_period_no= tp.tax_period_no                             
                                     AND (ass.estab_no = taxestab.estab_no OR taxestab.estab_no IS NULL)
                                   )

        and not exists (SELECT 1 FROM document doc
                         WHERE doc.tax_period_no =tp.tax_period_no
                         AND doc.tax_type_no = ta.tax_type_no
                         AND doc.tax_payer_no = t.tax_payer_no
                         AND doc.tax_centre_no = t.tax_centre_no
                         AND doc.doc_type_no = 1 
                         AND doc.doc_state_no <> 3 

                         AND (doc.estab_no = taxestab.estab_no OR taxestab.estab_no IS NULL))
oracle query-performance not-exists
1个回答
0
投票

根据基本调优原则,如果内部使用的查询不存在或存在具有巨大数据,则存在或不存在使用。如果它没有大数据使用IN或NOT IN代替

同时删除SELECT DISTINCT t.tax_payer_no,taxestab.estab_no中的distinct,并在CTE查询中使用它,看看它有多少时间

  with data as (
    SELECT t.tax_payer_no tax_payer_no,taxestab.estab_no estab_no.. rest of your query)
  select count(1),tax_payer_no,estab_no from data
     group by tax_payer_no,estab_no
© www.soinside.com 2019 - 2024. All rights reserved.