首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >由于oracle中不存在查询,查询性能较慢

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

Stack Overflow用户
提问于 2019-03-11 14:46:12
回答 1查看 936关注 0票数 0

这是我的查询,它需要更多的时间来执行它,有谁能让它更快!我认为not exists会导致更多的时间消耗,但我不知道如何将其转换为条件更多的左外部连接,我已经多次更改它,但结果也随之改变。

提前谢谢。

代码语言:javascript
复制
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))
EN

回答 1

Stack Overflow用户

发布于 2019-03-11 18:17:56

根据基本调优原则,使用exists或not exists如果内部使用的查询not exists或exists具有巨大的data.if,则使用IN或NOT IN

还要删除SELECT distinct t.tax_payer_no,taxestab.estab_no中的DISTINCT,并在CTE查询中使用它,看看它花费了多少时间

代码语言:javascript
复制
  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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55096491

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档