首页 > 其他分享 >视图查询优化-不带条件

视图查询优化-不带条件

时间:2024-05-04 17:44:34浏览次数:21  
标签:不带 bill 视图 id av 查询 type ID se

视图查询优化-不带条件

sql

select /*+ VIEW_FILTER_MERGING(1) NO_USE_CVT_VAR */ v.account_number,
       v.bill_id,
       v.account_id,
       v.bill_line_id,
       v.bill_number,
       v.business_type,
       v.business_type_sub,
       v.EVENT_ID,
       v.PROJECT_ID,
       v.OBJECT_TYPE,
       v.OBJECT_ID,
       v.EVENT_TYPE,
       v.EVENT_DATE,
       v.ACCOUNTING_DATE,
       v.PERIOD_NAME,
       v.CURRENCY_CODE,
       v.AMOUNT,
       v.LEDGER_ID,
       v.ACTUAL_FLAG,
       v.BATCH_NAME,
       v.BATCH_DESC,
       v.JOURNAL_NAME,
       v.JOURNAL_DESC,
       v.USER_JE_CATEGORY_NAME,
       v.USER_JE_SOURCE_NAME,
       v.EXCHANGE_RATE_TYPE,
       v.EXCHANGE_RATE_DATE,
       v.EXCHANGE_RATE,
       v.RELATION_ID,
       v.STATUS,
       v.STATUS_DATE,
       v.CREATION_DATE,
       V.Business_Stage "business_stage",
       v.reverse_status,
       v.right_yn,
       v.devalue_stage,
       v.classify_result,
       v.bus_model,
       v.sppi_yn,
       v.gl_date
  from amc_account_event_v V
 WHERE 1 = 1
  -- and v.business_stage != 'FINANCIAL_TRANSFER'
  -- and V.account_id = 2711605
union all
select  v.account_number,
       a.pack_id,
       v.account_id,
       v.bill_line_id,
       a.pack_number,
       v.business_type,
       v.business_type_sub,
       v.EVENT_ID,
       v.PROJECT_ID,
       v.OBJECT_TYPE,
       v.OBJECT_ID,
       v.EVENT_TYPE,
       v.EVENT_DATE,
       v.ACCOUNTING_DATE,
       v.PERIOD_NAME,
       v.CURRENCY_CODE,
       v.AMOUNT,
       v.LEDGER_ID,
       v.ACTUAL_FLAG,
       v.BATCH_NAME,
       v.BATCH_DESC,
       v.JOURNAL_NAME,
       v.JOURNAL_DESC,
       v.USER_JE_CATEGORY_NAME,
       v.USER_JE_SOURCE_NAME,
       v.EXCHANGE_RATE_TYPE,
       v.EXCHANGE_RATE_DATE,
       v.EXCHANGE_RATE,
       v.RELATION_ID,
       v.STATUS,
       v.STATUS_DATE,
       v.CREATION_DATE,
       V.Business_Stage "business_stage",
       v.reverse_status,
       v.right_yn,
       v.devalue_stage,
       v.classify_result,
       v.bus_model,
       v.sppi_yn,
       v.gl_date
  from amc_account_event_v V
  left join amc_bill_financial_head_b a
    on a.pack_id = v.pack_id
 WHERE 1 = 1
  -- and v.business_stage = 'FINANCIAL_TRANSFER'
  -- and V.account_id = 2711605
 order by EVENT_ID desc;
   
CREATE OR REPLACE VIEW "JRAF"."AMC_ACCOUNT_EVENT_V_BAK"
AS 
select h.bill_id,
       /*modify by F.lei 20190220
       select av.bill_id,
             av.account_id,
             av.bill_line_id,
             av.account_number,
             av.bill_number,
             av.business_stage,
             av.business_type,
             av.business_type_sub,
             xse.event_id,
             xse.project_id,
             xse.object_type,
             xse.object_id,
             xse.event_type,
             xse.event_date,
             xse.accounting_date,
             xse.period_name,
             xse.currency_code,
             xse.amount,
             xse.ledger_id,
             xse.actual_flag,
             xse.batch_name,
             xse.batch_desc,
             xse.journal_name,
             xse.journal_desc,
             xse.user_je_category_name,
             xse.user_je_source_name,
             xse.exchange_rate_type,
             xse.exchange_rate_date,
             xse.exchange_rate,
             xse.relation_id,
             xse.status,
             xse.status_date,
             xse.creation_date,
             av.reverse_status,
             av.sppi_yn,
             av.bus_model,
             av.right_yn,
             av.classify_result,
             av.devalue_stage
        from amc_bill_account_v          av,
             xxt_sl_events@toebs         xse,
             xxt_sl_entity_relatns@toebs xsr
       where av.bill_line_id = xsr.entity_id
         and xsr.relation_target_id = xse.event_id
         and xsr.relation_target = 'EVENT'
         and xsr.entity_category = 'BAD_ASSETS';*/
       h.pack_id,
       a.account_id,
       l.bill_line_id,
       a.account_number,
       h.bill_number,
       h.business_stage,
       l.business_type,
       l.business_type_sub,
       se.event_id,
       se.project_id,
       se.object_type,
       se.object_id,
       se.event_type,
       se.event_date,
       se.accounting_date,
       se.period_name,
       se.currency_code,
       se.amount,
       se.ledger_id,
       se.actual_flag,
       se.batch_name,
       se.batch_desc,
       se.journal_name,
       se.journal_desc,
       se.user_je_category_name,
       se.user_je_source_name,
       se.exchange_rate_type,
       se.exchange_rate_date,
       se.exchange_rate,
       se.relation_id,
       se.status,
       se.status_date,
       se.creation_date,
       h.reverse_status,
       l.sppi_yn,
       l.bus_model,
       l.right_yn,
       l.classify_result,
       l.devalue_stage,
       h.gl_date
  from amc_bill_asset_head_b       h,
       amc_bill_asset_line_b       l,
       amc_asset_account_info_b    a,
       amc_base_project_b          p,
       xxt_coa_prod_type_v         pt,
       xxt_sl_entity_relatns@toebs ser,
       xxt_sl_events@toebs         se
 where 1 = 1
   and h.bill_id = l.bill_id
   and l.account_id = a.account_id
   and h.project_id = p.project_id
   and a.product_num = pt.prod_type_code
   and l.bill_line_id = ser.entity_id
   and ser.relation_target = 'EVENT'
   and ser.entity_category = 'BAD_ASSETS'
   and ser.relation_target_id = se.event_id
   and se.event_type = l.business_type
   and se.object_id = a.account_id
   and h.entry_status not in ('NL', 'SL_IN_ERROR', 'SL_IN_PROCESS');

explain

#执行时间:48s

1   #NSET2: [60, 1499, 2766] 
2     #PIPE2: [60, 1499, 2766] 
3       #PRJT2: [16, 1499, 2766]; exp_num(40), is_atom(FALSE) 
4         #SORT3: [16, 1499, 2766]; key_num(1), is_distinct(FALSE), top_flag(0), is_adaptive(0)
5           #UNION ALL: [14, 1499, 2766]
6             #PRJT2: [5, 749, 2766]; exp_num(40), is_atom(FALSE) 
7               #HEAP TABLE SCAN: [5, 749, 2766]; table_no(0) 
8             #PRJT2: [7, 749, 2766]; exp_num(40), is_atom(FALSE) 
9               #HASH RIGHT JOIN2: [7, 749, 2766]; key_num(1), ret_null(0), KEY(A.PACK_ID=V.PACK_ID)
10                #CSCN2: [1, 43, 78]; INDEX33557182(AMC_BILL_FINANCIAL_HEAD_B as A); btr_scan(1)
11                #HEAP TABLE SCAN: [5, 749, 2766]; table_no(0) 
12      #HEAP TABLE: [44, 749, 2766]; table_no(0) full(0), mpp_full(0) autoid(0), sites(-)
13        #PRJT2: [44, 749, 2766]; exp_num(41), is_atom(FALSE) 
14          #HASH2 INNER JOIN: [44, 749, 2766]; RKEY_UNIQUE KEY_NUM(1); KEY(H.PROJECT_ID=P.PROJECT_ID) KEY_NULL_EQU(0)
15            #HASH RIGHT SEMI JOIN2: [40, 749, 2736]; n_keys(1) (ANTI), KEY(DMTEMPVIEW_889763040.colname=H.ENTRY_STATUS) KEY_NULL_EQU(0)
16              #CONST VALUE LIST: [1, 3, 48]; row_num(3), col_num(1)
17              #NEST LOOP INDEX JOIN2: [40, 749, 2736] 
18                #HASH2 INNER JOIN: [35, 749, 2441];  KEY_NUM(1); KEY(PT.PROD_TYPE_CODE=A.PRODUCT_NUM) KEY_NULL_EQU(0)
19                  #PRJT2: [1, 222, 816]; exp_num(1), is_atom(FALSE) 
20                    #CSCN2: [1, 222, 816]; INDEX33558407(XXT_COA_PROD_TYPE_B); btr_scan(1)
21                  #HASH2 INNER JOIN: [34, 750, 1625];  KEY_NUM(4); KEY(SER.COL3=SE.EVENT_ID AND L.BUSINESS_TYPE=SE.EVENT_TYPE AND A.ACCOUNT_ID=SE.OBJECT_ID AND L.ACCOUNT_ID=SE.OBJECT_ID) KEY_NULL_EQU(0, 0, 0, 0)
22                    #NEST LOOP INDEX JOIN2: [23, 1000, 708] 
23                      #NEST LOOP INDEX JOIN2: [16, 1000, 582] 
24                        #REMOTE SCAN: [10, 1000, 156]; TMPREMOTETAB889763037@TOEBS as SER, condition((SER.RELATION_TARGET = 'EVENT' AND SER.ENTITY_CATEGORY = 'BAD_ASSETS'))
25                        #BLKUP2: [6, 1, 30]; INDEX33559142(L)
26                          #SSEK2: [6, 1, 30]; scan_type(ASC), INDEX33559142(AMC_BILL_ASSET_LINE_B as L), scan_range[SER.COL0,SER.COL0]
27                      #BLKUP2: [6, 1, 30]; INDEX33557263(A)
28                        #SSEK2: [6, 1, 30]; scan_type(ASC), INDEX33557263(AMC_ASSET_ACCOUNT_INFO_B as A), scan_range[L.ACCOUNT_ID,L.ACCOUNT_ID]
29                    #REMOTE SCAN: [10, 1000, 917]; XXT_SL_EVENTS@TOEBS as SE
30                #BLKUP2: [4, 1, 30]; INDEX33557203(H)
31                  #SSEK2: [4, 1, 30]; scan_type(ASC), INDEX33557203(AMC_BILL_ASSET_HEAD_B as H), scan_range[L.BILL_ID,L.BILL_ID]
32            #SSCN: [1, 9421, 30]; INDEX33557197(AMC_BASE_PROJECT_B as P); btr_scan(1)

视图改写

使有关dblink的表放在一起获取数据。

CREATE OR REPLACE VIEW "JRAF"."AMC_ACCOUNT_EVENT_V"
AS 
with tt as (select    se.*,to_char(ser.entity_id) entity_id  from    xxt_sl_entity_relatns@toebs ser,
       xxt_sl_events@toebs         se
 where 1 = 1  
   and ser.relation_target = 'EVENT'
   and ser.entity_category = 'BAD_ASSETS'
   and ser.relation_target_id = se.event_id
)
select  /*+  ORDER(H,L,A,P,PT,TT)   */  h.bill_id,
       /*modify by F.lei 20190220
       select av.bill_id,
             av.account_id,
             av.bill_line_id,
             av.account_number,
             av.bill_number,
             av.business_stage,
             av.business_type,
             av.business_type_sub,
             xtt.event_id,
             xtt.project_id,
             xtt.object_type,
             xtt.object_id,
             xtt.event_type,
             xtt.event_date,
             xtt.accounting_date,
             xtt.period_name,
             xtt.currency_code,
             xtt.amount,
             xtt.ledger_id,
             xtt.actual_flag,
             xtt.batch_name,
             xtt.batch_desc,
             xtt.journal_name,
             xtt.journal_desc,
             xtt.user_je_category_name,
             xtt.user_je_source_name,
             xtt.exchange_rate_type,
             xtt.exchange_rate_date,
             xtt.exchange_rate,
             xtt.relation_id,
             xtt.status,
             xtt.status_date,
             xtt.creation_date,
             av.reverse_status,
             av.sppi_yn,
             av.bus_model,
             av.right_yn,
             av.classify_result,
             av.devalue_stage
        from amc_bill_account_v          av,
             xxt_sl_events@toebs         xse,
             xxt_sl_entity_relatns@toebs xsr
       where av.bill_line_id = xsr.entity_id
         and xsr.relation_target_id = xtt.event_id
         and xsr.relation_target = 'EVENT'
         and xsr.entity_category = 'BAD_ASSETS';*/
       h.pack_id,
       a.account_id,
       l.bill_line_id,
       a.account_number,
       h.bill_number,
       h.business_stage,
       l.business_type,
       l.business_type_sub,
       tt.event_id,
       tt.project_id,
       tt.object_type,
       tt.object_id,
       tt.event_type,
       tt.event_date,
       tt.accounting_date,
       tt.period_name,
       tt.currency_code,
       tt.amount,
       tt.ledger_id,
       tt.actual_flag,
       tt.batch_name,
       tt.batch_desc,
       tt.journal_name,
       tt.journal_desc,
       tt.user_je_category_name,
       tt.user_je_source_name,
       tt.exchange_rate_type,
       tt.exchange_rate_date,
       tt.exchange_rate,
       tt.relation_id,
       tt.status,
       tt.status_date,
       tt.creation_date,
       h.reverse_status,
       l.sppi_yn,
       l.bus_model,
       l.right_yn,
       l.classify_result,
       l.devalue_stage,
       h.gl_date
  from amc_bill_asset_head_b       h,
       amc_bill_asset_line_b       l,
       amc_asset_account_info_b    a,
       amc_base_project_b          p,
       xxt_coa_prod_type_v         pt,
       tt  
 where 1 = 1
   and h.bill_id = l.bill_id
   and l.account_id = a.account_id
   and h.project_id = p.project_id
   and a.product_num = pt.prod_type_code
   and  l.bill_line_id  =  tt.entity_id  
   and  tt.event_type  = l.business_type
   and   object_id   =  a.account_id 
   and h.entry_status not in ('NL', 'SL_IN_ERROR', 'SL_IN_PROCESS');

改写后explain

#12s

1   #NSET2: [2057, 2817, 3337] 
2     #PIPE2: [2057, 2817, 3337] 
3       #PRJT2: [29, 2817, 3337]; exp_num(40), is_atom(FALSE) 
4         #SORT3: [29, 2817, 3337]; key_num(1), is_distinct(FALSE), top_flag(0), is_adaptive(0)
5           #UNION ALL: [26, 2817, 3337]
6             #PRJT2: [11, 1408, 3337]; exp_num(40), is_atom(FALSE) 
7               #HEAP TABLE SCAN: [11, 1408, 3337]; table_no(0) 
8             #PRJT2: [12, 1408, 3337]; exp_num(40), is_atom(FALSE) 
9               #HASH RIGHT JOIN2: [12, 1408, 3337]; key_num(1), ret_null(0), KEY(A.PACK_ID=V.PACK_ID)
10                #CSCN2: [1, 43, 78]; INDEX33557182(AMC_BILL_FINANCIAL_HEAD_B as A); btr_scan(1)
11                #HEAP TABLE SCAN: [11, 1408, 3337]; table_no(0) 
12      #HEAP TABLE: [2027, 1408, 3337]; table_no(0) full(0), mpp_full(0) autoid(0), sites(-)
13        #PRJT2: [2027, 1408, 3337]; exp_num(41), is_atom(FALSE) 
14          #HASH2 INNER JOIN: [2027, 1408, 3337];  KEY_NUM(4); KEY(TT.EVENT_TYPE=L.BUSINESS_TYPE AND TT.OBJECT_ID=A.ACCOUNT_ID AND TT.OBJECT_ID=L.ACCOUNT_ID AND exp_cast(TT.ENTITY_ID)=L.BILL_LINE_ID) KEY_NULL_EQU(0, 0, 0, 0)
15            #PRJT2: [10, 1000, 1644]; exp_num(26), is_atom(FALSE) 
16              #REMOTE SCAN: [10, 1000, 1644]; TMPREMOTETAB889763124@TOEBS
17            #HASH2 INNER JOIN: [1410, 1107893, 1693];  KEY_NUM(1); KEY(PT.PROD_TYPE_CODE=A.PRODUCT_NUM) KEY_NULL_EQU(0)
18              #PRJT2: [1, 222, 816]; exp_num(1), is_atom(FALSE) 
19                #CSCN2: [1, 222, 816]; INDEX33558407(XXT_COA_PROD_TYPE_B); btr_scan(1)
20              #HASH2 INNER JOIN: [1026, 1107900, 877]; LKEY_UNIQUE KEY_NUM(1); KEY(P.PROJECT_ID=H.PROJECT_ID) KEY_NULL_EQU(0)
21                #SSCN: [1, 9421, 30]; INDEX33557197(AMC_BASE_PROJECT_B as P); btr_scan(1)
22                #HASH2 INNER JOIN: [650, 1107900, 847]; LKEY_UNIQUE KEY_NUM(1); KEY(A.ACCOUNT_ID=L.ACCOUNT_ID) KEY_NULL_EQU(0)
23                  #CSCN2: [10, 76329, 126]; INDEX33557215(AMC_ASSET_ACCOUNT_INFO_B as A); btr_scan(1)
24                  #HASH2 INNER JOIN: [294, 1107900, 721];  KEY_NUM(1); KEY(H.BILL_ID=L.BILL_ID) KEY_NULL_EQU(0)
25                    #HASH RIGHT SEMI JOIN2: [24, 130861, 295]; n_keys(1) (ANTI), KEY(DMTEMPVIEW_889763127.colname=H.ENTRY_STATUS) KEY_NULL_EQU(0)
26                      #CONST VALUE LIST: [1, 3, 48]; row_num(3), col_num(1)
27                      #CSCN2: [24, 141472, 295]; INDEX33557166(AMC_BILL_ASSET_HEAD_B as H); btr_scan(1)
28                    #CSCN2: [150, 785045, 426]; INDEX33559141(AMC_BILL_ASSET_LINE_B as L); btr_scan(1)

用时对比

标签:不带,bill,视图,id,av,查询,type,ID,se
From: https://www.cnblogs.com/lixiaomeng/p/18172503

相关文章

  • 视图优化带条件
    sqlselectv.account_number,v.bill_id,v.account_id,v.bill_line_id,v.bill_number,v.business_type,v.business_type_sub,v.EVENT_ID,v.PROJECT_ID,v.OBJECT_TYPE,v.OBJECT_ID,v......
  • Django - 探究CBV视图
    目录数据显示视图基础视图TemplateView数据显示视图基础视图TemplateView视图类TemplateView是所有视图类里最基础的应用视图类,开发者可以直接调用应用视图类,它继承多个父类classTemplateView(TemplateResponseMixin,ContextMixin,View):"""Renderatemplate......
  • MySQL分页查询优化
    CREATETABLEteacher( `id`BIGINT(20)NOTNULLAUTO_INCREMENTPRIMARYKEY,`teacher_id`CHAR(30)NOTNULLUNIQUEKEY, `name`VARCHAR(30)NOTNULL)ENGINE=INNODB;insertintoteacher(teacher_id,name)values('aaa','aaa');inserti......
  • Django - 探究FBV 视图
    目录设置响应方式返回响应内容设置响应方式视图(Views)是Django的MTV架构模式的V部分,主要负责处理用户请求和生成响应的响应内容,也可以理解为视图是MVC架构里面的C部分(控制器),主要处理功能和业务上的逻辑。我们习惯使用视图函数处理HTTP请求,即在视图里定义def函数,这种方......
  • [POM]idea安装pom文件maven依赖查询插件
    安装前: 安装:Fle->Setting plugin->marketplace搜索“”mavenhelper“”,点击install 安装后,下方多了“DependencyAnalyzer”,支持查看全部依赖、依赖冲突,依赖树,过滤  ......
  • efcore全局查询过滤器
    我们删除实体时,平常不需要物理删除,而是软删除,软删除有什么好处呢?它能够在下次创建实体时快速恢复实体的信息,平时我们使用IsDeleted字段来代表软删除,以下是一个示例publicclassPost{publicintPostId{get;set;}publicstringTitle{get;set;}public......
  • 查询指定用户的unique,primary索引名/键值
    --1.SQL用postgres账户查询PostgreSQL中指定DB以及schema下唯一索引的信息,按照表名:索引名:索引键值并按表名排序输出SELECTt.tablenameAStable_name,i.indexnameASindex_name,string_agg(a.attname,','ORDERBYa.attnum)ASindex_keysFROMpg_i......
  • SpringBoot Jpa多条件查询
    RepositoryMyRepositoryextendsJpaRepository<MyEntity,Integer>精确查询:Example包装EntityPageablepageable=PageRequest.of(current-1,pageSize);//myEntity实体类参数Exampleexample=Example.of(myEntity);Page<MyEntity>page=myRepository.fin......
  • [WUSTCTF2020]颜值成绩查询
    [WUSTCTF2020]颜值成绩查询打开环境是一个成绩查询的页面1.手工注入输入1发现有admin的账号和得分输入1'会提示学号不存在1/**/or/**/1=1#过滤了空格1/**/order/**/by/**/3#存在1/**/order/**/by/**/4#不存在由此得知有3个字段1/**/union/**/select/**/1,2,......
  • SQL查询优化
    当多表连接数据量只有几十万时还没有优化的必要,当数据量达到几百万或几千万时就有必要了,常见于日报,实时数据。最重要的优化是走索引。可以通过查询计划查看SQL语句中开销大的查询部分是不是全表扫描。但有时候根据业务逻辑写的SQL刚好避开了索引列。这时候需要走一些弯路。可以......