以下内容适用于Oracle 10.2.0.5及其以上版本
一个查询很慢,原始SQL如下:
select
a.*
from (select
ssi.ID,
'small_station_info' TB,
(select sbi.name
from scene_base_info sbi
where sbi.id = ssi.antenna_selection) as antenna_selection,
ssi.antenna_height,
ssi.down_angle,
ssi.azimuth_angle,
ssi.ITI_ID,
sa.longitude,
sa.latitude,
sa.attach_id
from consolidation_demand cd
left join demand_test_info dti
on cd.id = dti.cd_id
left join demand_plan_info dpi
on dti.id = dpi.tdl_id
left join building_plan_info bpi
on dpi.id = bpi.dpi_id
left join NEAR_FAR_PLACE_INFO nfpi
on bpi.id = nfpi.bpi_id
left join SMALL_STATION_INFO ssi
on nfpi.id = ssi.nfpi_id
left join site_attachment sa
on TO_NUMBER(sa.longitude) is not null
AND TO_NUMBER(sa.latitude) > 26.074423
AND TO_NUMBER(sa.latitude) < 26.077573
AND TO_NUMBER(sa.longitude) > 119.191148
AND TO_NUMBER(sa.longitude) < 119.197649
AND sa.attach_name =
substr(ssi.AZIMUTH_ANGLE_PHOTO,
instr(ssi.AZIMUTH_ANGLE_PHOTO, '/', -1) + 1,
length(ssi.AZIMUTH_ANGLE_PHOTO))) a
where a.longitude is not null
表都不大,执行计划如下:
已选择 12 行。
执行计划
----------------------------------------------------------
Plan hash value: 1917963167
---------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 253 | 519 (2)| 00:00:07 |
| 1 | TABLE ACCESS BY INDEX ROWID | SCENE_BASE_INFO | 1 | 14 | 1 (0)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | SCENE_BASE_INFO_PK | 1 | | 0 (0)| 00:00:01 |
| 3 | VIEW | | 1 | 253 | 519 (2)| 00:00:07 |
|* 4 | FILTER | | | | | |
|* 5 | HASH JOIN OUTER | | 1 | 251 | 519 (2)| 00:00:07 |
|* 6 | HASH JOIN OUTER | | 83 | 8134 | 505 (1)| 00:00:07 |
|* 7 | HASH JOIN OUTER | | 83 | 7304 | 501 (1)| 00:00:07 |
|* 8 | HASH JOIN OUTER | | 83 | 6391 | 493 (1)| 00:00:06 |
|* 9 | HASH JOIN OUTER | | 83 | 5478 | 271 (1)| 00:00:04 |
| 10 | MERGE JOIN CARTESIAN | | 36 | 2052 | 21 (0)| 00:00:01 |
|* 11 | TABLE ACCESS BY INDEX ROWID| SITE_ATTACHMENT | 1 | 53 | 16 (0)| 00:00:01 |
|* 12 | INDEX RANGE SCAN | IDX_SITE_ATTACHMENT_JWD | 1 | | 15 (0)| 00:00:01 |
| 13 | BUFFER SORT | | 6725 | 26900 | 5 (0)| 00:00:01 |
| 14 | INDEX FAST FULL SCAN | PK_CONSOLIDATION_DEMAND | 6725 | 26900 | 5 (0)| 00:00:01 |
| 15 | TABLE ACCESS FULL | DEMAND_TEST_INFO | 15459 | 135K| 249 (1)| 00:00:03 |
| 16 | TABLE ACCESS FULL | DEMAND_PLAN_INFO | 8787 | 96657 | 221 (1)| 00:00:03 |
| 17 | TABLE ACCESS FULL | BUILDING_PLAN_INFO | 3244 | 35684 | 8 (0)| 00:00:01 |
| 18 | TABLE ACCESS FULL | NEAR_FAR_PLACE_INFO | 389 | 3890 | 3 (0)| 00:00:01 |
| 19 | TABLE ACCESS FULL | SMALL_STATION_INFO | 594 | 90882 | 13 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------------------