Oracle中如何优化connectby语句
Oracle中如何优化connect by语句,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
十载的荔城网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。网络营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整荔城建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联公司从事“荔城网站设计”,“荔城网站推广”以来,每个客户项目都认真落实执行。
执行SQL:
SELECT A.CI, A.ENBAJ02 AS CELL_NAME FROM TDL_CM_CELL A, T_ORG_CELL_SCOPE S WHERE S.REGION_NAME = A.REGION_NAME AND S.CITY_NAME = A.CITY_NAME AND (S.ORG_ID) IN (SELECT ID FROM T_ORG O START WITH ID = 101021003 --1010210 --START WITH ID=1 CONNECT BY PARENT_ID = PRIOR ID)
实际使用的执行计划:
而不会采用自适应计划(adaptive plan):
Plan Hash Value : 2596385940 ------------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost | Time | ------------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 2622 | 228114 | 227 | 00:00:01 | | 1 | NESTED LOOPS | | 2622 | 228114 | 227 | 00:00:01 | | 2 | NESTED LOOPS | | 2622 | 228114 | 227 | 00:00:01 | | * 3 | HASH JOIN | | 1 | 31 | 7 | 00:00:01 | | 4 | VIEW | VW_NSO_1 | 1 | 13 | 4 | 00:00:01 | | 5 | HASH UNIQUE | | 1 | 20 | 4 | 00:00:01 | | * 6 | CONNECT BY NO FILTERING WITH SW (UNIQUE) | | | | | | | 7 | TABLE ACCESS FULL | T_ORG | 75 | 825 | 3 | 00:00:01 | | 8 | TABLE ACCESS FULL | T_ORG_CELL_SCOPE | 85 | 1530 | 3 | 00:00:01 | | * 9 | INDEX RANGE SCAN | IDX_TDL_CM_CELL_SCOPE | 257 | | 8 | 00:00:01 | | 10 | TABLE ACCESS BY INDEX ROWID | TDL_CM_CELL | 2313 | 129528 | 220 | 00:00:01 | ------------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): ------------------------------------------ * 3 - access("S"."ORG_ID"="ID") * 6 - access("PARENT_ID"=PRIOR "ID") * 6 - filter("ID"=101021003) * 9 - access("S"."REGION_NAME"="A"."REGION_NAME" AND "S"."CITY_NAME"="A"."CITY_NAME") Notes ----- - This is an adaptive plan
原因在于,oracle无法知道connect by之后的数量,所以只能认为是很大的量
--
有一种方式就是,就是使用提示来解决:
SELECT /*+ no_merge(x) use_nl(a x) */ A.CI, A.ENBAJ02 AS CELL_NAME FROM TDL_CM_CELL A, (select s.city_name, s.region_name from T_ORG_CELL_SCOPE S WHERE (S.ORG_ID) IN (SELECT ID FROM T_ORG O START WITH ID = 101021003 --1010210 --START WITH ID=1 CONNECT BY PARENT_ID = PRIOR ID) ) x where x.REGION_NAME = A.REGION_NAME AND x.CITY_NAME = A.CITY_NAME
这样计划就是:
Plan Hash Value : 37846894 --------------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost | Time | --------------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 2313 | 277560 | 227 | 00:00:01 | | 1 | NESTED LOOPS | | 2313 | 277560 | 227 | 00:00:01 | | 2 | NESTED LOOPS | | 2313 | 277560 | 227 | 00:00:01 | | 3 | VIEW | | 1 | 64 | 7 | 00:00:01 | | * 4 | HASH JOIN | | 1 | 31 | 7 | 00:00:01 | | 5 | VIEW | VW_NSO_1 | 1 | 13 | 4 | 00:00:01 | | 6 | HASH UNIQUE | | 1 | 20 | 4 | 00:00:01 | | * 7 | CONNECT BY NO FILTERING WITH SW (UNIQUE) | | | | | | | 8 | TABLE ACCESS FULL | T_ORG | 75 | 825 | 3 | 00:00:01 | | 9 | TABLE ACCESS FULL | T_ORG_CELL_SCOPE | 85 | 1530 | 3 | 00:00:01 | | * 10 | INDEX RANGE SCAN | IDX_TDL_CM_CELL_SCOPE | 257 | | 8 | 00:00:01 | | 11 | TABLE ACCESS BY INDEX ROWID | TDL_CM_CELL | 2313 | 129528 | 220 | 00:00:01 | --------------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): ------------------------------------------ * 4 - access("S"."ORG_ID"="ID") * 7 - access("PARENT_ID"=PRIOR "ID") * 7 - filter("ID"=101021003) * 10 - access("X"."REGION_NAME"="A"."REGION_NAME" AND "X"."CITY_NAME"="A"."CITY_NAME")
关于Oracle中如何优化connect by语句问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。
网站栏目:Oracle中如何优化connectby语句
网站URL:http://pwwzsj.com/article/poghpo.html