标签:
语句如下:
1 select * 2 from (select distinct a.rootcodeid SP_CODE, 3 a.parentcodeid DRAWNO, 4 a.codeid TESTCODE, 5 a.parentcode PROFILE, 6 b.desc2 SP_TESTNO, 7 b.desc3 SP_TESTNO_ENG, 8 b.remark COMMENTS, 9 b.version VERSION, 10 b.freezeflag STATUS, 11 a.relationid 12 from mdm_hczxbz_combrelationlog a, 13 mdm_hccsgl_code B, 14 mdm_hczxbz_modifyrecordlog f 15 where a.combsyscode = ‘HCCSGL‘ 16 AND A.PARENTCOMBSYSCODE = ‘HCCSFA‘ 17 and a.codeid = b.codeid 18 and a.filterid is null 19 AND a.relationid = f.relationid 20 AND f.LIMSA = 1 21 AND f.modifytype = 4 22 and exists (select 1 23 from mdm_hczxbz_synflag x 24 where x.codeid = a.rootcodeid 25 and x.synflag = ‘0‘ 26 and x.errornum = ‘0‘ 27 and synseq = ‘334248‘) 28 and exists (select 1 29 from mdm_relationsynflag k 30 where k.code1 = a.rootcodeid 31 and k.code2 = a.parentcodeid 32 and k.code3 = a.parentcode 33 and k.errornum = ‘0‘ 34 and k.relationtablename = ‘SP_DRAWS_LIMSA‘) 35 and exists (select 1 36 from mdm_hccsgl_synflag x 37 where x.codeid = a.codeid 38 and x.synflag = ‘0‘ 39 and x.errornum = ‘0‘ 40 and x.synseq = ‘334227‘) 41 and exists 42 (select 1 43 from mdm_relationsynflag k 44 where k.code1 = a.rootcodeid 45 and k.code2 = a.parentcodeid 46 and k.code3 = a.codeid 47 and k.code4 = a.parentcode 48 and k.errornum = ‘0‘ 49 and k.relationtablename = ‘SP_TESTS_LIMSA‘)) 50 where rownum < 20
执行计划信息如下:
1 Plan Hash Value : 2018468880 2 3 ------------------------------------------------------------------------------------------------------------------------ 4 | Id | Operation | Name | Rows | Bytes | Cost | Time | 5 ------------------------------------------------------------------------------------------------------------------------ 6 | 0 | SELECT STATEMENT | | 1 | 6096 | 543 | 00:00:07 | 7 | * 1 | COUNT STOPKEY | | | | | | 8 | 2 | VIEW | | 1 | 6096 | 543 | 00:00:07 | 9 | * 3 | SORT GROUP BY STOPKEY | | 1 | 463 | 543 | 00:00:07 | 10 | 4 | NESTED LOOPS SEMI | | 1 | 463 | 542 | 00:00:07 | 11 | 5 | NESTED LOOPS SEMI | | 1 | 405 | 404 | 00:00:05 | 12 | 6 | NESTED LOOPS SEMI | | 1 | 389 | 403 | 00:00:05 | 13 | 7 | NESTED LOOPS | | 1 | 374 | 402 | 00:00:05 | 14 | 8 | NESTED LOOPS | | 1 | 113 | 401 | 00:00:05 | 15 | 9 | NESTED LOOPS | | 1 | 102 | 333 | 00:00:04 | 16 | 10 | SORT UNIQUE | | 187 | 9537 | 16 | 00:00:01 | 17 | * 11 | TABLE ACCESS BY INDEX ROWID | MDM_RELATIONSYNFLAG | 187 | 9537 | 16 | 00:00:01 | 18 | * 12 | INDEX RANGE SCAN | INDEX_RELATIONSYNFLAG_REL | 195 | | 3 | 00:00:01 | 19 | * 13 | TABLE ACCESS BY INDEX ROWID | MDM_HCZXBZ_COMBRELATIONLOG | 1 | 51 | 333 | 00:00:04 | 20 | 14 | BITMAP CONVERSION TO ROWIDS | | | | | | 21 | 15 | BITMAP AND | | | | | | 22 | 16 | BITMAP CONVERSION FROM ROWIDS | | | | | | 23 | * 17 | INDEX RANGE SCAN | INDEX_HCZXBZ_COMBRELATIONLOG_D | 35 | | 1 | 00:00:01 | 24 | 18 | BITMAP CONVERSION FROM ROWIDS | | | | | | 25 | * 19 | INDEX RANGE SCAN | INDEX_HCZXBZ_COMBRELATIONLOG_F | 35 | | 2 | 00:00:01 | 26 | * 20 | TABLE ACCESS BY INDEX ROWID | MDM_HCZXBZ_MODIFYRECORDLOG | 1 | 11 | 68 | 00:00:01 | 27 | * 21 | INDEX RANGE SCAN | MDM_HCZXBZ_MODIFYRECORDLOG_A | 3709 | | 10 | 00:00:01 | 28 | 22 | TABLE ACCESS BY INDEX ROWID | MDM_HCCSGL_CODE | 1 | 261 | 1 | 00:00:01 | 29 | * 23 | INDEX UNIQUE SCAN | PK_HCCSGL_CODE | 1 | | 0 | 00:00:01 | 30 | * 24 | INDEX RANGE SCAN | UK_MDM_HCZXBZ_SYNSEQ_SYNSEQ | 135 | 2025 | 1 | 00:00:01 | 31 | * 25 | INDEX RANGE SCAN | UK_MDM_HCCSGL_SYNSEQ_SYNSEQ | 3380 | 54080 | 1 | 00:00:01 | 32 | * 26 | TABLE ACCESS BY INDEX ROWID | MDM_RELATIONSYNFLAG | 185 | 10730 | 138 | 00:00:02 | 33 | * 27 | INDEX RANGE SCAN | INDEX_RELATIONSYNFLAG_REL | 2044 | | 11 | 00:00:01 | 34 ------------------------------------------------------------------------------------------------------------------------ 35 36 Predicate Information (identified by operation id): 37 ------------------------------------------ 38 * 1 - filter(ROWNUM<20) 39 * 3 - filter(ROWNUM<20) 40 * 11 - filter("K"."ERRORNUM"=0) 41 * 12 - access("K"."RELATIONTABLENAME"=‘SP_DRAWS_LIMSA‘) 42 * 13 - filter("A"."FILTERID" IS NULL AND "A"."COMBSYSCODE"=‘HCCSGL‘ AND "A"."PARENTCOMBSYSCODE"=‘HCCSFA‘ AND "A"."ROOTCODEID"=TO_NUMBER("K"."CODE1")) 43 * 17 - access("A"."PARENTCODEID"=TO_NUMBER("K"."CODE2")) 44 * 19 - access("K"."CODE3"="A"."PARENTCODE") 45 * 20 - filter(TO_NUMBER("F"."MODIFYTYPE")=4 AND "A"."RELATIONID"="F"."RELATIONID") 46 * 21 - access("F"."LIMSA"=1) 47 * 23 - access("A"."CODEID"="B"."CODEID") 48 * 24 - access("SYNSEQ"=334248 AND "X"."CODEID"="A"."ROOTCODEID" AND "X"."SYNFLAG"=‘0‘ AND "X"."ERRORNUM"=0) 49 * 25 - access("X"."SYNSEQ"=334227 AND "X"."CODEID"="A"."CODEID" AND "X"."SYNFLAG"=‘0‘ AND "X"."ERRORNUM"=0) 50 * 26 - filter("K"."CODE4" IS NOT NULL AND "K"."ERRORNUM"=0 AND "A"."ROOTCODEID"=TO_NUMBER("K"."CODE1") AND "A"."PARENTCODEID"=TO_NUMBER("K"."CODE2") AND "A"."CODEID"=TO_NUMBER("K"."CODE3") AND 51 "K"."CODE4"="A"."PARENTCODE") 52 * 27 - access("K"."RELATIONTABLENAME"=‘SP_TESTS_LIMSA‘)
由于查询字段中并没有对表mdm_hczxbz_modifyrecordlog f表字段的查询,可以使用局部范围扫描mdm_hczxbz_modifyrecordlog f表,同时修正上面的类型转换,修改后语句如下:
1 select * 2 from (select distinct a.rootcodeid SP_CODE, 3 a.parentcodeid DRAWNO, 4 a.codeid TESTCODE, 5 a.parentcode PROFILE, 6 b.desc2 SP_TESTNO, 7 b.desc3 SP_TESTNO_ENG, 8 b.remark COMMENTS, 9 b.version VERSION, 10 b.freezeflag STATUS, 11 a.relationid 12 from mdm_hczxbz_combrelationlog a, mdm_hccsgl_code B 13 where a.combsyscode = ‘HCCSGL‘ 14 AND A.PARENTCOMBSYSCODE = ‘HCCSFA‘ 15 and a.codeid = b.codeid 16 and a.filterid is null 17 and exists (select 1 18 from mdm_hczxbz_synflag x 19 where x.codeid = a.rootcodeid 20 and x.synflag = ‘0‘ 21 and x.errornum = 0 22 and synseq = 334248) 23 and exists (select 1 24 from mdm_relationsynflag k 25 where k.code1 = a.rootcodeid 26 and k.code2 = a.parentcodeid 27 and k.code3 = a.parentcode 28 and k.errornum = 0 29 and k.relationtablename = ‘SP_DRAWS_LIMSA‘) 30 and exists (select 1 31 from mdm_hccsgl_synflag x 32 where x.codeid = a.codeid 33 and x.synflag = ‘0‘ 34 and x.errornum = 0 35 and x.synseq = 334227) 36 and exists (select 1 37 from mdm_relationsynflag k 38 where k.code1 = a.rootcodeid 39 and k.code2 = a.parentcodeid 40 and k.code3 = a.codeid 41 and k.code4 = a.parentcode 42 and k.errornum = 0 43 and k.relationtablename = ‘SP_TESTS_LIMSA‘) 44 and exists (select null 45 from mdm_hczxbz_modifyrecordlog f 46 where a.relationid = f.relationid 47 AND f.LIMSA = 1 48 AND f.modifytype = 4)) 49 where rownum < 20
如上,对mdm_hczxbz_modifyrecordlog的查询,改为exists实现了局部范围扫描。这时候的查询计划,cost为437。
Plan Hash Value : 3906393145 ---------------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost | Time | ---------------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 6096 | 437 | 00:00:06 | | * 1 | COUNT STOPKEY | | | | | | | 2 | VIEW | | 1 | 6096 | 437 | 00:00:06 | | * 3 | SORT GROUP BY STOPKEY | | 1 | 463 | 437 | 00:00:06 | | 4 | NESTED LOOPS SEMI | | 1 | 463 | 436 | 00:00:06 | | 5 | NESTED LOOPS SEMI | | 1 | 405 | 298 | 00:00:04 | | * 6 | HASH JOIN SEMI | | 1 | 389 | 297 | 00:00:04 | | 7 | NESTED LOOPS | | 40 | 13520 | 281 | 00:00:04 | | 8 | NESTED LOOPS | | 67 | 13520 | 281 | 00:00:04 | | * 9 | HASH JOIN SEMI | | 67 | 5159 | 242 | 00:00:03 | | 10 | NESTED LOOPS | | 91 | 5642 | 237 | 00:00:03 | | 11 | NESTED LOOPS | | 126 | 5642 | 237 | 00:00:03 | | 12 | SORT UNIQUE | | 84 | 924 | 68 | 00:00:01 | | * 13 | TABLE ACCESS BY INDEX ROWID | MDM_HCZXBZ_MODIFYRECORDLOG | 84 | 924 | 68 | 00:00:01 | | * 14 | INDEX RANGE SCAN | MDM_HCZXBZ_MODIFYRECORDLOG_A | 3709 | | 10 | 00:00:01 | | * 15 | INDEX RANGE SCAN | INDEX_HCZXBZ_COMBRELATIONLOG_B | 3 | | 1 | 00:00:01 | | * 16 | TABLE ACCESS BY INDEX ROWID | MDM_HCZXBZ_COMBRELATIONLOG | 1 | 51 | 4 | 00:00:01 | | * 17 | INDEX RANGE SCAN | UK_MDM_HCZXBZ_SYNSEQ_SYNSEQ | 135 | 2025 | 5 | 00:00:01 | | * 18 | INDEX UNIQUE SCAN | PK_HCCSGL_CODE | 1 | | 0 | 00:00:01 | | 19 | TABLE ACCESS BY INDEX ROWID | MDM_HCCSGL_CODE | 1 | 261 | 1 | 00:00:01 | | * 20 | TABLE ACCESS BY INDEX ROWID | MDM_RELATIONSYNFLAG | 187 | 9537 | 16 | 00:00:01 | | * 21 | INDEX RANGE SCAN | INDEX_RELATIONSYNFLAG_REL | 195 | | 3 | 00:00:01 | | * 22 | INDEX RANGE SCAN | UK_MDM_HCCSGL_SYNSEQ_SYNSEQ | 3380 | 54080 | 1 | 00:00:01 | | * 23 | TABLE ACCESS BY INDEX ROWID | MDM_RELATIONSYNFLAG | 173 | 10034 | 138 | 00:00:02 | | * 24 | INDEX RANGE SCAN | INDEX_RELATIONSYNFLAG_REL | 2044 | | 11 | 00:00:01 | ---------------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): ------------------------------------------ * 1 - filter(ROWNUM<20) * 3 - filter(ROWNUM<20) * 6 - access("A"."ROOTCODEID"=TO_NUMBER("K"."CODE1") AND "A"."PARENTCODEID"=TO_NUMBER("K"."CODE2") AND "K"."CODE3"="A"."PARENTCODE") * 9 - access("X"."CODEID"="A"."ROOTCODEID") * 13 - filter(TO_NUMBER("F"."MODIFYTYPE")=4) * 14 - access("F"."LIMSA"=1) * 15 - access("A"."RELATIONID"="F"."RELATIONID") * 16 - filter("A"."FILTERID" IS NULL AND "A"."COMBSYSCODE"=‘HCCSGL‘ AND "A"."PARENTCOMBSYSCODE"=‘HCCSFA‘) * 17 - access("SYNSEQ"=334248 AND "X"."SYNFLAG"=‘0‘ AND "X"."ERRORNUM"=0) * 17 - filter("X"."SYNFLAG"=‘0‘ AND "X"."ERRORNUM"=0) * 18 - access("A"."CODEID"="B"."CODEID") * 20 - filter("K"."ERRORNUM"=0) * 21 - access("K"."RELATIONTABLENAME"=‘SP_DRAWS_LIMSA‘) * 22 - access("X"."SYNSEQ"=334227 AND "X"."CODEID"="A"."CODEID" AND "X"."SYNFLAG"=‘0‘ AND "X"."ERRORNUM"=0) * 23 - filter("K"."CODE4" IS NOT NULL AND "K"."ERRORNUM"=0 AND "A"."ROOTCODEID"=TO_NUMBER("K"."CODE1") AND "A"."PARENTCODEID"=TO_NUMBER("K"."CODE2") AND "A"."CODEID"=TO_NUMBER("K"."CODE3") AND "K"."CODE4"="A"."PARENTCODE") * 24 - access("K"."RELATIONTABLENAME"=‘SP_TESTS_LIMSA‘
然后观察上面修改过的语句,发现有对mdm_relationsynflag k表两次扫描
1 select * 2 from (select distinct a.rootcodeid SP_CODE, 3 a.parentcodeid DRAWNO, 4 a.codeid TESTCODE, 5 a.parentcode PROFILE, 6 b.desc2 SP_TESTNO, 7 b.desc3 SP_TESTNO_ENG, 8 b.remark COMMENTS, 9 b.version VERSION, 10 b.freezeflag STATUS, 11 a.relationid 12 from mdm_hczxbz_combrelationlog a, mdm_hccsgl_code B 13 where a.combsyscode = ‘HCCSGL‘ 14 AND A.PARENTCOMBSYSCODE = ‘HCCSFA‘ 15 and a.codeid = b.codeid 16 and a.filterid is null 17 and exists (select 1 18 from mdm_hczxbz_synflag x 19 where x.codeid = a.rootcodeid 20 and x.synflag = ‘0‘ 21 and x.errornum = 0 22 and synseq = 334248) 23 and exists (select 1 24 from mdm_relationsynflag k 25 where k.code1 = a.rootcodeid 26 and k.code2 = a.parentcodeid 27 and k.code3 = a.parentcode 28 and k.errornum = 0 29 and k.relationtablename = ‘SP_DRAWS_LIMSA‘) 30 and exists (select 1 31 from mdm_hccsgl_synflag x 32 where x.codeid = a.codeid 33 and x.synflag = ‘0‘ 34 and x.errornum = 0 35 and x.synseq = 334227) 36 and exists (select 1 37 from mdm_relationsynflag k 38 where k.code1 = a.rootcodeid 39 and k.code2 = a.parentcodeid 40 and k.code3 = a.codeid 41 and k.code4 = a.parentcode 42 and k.errornum = 0 43 and k.relationtablename = ‘SP_TESTS_LIMSA‘) 44 and exists (select null 45 from mdm_hczxbz_modifyrecordlog f 46 where a.relationid = f.relationid 47 AND f.LIMSA = 1 48 AND f.modifytype = 4)) 49 where rownum < 20
继续修改语句如下,合并两次扫描
1 select * 2 from (select distinct a.rootcodeid SP_CODE, 3 a.parentcodeid DRAWNO, 4 a.codeid TESTCODE, 5 a.parentcode PROFILE, 6 b.desc2 SP_TESTNO, 7 b.desc3 SP_TESTNO_ENG, 8 b.remark COMMENTS, 9 b.version VERSION, 10 b.freezeflag STATUS, 11 a.relationid 12 from mdm_hczxbz_combrelationlog a, mdm_hccsgl_code B 13 where a.combsyscode = ‘HCCSGL‘ 14 AND A.PARENTCOMBSYSCODE = ‘HCCSFA‘ 15 and a.codeid = b.codeid 16 and a.filterid is null 17 and exists (select 1 18 from mdm_hczxbz_synflag x 19 where x.codeid = a.rootcodeid 20 and x.synflag = ‘0‘ 21 and x.errornum = 0 22 and synseq = 334248) 23 and exists (select 1 24 from mdm_relationsynflag k 25 where k.code1 = a.rootcodeid 26 and k.code2 = a.parentcodeid 27 and k.code3 = a.parentcode 28 and k.code4 = case when k.relationtablename = ‘SP_DRAWS_LIMSA‘ then k.code4 29 when k.relationtablename = ‘SP_TESTS_LIMSA‘ then a.parentcode 30 end 31 and k.errornum = 0 32 and k.relationtablename IN ( ‘SP_DRAWS_LIMSA‘,‘SP_TESTS_LIMSA‘)) 33 and exists (select 1 34 from mdm_hccsgl_synflag x 35 where x.codeid = a.codeid 36 and x.synflag = ‘0‘ 37 and x.errornum = 0 38 and x.synseq = 334227) 39 and exists (select null 40 from mdm_hczxbz_modifyrecordlog f 41 where a.relationid = f.relationid 42 AND f.LIMSA = 1 43 AND f.modifytype = 4)) 44 where rownum < 20
执行计划如下(cost 355):
Plan Hash Value : 2344144136 --------------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost | Time | --------------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 6096 | 394 | 00:00:05 | | * 1 | COUNT STOPKEY | | | | | | | 2 | VIEW | | 1 | 6096 | 394 | 00:00:05 | | * 3 | SORT GROUP BY STOPKEY | | 1 | 412 | 394 | 00:00:05 | | 4 | NESTED LOOPS SEMI | | 1 | 412 | 393 | 00:00:05 | | 5 | NESTED LOOPS SEMI | | 1 | 396 | 392 | 00:00:05 | | 6 | NESTED LOOPS | | 1 | 381 | 391 | 00:00:05 | | * 7 | HASH JOIN SEMI | | 1 | 120 | 390 | 00:00:05 | | 8 | NESTED LOOPS | | 91 | 5642 | 237 | 00:00:03 | | 9 | NESTED LOOPS | | 126 | 5642 | 237 | 00:00:03 | | 10 | SORT UNIQUE | | 84 | 924 | 68 | 00:00:01 | | * 11 | TABLE ACCESS BY INDEX ROWID | MDM_HCZXBZ_MODIFYRECORDLOG | 84 | 924 | 68 | 00:00:01 | | * 12 | INDEX RANGE SCAN | MDM_HCZXBZ_MODIFYRECORDLOG_A | 3709 | | 10 | 00:00:01 | | * 13 | INDEX RANGE SCAN | INDEX_HCZXBZ_COMBRELATIONLOG_B | 3 | | 1 | 00:00:01 | | * 14 | TABLE ACCESS BY INDEX ROWID | MDM_HCZXBZ_COMBRELATIONLOG | 1 | 51 | 4 | 00:00:01 | | 15 | INLIST ITERATOR | | | | | | | * 16 | TABLE ACCESS BY INDEX ROWID | MDM_RELATIONSYNFLAG | 2147 | 124526 | 153 | 00:00:02 | | * 17 | INDEX RANGE SCAN | INDEX_RELATIONSYNFLAG_REL | 2239 | | 14 | 00:00:01 | | 18 | TABLE ACCESS BY INDEX ROWID | MDM_HCCSGL_CODE | 1 | 261 | 1 | 00:00:01 | | * 19 | INDEX UNIQUE SCAN | PK_HCCSGL_CODE | 1 | | 0 | 00:00:01 | | * 20 | INDEX RANGE SCAN | UK_MDM_HCZXBZ_SYNSEQ_SYNSEQ | 135 | 2025 | 1 | 00:00:01 | | * 21 | INDEX RANGE SCAN | UK_MDM_HCCSGL_SYNSEQ_SYNSEQ | 3380 | 54080 | 1 | 00:00:01 | --------------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): ------------------------------------------ * 1 - filter(ROWNUM<20) * 3 - filter(ROWNUM<20) * 7 - access("A"."ROOTCODEID"=TO_NUMBER("K"."CODE1") AND "A"."PARENTCODEID"=TO_NUMBER("K"."CODE2") AND "K"."CODE3"="A"."PARENTCODE") * 7 - filter("K"."CODE4"=CASE "K"."RELATIONTABLENAME" WHEN ‘SP_DRAWS_LIMSA‘ THEN "K"."CODE4" WHEN ‘SP_TESTS_LIMSA‘ THEN "A"."PARENTCODE" END ) * 11 - filter(TO_NUMBER("F"."MODIFYTYPE")=4) * 12 - access("F"."LIMSA"=1) * 13 - access("A"."RELATIONID"="F"."RELATIONID") * 14 - filter("A"."FILTERID" IS NULL AND "A"."COMBSYSCODE"=‘HCCSGL‘ AND "A"."PARENTCOMBSYSCODE"=‘HCCSFA‘) * 16 - filter("K"."ERRORNUM"=0) * 17 - access("K"."RELATIONTABLENAME"=‘SP_DRAWS_LIMSA‘ OR "K"."RELATIONTABLENAME"=‘SP_TESTS_LIMSA‘) * 19 - access("A"."CODEID"="B"."CODEID") * 20 - access("SYNSEQ"=334248 AND "X"."CODEID"="A"."ROOTCODEID" AND "X"."SYNFLAG"=‘0‘ AND "X"."ERRORNUM"=0) * 21 - access("X"."SYNSEQ"=334227 AND "X"."CODEID"="A"."CODEID" AND "X"."SYNFLAG"=‘0‘ AND "X"."ERRORNUM"=0)
接下来,检查下a,b表连接情况及索引情况
从上面树型执行计划图,a、b是嵌套循环。
A表索引结构如下:
1 select * 2 from user_ind_columns 3 where table_name = upper(‘mdm_hczxbz_combrelationlog‘) 4 ORDER BY INDEX_NAME, COLUMN_POSITION;
结合谓词:a.combsyscode = ‘HCCSGL‘ AND A.PARENTCOMBSYSCODE = ‘HCCSFA‘ and a.filterid is null
需要为此语句添加索引信息
1 CREATE INDEX INDEX_HCZXBZ_COMBRELATIONLOG_G ON MDM_HCZXBZ_COMBRELATIONLOG(COMBSYSCODE,PARENTCOMBSYSCODE,DECODE(filterid,NULL,0));
更好地利用上面索引,需要我们修改脚本
1 select * 2 from (select distinct a.rootcodeid SP_CODE, 3 a.parentcodeid DRAWNO, 4 a.codeid TESTCODE, 5 a.parentcode PROFILE, 6 b.desc2 SP_TESTNO, 7 b.desc3 SP_TESTNO_ENG, 8 b.remark COMMENTS, 9 b.version VERSION, 10 b.freezeflag STATUS, 11 a.relationid 12 from mdm_hczxbz_combrelationlog a, mdm_hccsgl_code B 13 where a.combsyscode = ‘HCCSGL‘ 14 AND A.PARENTCOMBSYSCODE = ‘HCCSFA‘ 15 and a.codeid = b.codeid 16 and decode(a.filterid,null,0) = 0 17 and exists (select 1 18 from mdm_hczxbz_synflag x 19 where x.codeid = a.rootcodeid 20 and x.synflag = ‘0‘ 21 and x.errornum = 0 22 and synseq = 334248) 23 and exists (select 1 24 from mdm_relationsynflag k 25 where k.code1 = a.rootcodeid 26 and k.code2 = a.parentcodeid 27 and k.code3 = a.parentcode 28 and k.code4 = case when k.relationtablename = ‘SP_DRAWS_LIMSA‘ then k.code4 29 when k.relationtablename = ‘SP_TESTS_LIMSA‘ then a.parentcode 30 end 31 and k.errornum = 0 32 and k.relationtablename IN ( ‘SP_DRAWS_LIMSA‘,‘SP_TESTS_LIMSA‘)) 33 and exists (select 1 34 from mdm_hccsgl_synflag x 35 where x.codeid = a.codeid 36 and x.synflag = ‘0‘ 37 and x.errornum = 0 38 and x.synseq = 334227) 39 and exists (select null 40 from mdm_hczxbz_modifyrecordlog f 41 where a.relationid = f.relationid 42 AND f.LIMSA = 1 43 AND f.modifytype = 4)) 44 where rownum < 20
察看执行计划(cost:233)
Plan Hash Value : 2269148764 -------------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost | Time | -------------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 6096 | 233 | 00:00:03 | | * 1 | COUNT STOPKEY | | | | | | | 2 | VIEW | | 1 | 6096 | 233 | 00:00:03 | | * 3 | SORT GROUP BY STOPKEY | | 1 | 411 | 233 | 00:00:03 | | 4 | NESTED LOOPS SEMI | | 1 | 411 | 232 | 00:00:03 | | 5 | NESTED LOOPS SEMI | | 1 | 395 | 231 | 00:00:03 | | 6 | NESTED LOOPS SEMI | | 1 | 380 | 230 | 00:00:03 | | 7 | NESTED LOOPS | | 1 | 369 | 162 | 00:00:02 | | * 8 | HASH JOIN SEMI | | 1 | 108 | 161 | 00:00:02 | | 9 | TABLE ACCESS BY INDEX ROWID | MDM_HCZXBZ_COMBRELATIONLOG | 275 | 13750 | 8 | 00:00:01 | | * 10 | INDEX RANGE SCAN | INDEX_HCZXBZ_COMBRELATIONLOG_G | 110 | | 3 | 00:00:01 | | 11 | INLIST ITERATOR | | | | | | | * 12 | TABLE ACCESS BY INDEX ROWID | MDM_RELATIONSYNFLAG | 2147 | 124526 | 153 | 00:00:02 | | * 13 | INDEX RANGE SCAN | INDEX_RELATIONSYNFLAG_REL | 2239 | | 14 | 00:00:01 | | 14 | TABLE ACCESS BY INDEX ROWID | MDM_HCCSGL_CODE | 1 | 261 | 1 | 00:00:01 | | * 15 | INDEX UNIQUE SCAN | PK_HCCSGL_CODE | 1 | | 0 | 00:00:01 | | * 16 | TABLE ACCESS BY INDEX ROWID | MDM_HCZXBZ_MODIFYRECORDLOG | 84 | 924 | 68 | 00:00:01 | | * 17 | INDEX RANGE SCAN | MDM_HCZXBZ_MODIFYRECORDLOG_A | 3709 | | 10 | 00:00:01 | | * 18 | INDEX RANGE SCAN | UK_MDM_HCZXBZ_SYNSEQ_SYNSEQ | 135 | 2025 | 1 | 00:00:01 | | * 19 | INDEX RANGE SCAN | UK_MDM_HCCSGL_SYNSEQ_SYNSEQ | 3380 | 54080 | 1 | 00:00:01 | -------------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): ------------------------------------------ * 1 - filter(ROWNUM<20) * 3 - filter(ROWNUM<20) * 8 - access("A"."ROOTCODEID"=TO_NUMBER("K"."CODE1") AND "A"."PARENTCODEID"=TO_NUMBER("K"."CODE2") AND "K"."CODE3"="A"."PARENTCODE") * 8 - filter("K"."CODE4"=CASE "K"."RELATIONTABLENAME" WHEN ‘SP_DRAWS_LIMSA‘ THEN "K"."CODE4" WHEN ‘SP_TESTS_LIMSA‘ THEN "A"."PARENTCODE" END ) * 10 - access("A"."COMBSYSCODE"=‘HCCSGL‘ AND "A"."PARENTCOMBSYSCODE"=‘HCCSFA‘ AND DECODE(TO_CHAR("FILTERID"),NULL,0)=0) * 12 - filter("K"."ERRORNUM"=0) * 13 - access("K"."RELATIONTABLENAME"=‘SP_DRAWS_LIMSA‘ OR "K"."RELATIONTABLENAME"=‘SP_TESTS_LIMSA‘) * 15 - access("A"."CODEID"="B"."CODEID") * 16 - filter(TO_NUMBER("F"."MODIFYTYPE")=4 AND "A"."RELATIONID"="F"."RELATIONID") * 17 - access("F"."LIMSA"=1) * 18 - access("SYNSEQ"=334248 AND "X"."CODEID"="A"."ROOTCODEID" AND "X"."SYNFLAG"=‘0‘ AND "X"."ERRORNUM"=0) * 19 - access("X"."SYNSEQ"=334227 AND "X"."CODEID"="A"."CODEID" AND "X"."SYNFLAG"=‘0‘ AND "X"."ERRORNUM"=0)
根据关联条件a.codeid = b.codeid,检查b表索引情况
b表的codeid是有索引的,并且查询也利用到该索引(PK_HCCSGL_CODE),这样避免在嵌套循环时,内层循环的全表扫描。表连接及索引情况都正常。
接下来的修改,主要针对子查询嵌套的修改
第一个嵌套查询如下:
and exists (select 1 from mdm_hczxbz_synflag x where x.codeid = a.rootcodeid and x.synflag = ‘0‘ and x.errornum = 0 and synseq = 334248)
检查mdm_hczxbz_synflag索引情况
1 select * 2 from user_ind_columns 3 where table_name = upper(‘mdm_hczxbz_synflag‘) 4 ORDER BY INDEX_NAME, COLUMN_POSITION;
查询可以使用UK_MDM_HCZXBZ_SYNSEQ_SYNSEQ索引(SYNSEQ、CODEID、SYNFLAG、ERRORNUM),由mdm_hczxbz_combrelationlog a传过来的rootcodeid是定值,不存在索引缺失情况。
第二个嵌套查询如下:
and exists (select 1 from mdm_relationsynflag k where k.code1 = a.rootcodeid and k.code2 = a.parentcodeid and k.code3 = a.parentcode and k.code4 = case when k.relationtablename = ‘SP_DRAWS_LIMSA‘ then k.code4 when k.relationtablename = ‘SP_TESTS_LIMSA‘ then a.parentcode end and k.errornum = 0 and k.relationtablename IN ( ‘SP_DRAWS_LIMSA‘,‘SP_TESTS_LIMSA‘))
同样检查mdm_relationsynflag k的索引情况
由于mdm_relationsynflag.code1、code2、code3为字符型,而a. rootcodeid、parentcodeid、parentcode为数字类型。因此,要使用该索引,必须修改脚本。修改语句如下
1 select * 2 from (select distinct a.rootcodeid SP_CODE, 3 a.parentcodeid DRAWNO, 4 a.codeid TESTCODE, 5 a.parentcode PROFILE, 6 b.desc2 SP_TESTNO, 7 b.desc3 SP_TESTNO_ENG, 8 b.remark COMMENTS, 9 b.version VERSION, 10 b.freezeflag STATUS, 11 a.relationid 12 from mdm_hczxbz_combrelationlog a, mdm_hccsgl_code B 13 where a.combsyscode = ‘HCCSGL‘ 14 AND A.PARENTCOMBSYSCODE = ‘HCCSFA‘ 15 and a.codeid = b.codeid 16 and decode(a.filterid,null,0) = 0 17 and exists (select 1 18 from mdm_hczxbz_synflag x 19 where x.codeid = a.rootcodeid 20 and x.synflag = ‘0‘ 21 and x.errornum = 0 22 and synseq = 334248) 23 and exists (select 1 24 from mdm_relationsynflag k 25 where k.code1 = to_char(a.rootcodeid) 26 and k.code2 = to_char(a.parentcodeid) 27 and k.code3 = to_char(a.parentcode) 28 and k.code4 = case when k.relationtablename = ‘SP_DRAWS_LIMSA‘ then k.code4 29 when k.relationtablename = ‘SP_TESTS_LIMSA‘ then a.parentcode 30 end 31 and k.errornum = 0 32 and k.relationtablename IN ( ‘SP_DRAWS_LIMSA‘,‘SP_TESTS_LIMSA‘)) 33 and exists (select 1 34 from mdm_hccsgl_synflag x 35 where x.codeid = a.codeid 36 and x.synflag = ‘0‘ 37 and x.errornum = 0 38 and x.synseq = 334227) 39 and exists (select null 40 from mdm_hczxbz_modifyrecordlog f 41 where a.relationid = f.relationid 42 AND f.LIMSA = 1 43 AND f.modifytype = 4)) 44 where rownum < 20
再检查执行计划(cost:155)
Plan Hash Value : 2367419366 ------------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost | Time | ------------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 6096 | 155 | 00:00:02 | | * 1 | COUNT STOPKEY | | | | | | | 2 | VIEW | | 1 | 6096 | 155 | 00:00:02 | | * 3 | SORT GROUP BY STOPKEY | | 1 | 411 | 155 | 00:00:02 | | 4 | NESTED LOOPS SEMI | | 1 | 411 | 154 | 00:00:02 | | 5 | NESTED LOOPS SEMI | | 1 | 395 | 153 | 00:00:02 | | * 6 | HASH JOIN RIGHT SEMI | | 15 | 5055 | 108 | 00:00:02 | | * 7 | TABLE ACCESS BY INDEX ROWID | MDM_HCZXBZ_MODIFYRECORDLOG | 84 | 924 | 68 | 00:00:01 | | * 8 | INDEX RANGE SCAN | MDM_HCZXBZ_MODIFYRECORDLOG_A | 3709 | | 10 | 00:00:01 | | 9 | NESTED LOOPS | | 45 | 14670 | 40 | 00:00:01 | | 10 | NESTED LOOPS | | 45 | 14670 | 40 | 00:00:01 | | * 11 | HASH JOIN | | 45 | 2925 | 14 | 00:00:01 | | 12 | SORT UNIQUE | | 135 | 2025 | 5 | 00:00:01 | | * 13 | INDEX RANGE SCAN | UK_MDM_HCZXBZ_SYNSEQ_SYNSEQ | 135 | 2025 | 5 | 00:00:01 | | 14 | TABLE ACCESS BY INDEX ROWID | MDM_HCZXBZ_COMBRELATIONLOG | 275 | 13750 | 8 | 00:00:01 | | * 15 | INDEX RANGE SCAN | INDEX_HCZXBZ_COMBRELATIONLOG_G | 110 | | 3 | 00:00:01 | | * 16 | INDEX UNIQUE SCAN | PK_HCCSGL_CODE | 1 | | 0 | 00:00:01 | | 17 | TABLE ACCESS BY INDEX ROWID | MDM_HCCSGL_CODE | 1 | 261 | 1 | 00:00:01 | | * 18 | TABLE ACCESS BY INDEX ROWID | MDM_RELATIONSYNFLAG | 1 | 58 | 3 | 00:00:01 | | * 19 | INDEX RANGE SCAN | INDEX_RELATIONSYNFLAG_CODE3 | 1 | | 2 | 00:00:01 | | * 20 | INDEX RANGE SCAN | UK_MDM_HCCSGL_SYNSEQ_SYNSEQ | 3380 | 54080 | 1 | 00:00:01 | ------------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): ------------------------------------------ * 1 - filter(ROWNUM<20) * 3 - filter(ROWNUM<20) * 6 - access("A"."RELATIONID"="F"."RELATIONID") * 7 - filter(TO_NUMBER("F"."MODIFYTYPE")=4) * 8 - access("F"."LIMSA"=1) * 11 - access("X"."CODEID"="A"."ROOTCODEID") * 13 - access("SYNSEQ"=334248 AND "X"."SYNFLAG"=‘0‘ AND "X"."ERRORNUM"=0) * 13 - filter("X"."SYNFLAG"=‘0‘ AND "X"."ERRORNUM"=0) * 15 - access("A"."COMBSYSCODE"=‘HCCSGL‘ AND "A"."PARENTCOMBSYSCODE"=‘HCCSFA‘ AND DECODE(TO_CHAR("FILTERID"),NULL,0)=0) * 16 - access("A"."CODEID"="B"."CODEID") * 18 - filter(("K"."RELATIONTABLENAME"=‘SP_DRAWS_LIMSA‘ OR "K"."RELATIONTABLENAME"=‘SP_TESTS_LIMSA‘) AND "K"."ERRORNUM"=0 AND "K"."CODE4"=CASE "K"."RELATIONTABLENAME" WHEN ‘SP_DRAWS_LIMSA‘ THEN "K"."CODE4" WHEN ‘SP_TESTS_LIMSA‘ THEN "A"."PARENTCODE" END ) * 19 - access("K"."CODE1"=TO_CHAR("A"."ROOTCODEID") AND "K"."CODE2"=TO_CHAR("A"."PARENTCODEID") AND "K"."CODE3"="A"."PARENTCODE") * 20 - access("X"."SYNSEQ"=334227 AND "X"."CODEID"="A"."CODEID" AND "X"."SYNFLAG"=‘0‘ AND "X"."ERRORNUM"=0)
再来看第三个嵌套
and exists (select 1 from mdm_hccsgl_synflag x where x.codeid = a.codeid and x.synflag = ‘0‘ and x.errornum = 0 and x.synseq = 334227)
同样检查索引情况
查询可以使用UK_MDM_HCCSGL_SYNSEQ_SYNSEQ索引,同时,我们也发现UK_MDM_HCCSGL_SYNSEQ_CODEID索引是多余索引,前者完全包含于它。
接下来最后一个嵌套
and exists (select null from mdm_hczxbz_modifyrecordlog f where a.relationid = f.relationid AND f.LIMSA = 1 AND f.modifytype = 4)
索引情况如下
需要为该表添加索引
CREATE INDEX MDM_HCZXBZ_MODIFYRECORDLOG_E ON MDM_HCZXBZ_MODIFYRECORDLOG(RELATIONID,LIMSA,MODIFYTYPE);
添加索引后,再查看执行计划
Plan Hash Value : 1792805717 ------------------------------------------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost | Time | ------------------------------------------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 1 | 6096 | 96 | 00:00:02 | | * 1 | COUNT STOPKEY | | | | | | | 2 | VIEW | | 1 | 6096 | 96 | 00:00:02 | | * 3 | SORT GROUP BY STOPKEY | | 1 | 411 | 96 | 00:00:02 | | 4 | NESTED LOOPS SEMI | | 1 | 411 | 95 | 00:00:02 | | 5 | NESTED LOOPS SEMI | | 1 | 395 | 94 | 00:00:02 | | 6 | NESTED LOOPS | | 14 | 4718 | 52 | 00:00:01 | | * 7 | HASH JOIN SEMI | | 14 | 1064 | 44 | 00:00:01 | | * 8 | HASH JOIN | | 45 | 2925 | 14 | 00:00:01 | | 9 | SORT UNIQUE | | 135 | 2025 | 5 | 00:00:01 | | * 10 | INDEX RANGE SCAN | UK_MDM_HCZXBZ_SYNSEQ_SYNSEQ | 135 | 2025 | 5 | 00:00:01 | | 11 | TABLE ACCESS BY INDEX ROWID | MDM_HCZXBZ_COMBRELATIONLOG | 275 | 13750 | 8 | 00:00:01 | | * 12 | INDEX RANGE SCAN | INDEX_HCZXBZ_COMBRELATIONLOG_G | 110 | | 3 | 00:00:01 | | * 13 | INDEX FAST FULL SCAN | MDM_HCZXBZ_MODIFYRECORDLOG_E | 84 | 924 | 30 | 00:00:01 | | 14 | TABLE ACCESS BY INDEX ROWID | MDM_HCCSGL_CODE | 1 | 261 | 1 | 00:00:01 | | * 15 | INDEX UNIQUE SCAN | PK_HCCSGL_CODE | 1 | | 0 | 00:00:01 | | * 16 | TABLE ACCESS BY INDEX ROWID | MDM_RELATIONSYNFLAG | 1 | 58 | 3 | 00:00:01 | | * 17 | INDEX RANGE SCAN | INDEX_RELATIONSYNFLAG_CODE3 | 1 | | 2 | 00:00:01 | | * 18 | INDEX RANGE SCAN | UK_MDM_HCCSGL_SYNSEQ_SYNSEQ | 3380 | 54080 | 1 | 00:00:01 | ------------------------------------------------------------------------------------------------------------------ Predicate Information (identified by operation id): ------------------------------------------ * 1 - filter(ROWNUM<20) * 3 - filter(ROWNUM<20) * 7 - access("A"."RELATIONID"="F"."RELATIONID") * 8 - access("X"."CODEID"="A"."ROOTCODEID") * 10 - access("SYNSEQ"=334248 AND "X"."SYNFLAG"=‘0‘ AND "X"."ERRORNUM"=0) * 10 - filter("X"."SYNFLAG"=‘0‘ AND "X"."ERRORNUM"=0) * 12 - access("A"."COMBSYSCODE"=‘HCCSGL‘ AND "A"."PARENTCOMBSYSCODE"=‘HCCSFA‘ AND DECODE(TO_CHAR("FILTERID"),NULL,0)=0) * 13 - filter("F"."LIMSA"=1 AND TO_NUMBER("F"."MODIFYTYPE")=4) * 15 - access("A"."CODEID"="B"."CODEID") * 16 - filter(("K"."RELATIONTABLENAME"=‘SP_DRAWS_LIMSA‘ OR "K"."RELATIONTABLENAME"=‘SP_TESTS_LIMSA‘) AND "K"."ERRORNUM"=0 AND "K"."CODE4"=CASE "K"."RELATIONTABLENAME" WHEN ‘SP_DRAWS_LIMSA‘ THEN "K"."CODE4" WHEN ‘SP_TESTS_LIMSA‘ THEN "A"."PARENTCODE" END ) * 17 - access("K"."CODE1"=TO_CHAR("A"."ROOTCODEID") AND "K"."CODE2"=TO_CHAR("A"."PARENTCODEID") AND "K"."CODE3"="A"."PARENTCODE") * 18 - access("X"."SYNSEQ"=334227 AND "X"."CODEID"="A"."CODEID" AND "X"."SYNFLAG"=‘0‘ AND "X"."ERRORNUM"=0)
查询计划谓词部分,对MODIFYTYPE进行了类型转换,将其转换为NUMBER类型,继续修改语句
and exists (select null from mdm_hczxbz_modifyrecordlog f where a.relationid = f.relationid AND f.LIMSA = 1 AND f.modifytype = ‘4‘)
最后语句如下:
1 select * 2 from (select distinct a.rootcodeid SP_CODE, 3 a.parentcodeid DRAWNO, 4 a.codeid TESTCODE, 5 a.parentcode PROFILE, 6 b.desc2 SP_TESTNO, 7 b.desc3 SP_TESTNO_ENG, 8 b.remark COMMENTS, 9 b.version VERSION, 10 b.freezeflag STATUS, 11 a.relationid 12 from mdm_hczxbz_combrelationlog a, mdm_hccsgl_code B 13 where a.combsyscode = ‘HCCSGL‘ 14 AND A.PARENTCOMBSYSCODE = ‘HCCSFA‘ 15 and a.codeid = b.codeid 16 and decode(a.filterid,null,0) = 0 17 and exists (select 1 18 from mdm_hczxbz_synflag x 19 where x.codeid = a.rootcodeid 20 and x.synflag = ‘0‘ 21 and x.errornum = 0 22 and synseq = 334248) 23 and exists (select 1 24 from mdm_relationsynflag k 25 where k.code1 = to_char(a.rootcodeid) 26 and k.code2 = to_char(a.parentcodeid) 27 and k.code3 = to_char(a.parentcode) 28 and k.code4 = case when k.relationtablename = ‘SP_DRAWS_LIMSA‘ then k.code4 29 when k.relationtablename = ‘SP_TESTS_LIMSA‘ then a.parentcode 30 end 31 and k.errornum = 0 32 and k.relationtablename IN ( ‘SP_DRAWS_LIMSA‘,‘SP_TESTS_LIMSA‘)) 33 and exists (select 1 34 from mdm_hccsgl_synflag x 35 where x.codeid = a.codeid 36 and x.synflag = ‘0‘ 37 and x.errornum = 0 38 and x.synseq = 334227) 39 and exists (select null 40 from mdm_hczxbz_modifyrecordlog f 41 where a.relationid = f.relationid 42 AND f.LIMSA = 1 43 AND f.modifytype = ‘4‘)) 44 where rownum < 20
执行计划如下:
Plan Hash Value : 918333148 ------------------------------------------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost | Time | ------------------------------------------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 1 | 6096 | 86 | 00:00:02 | | * 1 | COUNT STOPKEY | | | | | | | 2 | VIEW | | 1 | 6096 | 86 | 00:00:02 | | * 3 | SORT GROUP BY STOPKEY | | 1 | 411 | 86 | 00:00:02 | | 4 | NESTED LOOPS SEMI | | 1 | 411 | 85 | 00:00:02 | | 5 | NESTED LOOPS SEMI | | 1 | 395 | 84 | 00:00:02 | | 6 | NESTED LOOPS | | 14 | 4718 | 42 | 00:00:01 | | * 7 | HASH JOIN SEMI | | 14 | 1064 | 34 | 00:00:01 | | * 8 | HASH JOIN | | 45 | 2925 | 14 | 00:00:01 | | 9 | SORT UNIQUE | | 135 | 2025 | 5 | 00:00:01 | | * 10 | INDEX RANGE SCAN | UK_MDM_HCZXBZ_SYNSEQ_SYNSEQ | 135 | 2025 | 5 | 00:00:01 | | 11 | TABLE ACCESS BY INDEX ROWID | MDM_HCZXBZ_COMBRELATIONLOG | 275 | 13750 | 8 | 00:00:01 | | * 12 | INDEX RANGE SCAN | INDEX_HCZXBZ_COMBRELATIONLOG_G | 110 | | 3 | 00:00:01 | | * 13 | TABLE ACCESS BY INDEX ROWID | MDM_HCZXBZ_MODIFYRECORDLOG | 84 | 924 | 20 | 00:00:01 | | * 14 | INDEX RANGE SCAN | MDM_HCZXBZ_MODIFYRECORDLOG_MT | 762 | | 6 | 00:00:01 | | 15 | TABLE ACCESS BY INDEX ROWID | MDM_HCCSGL_CODE | 1 | 261 | 1 | 00:00:01 | | * 16 | INDEX UNIQUE SCAN | PK_HCCSGL_CODE | 1 | | 0 | 00:00:01 | | * 17 | TABLE ACCESS BY INDEX ROWID | MDM_RELATIONSYNFLAG | 1 | 58 | 3 | 00:00:01 | | * 18 | INDEX RANGE SCAN | INDEX_RELATIONSYNFLAG_CODE3 | 1 | | 2 | 00:00:01 | | * 19 | INDEX RANGE SCAN | UK_MDM_HCCSGL_SYNSEQ_SYNSEQ | 3380 | 54080 | 1 | 00:00:01 | ------------------------------------------------------------------------------------------------------------------ Predicate Information (identified by operation id): ------------------------------------------ * 1 - filter(ROWNUM<20) * 3 - filter(ROWNUM<20) * 7 - access("A"."RELATIONID"="F"."RELATIONID") * 8 - access("X"."CODEID"="A"."ROOTCODEID") * 10 - access("SYNSEQ"=334248 AND "X"."SYNFLAG"=‘0‘ AND "X"."ERRORNUM"=0) * 10 - filter("X"."SYNFLAG"=‘0‘ AND "X"."ERRORNUM"=0) * 12 - access("A"."COMBSYSCODE"=‘HCCSGL‘ AND "A"."PARENTCOMBSYSCODE"=‘HCCSFA‘ AND DECODE(TO_CHAR("FILTERID"),NULL,0)=0) * 13 - filter("F"."LIMSA"=1) * 14 - access("F"."MODIFYTYPE"=‘4‘) * 16 - access("A"."CODEID"="B"."CODEID") * 17 - filter(("K"."RELATIONTABLENAME"=‘SP_DRAWS_LIMSA‘ OR "K"."RELATIONTABLENAME"=‘SP_TESTS_LIMSA‘) AND "K"."ERRORNUM"=0 AND "K"."CODE4"=CASE "K"."RELATIONTABLENAME" WHEN ‘SP_DRAWS_LIMSA‘ THEN "K"."CODE4" WHEN ‘SP_TESTS_LIMSA‘ THEN "A"."PARENTCODE" END ) * 18 - access("K"."CODE1"=TO_CHAR("A"."ROOTCODEID") AND "K"."CODE2"=TO_CHAR("A"."PARENTCODEID") AND "K"."CODE3"="A"."PARENTCODE") * 19 - access("X"."SYNSEQ"=334227 AND "X"."CODEID"="A"."CODEID" AND "X"."SYNFLAG"=‘0‘ AND "X"."ERRORNUM"=0)
上面怎样将语句一步步从cost由543调整到86的过程,对于该语句的优化并没有完成,还需要将新的语句更新进系统。
SQL语句优化,怎样将语句ctr559tupxnjq的cost一步步由543调整到86
标签:
原文地址:http://www.cnblogs.com/wangcm/p/5851870.html