我有查询我尝试对其进行性能调整,目前运行缓慢,大约30分钟,这并不是很好,因为我试图将此查询放入Oracle表单中
有没有办法让下面的查询更快。我应该注意什么,或者我应该尝试改善此查询的性能。
表的大小如下。
我想如果从上到下按顺序(从小表到最大值)执行下面的查询可能会更快运行。
select broadcaster_tp.THIRD_PARTY_SURR_ID
,broadcaster_tp.THIRD_PARTY_GROUP_ID
,broadcaster_tp.THIRD_PARTY_ROOT_ID
,broadcaster_tp.SUPPLIER_NAME
,broadcaster_tp.STATION_ID
,broadcaster_tp.BROADCASTER_NAME
,usage_headers.bro_broadcast_by_tp_surr_id
,usage_headers.production_number
,usage_headers.prod_exploitation_cre_surr_id
,productions.production_source
,productions.cre_surr_id
,productions.prod_series_cre_surr_id
,usage_headers.right_type
,usage_headers.dn_uls_usage_status
from ( select third_party.surr_id as THIRD_PARTY_SURR_ID,
third_party.supplier_group_id as THIRD_PARTY_GROUP_ID,
third_party.dn_root_tp_surr_id as THIRD_PARTY_ROOT_ID,
third_party.supplier_name as SUPPLIER_NAME,
broadcasters.station_id as STATION_ID,
broadcasters.dn_tp_name as BROADCASTER_NAME
from (SELECT third_parties.surr_id,
third_parties.name as supplier_name,
third_parties.tp_surr_id as supplier_group_id,
third_parties.dn_root_tp_surr_id
FROM third_parties
CONNECT BY PRIOR third_parties.surr_id = third_parties.tp_surr_id
START WITH third_parties.surr_id IN (4251,4247,4237,4034,10157)) third_party -- just a selected group of third party groups to be used
JOIN broadcasters ON (third_party.surr_id = broadcasters.tp_surr_id)) broadcaster_tp
, usage_headers
, productions
WHERE usage_headers.bro_broadcast_by_tp_surr_id = broadcaster_tp.THIRD_PARTY_SURR_ID
AND usage_headers.prod_exploitation_cre_surr_id = productions.cre_surr_id
AND usage_headers.prod_exploitation_cre_surr_id IS NOT NULL
AND usage_headers.right_type = 'M'
AND usage_headers.udg_surr_id IS NOT NULL
AND usage_headers.dn_uls_usage_status NOT IN ('9', '11') -- not deleted or distributed
AND productions.production_source <> 'AP'
AND broadcaster_tp.THIRD_PARTY_SURR_ID = 4035 -- users to pick the third party id from screen
AND broadcaster_tp.STATION_ID = 'BTWONE' -- users to pick the station id from screen
AND usage_headers.bro_broadcast_by_tp_surr_id = 4035; -- users to pick broadcaster from screen
索引和解释计划如下。
THIRD_PARTIES
INFO, INDEX_NAME, UNIQUE, LOGGING, DEGREE, COLUMN_NAME, ORDER
PLAIN, TP_PK, Y, NO, 1, SURR_ID, Asc
PLAIN, TP_TP_FK_I, N, NO, 1, TP_SURR_ID, Asc
FUNCTION, TP_UK1, Y, NO, 1, UPPER("NAME"), Asc
BROADCASTERS
INFO, INDEX_NAME, UNIQUE, LOGGING, DEGREE, COLUMN_NAME, ORDER
PLAIN, BRO_DOM_FK_I, N, YES, 1, DOM_SURR_ID, Asc
PLAIN, BRO_ELT_FK_I, N, YES, 1, ELT_CODE, Asc
PLAIN, BRO_PK, Y, YES, 1, TP_SURR_ID, Asc
PLAIN, BRO_TP_ROLLUP_FK_I, N, YES, 1, TP_ROLLUP_SURR_ID, Asc
PLAIN, BRO_UK1, Y, YES, 1, STATION_ID, Asc
USAGE_HEADERS
INFO, INDEX_NAME, UNIQUE, LOGGING, DEGREE, COLUMN_NAME, ORDER
PLAIN, UDG_ORIGINAL_SURR_ID_FK_I, N, YES, 1, UDG_ORIGINAL_SURR_ID, Asc
PLAIN, UH_BRO_BROADCAST_BY_FK_I, N, YES, 1, BRO_BROADCAST_BY_TP_SURR_ID, Asc
PLAIN, UH_BRO_ORIG_BROADCAST_BY_FK_I, N, YES, 1, BRO_ORIG_BRO_BY_TP_SURR_ID, Asc
PLAIN, UH_ELT_FK_I, N, YES, 1, ELT_CODE, Asc
PLAIN, UH_FL_FK_I, N, YES, 1, FL_SURR_ID, Asc
PLAIN, UH_I1, N, YES, 1, PERFORMANCE_DATE, Asc
BRO_BROADCAST_BY_TP_SURR_ID
PLAIN, UH_PK, Y, YES, 1, SURR_ID, Asc
PLAIN, UH_PN_I, N, YES, 1, PRODUCTION_NUMBER,
PROGRAMME_NAME
PLAIN, UH_PP_FK_I, N, YES, 1, PP_SURR_ID, Asc
PLAIN, UH_PROD_EXPLOITATION_FK_I, N, YES, 1, PROD_EXPLOITATION_CRE_SURR_ID, Asc
PLAIN, UH_UDG_FK_I, N, YES, 1, UDG_SURR_ID, Asc
PLAIN, UH_UK1, Y, YES, 1, PROD_RECEIVED_WITH_CRE_SURR_ID, Asc
PRODUCTIONS
INFO, INDEX_NAME, UNIQUE, LOGGING, DEGREE, COLUMN_NAME, ORDER
PLAIN, PROD_DOM_INT_IND_I, N, YES, 1, DOMESTIC_INTERNATIONAL_IND, Asc
PLAIN, PROD_ELT_FK, N, YES, 1, ELT_CODE, Asc
PLAIN, PROD_I2, N, YES, 1, EPISODE_NUMBER, Asc
PLAIN, PROD_I3, N, YES, 1, SUPPLIER_RELEASE_ID, Asc
PLAIN, PROD_PK, Y, YES, 1, CRE_SURR_ID, Asc
FUNCTION, PROD_PK_CHAR, Y, YES, 1, CRE_SURR_ID_CHAR, Asc
PLAIN, PROD_PROD_DUPLICATE_FK_I, N, YES, 1, PROD_DUPLICATE_CRE_SURR_ID, Asc
PLAIN, PROD_PROD_MASTER_FK_I, N, YES, 1, PROD_MASTER_CRE_SURR_ID, Asc
FUNCTION, PROD_PROD_SERIES_FK_CHAR, N, YES, 1, PROD_SERIES_CRE_SURR_ID_CHAR, Asc
PLAIN, PROD_PROD_SERIES_FK_I, N, YES, 1, PROD_SERIES_CRE_SURR_ID, Asc
PLAIN, PROD_SLH_SET_LIST_ID_I, N, YES, 1, SLH_SET_LIST_ID, Asc
---------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 7 | 924 | 6995 (1)| 00:01:24 |
| 1 | NESTED LOOPS | | | | | |
| 2 | NESTED LOOPS | | 7 | 924 | 6995 (1)| 00:01:24 |
| 3 | NESTED LOOPS | | 13 | 1573 | 6956 (1)| 00:01:24 |
| 4 | NESTED LOOPS | | 12 | 1248 | 6 (0)| 00:00:01 |
|* 5 | TABLE ACCESS BY INDEX ROWID | BROADCASTERS | 1 | 33 | 2 (0)| 00:00:01 |
|* 6 | INDEX UNIQUE SCAN | BRO_PK | 1 | | 1 (0)| 00:00:01 |
|* 7 | VIEW | | 12 | 852 | 4 (0)| 00:00:01 |
|* 8 | CONNECT BY WITH FILTERING | | | | | |
| 9 | INLIST ITERATOR | | | | | |
| 10 | TABLE ACCESS BY INDEX ROWID| THIRD_PARTIES | 5 | 180 | 4 (0)| 00:00:01 |
|* 11 | INDEX UNIQUE SCAN | TP_PK | 5 | | 2 (0)| 00:00:01 |
| 12 | NESTED LOOPS | | | | | |
| 13 | CONNECT BY PUMP | | | | | |
| 14 | TABLE ACCESS BY INDEX ROWID| THIRD_PARTIES | 12 | 432 | 4 (0)| 00:00:01 |
|* 15 | INDEX RANGE SCAN | TP_TP_FK_I | 12 | | 1 (0)| 00:00:01 |
|* 16 | TABLE ACCESS BY INDEX ROWID | USAGE_HEADERS | 1 | 17 | 595 (1)| 00:00:08 |
|* 17 | INDEX RANGE SCAN | UH_BRO_BROADCAST_BY_FK_I | 218 | | 529 (1)| 00:00:07 |
|* 18 | INDEX UNIQUE SCAN | PROD_PK | 1 | | 2 (0)| 00:00:01 |
|* 19 | TABLE ACCESS BY INDEX ROWID | PRODUCTIONS | 1 | 11 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
5 - filter("BROADCASTERS"."STATION_ID"='BTWONE')
6 - access("BROADCASTERS"."TP_SURR_ID"=4035)
7 - filter("THIRD_PARTY"."SURR_ID"=4035)
8 - access("THIRD_PARTIES"."TP_SURR_ID"=PRIOR "THIRD_PARTIES"."SURR_ID")
11 - access("THIRD_PARTIES"."SURR_ID"=4034 OR "THIRD_PARTIES"."SURR_ID"=4237 OR
"THIRD_PARTIES"."SURR_ID"=4247 OR "THIRD_PARTIES"."SURR_ID"=4251 OR "THIRD_PARTIES"."SURR_ID"=10157)
15 - access("THIRD_PARTIES"."TP_SURR_ID"=PRIOR "THIRD_PARTIES"."SURR_ID")
16 - filter("USAGE_HEADERS"."PROD_EXPLOITATION_CRE_SURR_ID" IS NOT NULL AND
"USAGE_HEADERS"."UDG_SURR_ID" IS NOT NULL AND "USAGE_HEADERS"."RIGHT_TYPE"='M' AND
"USAGE_HEADERS"."DN_ULS_USAGE_STATUS"<>'9' AND "USAGE_HEADERS"."DN_ULS_USAGE_STATUS"<>'11')
17 - access("USAGE_HEADERS"."BRO_BROADCAST_BY_TP_SURR_ID"=4035)
filter("USAGE_HEADERS"."BRO_BROADCAST_BY_TP_SURR_ID"="THIRD_PARTY"."SURR_ID")
18 - access("USAGE_HEADERS"."PROD_EXPLOITATION_CRE_SURR_ID"="PRODUCTIONS"."CRE_SURR_ID")
19 - filter("PRODUCTIONS"."PRODUCTION_SOURCE"<>'AP')