分析最近管理的一个系统的数据库报告看到一条SQL执行6次,平均执行时间为57s。检查了下SQL,发现语句并无错误,从执行计划中的rows=1来看,应该是统计信息没有收集。检查了下user_tables中的统计信息,确认是没有收集。语句执行速度提升了10倍。
SELECT * FROM (SELECT INNER_TABLE.*, ROWNUM OUTER_TABLE_ROWNUM FROM (SELECT EXPERIMENTWORK_PACKAGE.EXPERIMENTWORK_PACKAGE_ID, EXPERIMENT_WORK.WORK_ID, EXPERIMENT_WORK.STANDARD_PACKAGE_ID, EXPERIMENT_WORK.PERIOD_PLAN_ID, EXPERIMENT_WORK.WORK_NAME, EXPERIMENT_WORK.WORK_CODE, EXPERIMENT_WORK.SPECIALTY, EXPERIMENT_WORK.WORK_CHARACTER, EXPERIMENT_WORK.PLACE_ID, EXPERIMENT_WORK.PLACE_NAME, EXPERIMENT_WORK.PLACE_TYPE, EXPERIMENT_WORK.MASTER, EXPERIMENT_WORK.MASTER_ID, EXPERIMENT_WORK.DEPARTMENT_ID, EXPERIMENT_WORK.DEPARTMENT_NAME, EXPERIMENT_WORK.DEPARTMENT_CODE, EXPERIMENT_WORK.WORK_TEAM, EXPERIMENT_WORK.WORK_TEAM_CODE, EXPERIMENT_WORK.WORK_TEAM_ID, EXPERIMENT_WORK.WORK_PEASONS, EXPERIMENT_WORK.STANDARD_PACKAGE_NAME, EXPERIMENT_WORK.WORK_DESCR, EXPERIMENT_WORK.PLAN_FINISH_TIME, EXPERIMENT_WORK.CREATOR, EXPERIMENT_WORK.CREATOR_ID, EXPERIMENT_WORK.CREATE_TIME, EXPERIMENT_WORK.ACTUAL_START_TIME, EXPERIMENT_WORK.ACTUAL_FINISH_TIME, EXPERIMENT_WORK.WORK_RESULT, EXPERIMENT_WORK.IS_FIELD_WORK, EXPERIMENT_WORK.BACK_FLAG, EXPERIMENT_WORK.IS_INTERRUPTED, EXPERIMENT_WORK.IS_PLANNED, EXPERIMENT_WORK.FINISH_FLAG, EXPERIMENT_WORK.QUALIFIED_FLAG, EXPERIMENT_WORK.DEVICE_STATUS, EXPERIMENT_WORK.DEVICE_LOCATION, EXPERIMENT_WORK.STATE, EXPERIMENT_WORK.REMARK, EXPERIMENT_WORK.DATA_FROM, EXPERIMENT _WORK.INSTRUMENT_MODEL, EXPERIMENT_WORK.PERIOD_UPDATE_STATE, EXPERIMENT_WORK.IS_NEED_UPDATE, EXPERIMENT_WORK.IS_DEFECT, EXPERIMENT_WORK.TYPE, EXPERIMENT_WORK.LOCATION_ID, EXPERIMENT_WORK.FUNCTION_LOCATION_NAME, EXPERIMENT_WORK.BAY_NAME, EXPERIMENT_WORK.INSTRUMENT_CODE, EXPERIMENT_WORK.PLAN_BOUND, EXPERIMENT_WORK.MANAGE_DEPARTMENT_ID, EXPERIMENT_WORK.MANAGE_DEPARTMENT, EXPERIMENT_WORK.PLAN_START_TIME, EXPERIMENT_WORK.WORK_TYPE, EXPERIMENT_WORK.VEHICLE_NO, EXPERIMENT_WORK.IS_NEED_VEHICLE, EXPERIMENT_WORK.CENTER_SUBSTATION_ID, EXPERIMENT_WORK.CENTER_SUBSTATION_NAME, EXPERIMENT_WORK.VEHICLE_TIME, EXPERIMENT_WORK.MEMBER_NUM, EXPERIMENT_WORK.IS_SHARE_VEHICLE, EXPERIMENT_WORK.DRIVER, EXPERIMENT_WORK.DRIVER_ID, EXPERIMENT_WORK.SHARE_VEHICLE_TEAM, EXPERIMENT_WORK.CONTACT_WAY, EXPERIMENT_WORK.SHARE_VEHICLE_TEAM_IDS, EXPERIMENT_WORK.IS_COMMISSIONED, EXPERIMENT_WORK.COMMISSION_WORK_ID, EXPERIMENT_WORK.OBJECT_NUMBER, EXPERIMENT_WORK.WORK_STATUS, EXPERIMENT_WORK.IS_NEED_HIGH_VEHICLE, EXPERIMENT_WORK.HIGH_VEHICLE_DRIVER, EXPERIMENT_WORK.HIGH_VEHICLE_NO, EXPERIMENT_WORK.IS_SPECIFICSAFETOOL, EXPERIMENTWORK_PACKAGE.PACKAGE_NAME, EXPERIMENTWORK_PACKAGE.IS_PASSED, EXPERIMENTWORK_PACKAGE.Package_Id, STANDARD_PACKAGE.VERSION_NO, RP_EXPERIMENT_ENVIRONMENT.ENVIRONMENT_NAME, RP_EXPERIMENT_ENVIRONMENT.ENVIRONMEN TL_PLACE, RP_EXPERIMENT_ENVIRONMENT.ENVIRONMENT_CHARACTER, RP_EXPERIMENT_ENVIRONMENT.ENVIRONMENT_DATE, RP_EXPERIMENT_ENVIRONMENT.ENVIRONMENT_CONCLUSION FROM EXPERIMENT_WORK, EXPERIMENTWORK_PACKAGE, RP_EXPERIMENT_ENVIRONMENT, STANDARD_PACKAGE, RP_REPORT_INSTANCE_OBJECT WHERE EXPERIMENT_WORK.WORK_ID = EXPERIMENTWORK_PACKAGE.WORK_ID AND RP_REPORT_INSTANCE_OBJECT.EXPERIMENTWORK_PACKAGE_ID = EXPERIMENTWORK_PACKAGE.EXPERIMENTWORK_PACKAGE_ID AND RP_REPORT_INSTANCE_OBJECT.REPORT_INSTANCE_OBJECT_ID = RP_EXPERIMENT_ENVIRONMENT.REPORT_INSTANCE_OBJECT_ID(+) AND EXPERIMENTWORK_PACKAGE.PACKAGE_ID = STANDARD_PACKAGE.STANDARD_PACKAGE_ID AND EXISTS (SELECT C.CATALOG_ID FROM STANDARD_CATALOG C WHERE C.CATALOG_ID = STANDARD_PACKAGE.CATALOG_ID START WITH C.PARENT_ID = 0 CONNECT BY PRIOR C.CATALOG_ID = C.PARENT_ID) AND (RP_EXPERIMENT_ENVIRONMENT.ENVIRONMENT_CONCLUSION = :1 OR RP_EXPERIMENT_ENVIRONMENT.ENVIRONMENT_CONCLUSION = :2) AND RP_EXPERIMENT_ENVIRONMENT.ENVIRONMENT_CHARACTER like :3 AND STANDARD_PACKAGE.STANDARD_PACKAGE_NO = :4 AND RP_EXPERIMENT_ENVIRONMENT.ENVIRONMENT_DATE >= :5 AND RP_EXPERIMENT_ENVIRONMENT.ENVIRONMENT_DATE <= :6 AND EXPERIMENT_WORK.SPECIALTY = :7 AND EXPERIMENT_WORK.WORK_TEAM_ID = :8 ORDER BY RP_EXPERIMENT_ENVIRONMENT.ENVIRONMENT_DATE asc nulls last) INNER_TABLE WHERE ROWNUM <= 18) OUTER_TABLE WHERE OUTER_TABLE_ROWNUM > 0; 已用时间: 00: 00: 06.93 执行计划 -------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| ---------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 8520 | 38 (3)| | 1 | VIEW | | 1 | 8520 | 38 (3)| | 2 | COUNT STOPKEY | | | | | | 3 | VIEW | | 1 | 8507 | 38 (3)| | 4 | SORT ORDER BY STOPKEY | | 1 | 567 | 38 (3)| | 5 | FILTER | | | | | | 6 | NESTED LOOPS | | 1 | 567 | 34 (0)| | 7 | NESTED LOOPS | | 1 | 542 | 33 (0)| | 8 | MERGE JOIN CARTESIAN | | 1 | 507 | 32 (0)| | 9 | NESTED LOOPS | | 1 | 119 | 14 (0)| | 10 | TABLE ACCESS FULL | RP_EXPERIMENT_ENVIRONMENT | 1 | 77 | 13 (0)| | 11 | TABLE ACCESS BY INDEX ROWID| RP_REPORT_INSTANCE_OBJECT | 1 | 42 | 1 (0)| | 12 | INDEX UNIQUE SCAN | PK_RP_REPORT_INSTANCE_OBJECT | 1 | | 1 (0)| | 13 | BUFFER SORT | | 10 | 3880 | 31 (0)| | 14 | TABLE ACCESS FULL | EXPERIMENT_WORK | 10 | 3880 | 18 (0)| | 15 | TABLE ACCESS BY INDEX ROWID | EXPERIMENTWORK_PACKAGE | 1 | 35 | 1 (0)| | 16 | INDEX RANGE SCAN | IDX_WORK_ID | 2 | | 1 (0)| | 17 | TABLE ACCESS BY INDEX ROWID | STANDARD_PACKAGE | 1 | 25 | 1 (0)| | 18 | INDEX UNIQUE SCAN | PK_STANDARD_PACKAGE | 1 | | 1 (0)| | 19 | FILTER | | | | | | 20 | CONNECT BY WITH FILTERING | | | | | | 21 | FILTER | | | | | | 22 | TABLE ACCESS FULL | STANDARD_CATALOG | 192 | 1536 | 3 (0)| | 23 | HASH JOIN | | | | | | 24 | CONNECT BY PUMP | | | | | | 25 | TABLE ACCESS FULL | STANDARD_CATALOG | 192 | 1536 | 3 (0)| | 26 | TABLE ACCESS FULL | STANDARD_CATALOG | 192 | 1536 | 3 (0)| ----------------------------------------------------------------------------------------------------------
统计信息 ---------------------------------------------------------- 1 recursive calls 0 db block gets 1159757 consistent gets 0 physical reads 0 redo size 6782 bytes sent via SQL*Net to client 5334 bytes received via SQL*Net from client 3 SQL*Net roundtrips to/from client 86 sorts (memory) 0 sorts (disk) 18 rows processed
执行统计信息后
已用时间: 00: 00: 00.68 执行计划 ------------------------------------------------------------------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| --------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 8520 | 497 (2)| | 1 | VIEW | | 1 | 8520 | 497 (2)| | 2 | COUNT STOPKEY | | | | | | 3 | VIEW | | 1 | 8507 | 497 (2)| | 4 | SORT ORDER BY STOPKEY | | 1 | 618 | 497 (2)| | 5 | FILTER | | | | | | 6 | NESTED LOOPS | | 1 | 618 | 493 (1)| | 7 | HASH JOIN | | 1 | 589 | 492 (1)| | 8 | TABLE ACCESS FULL | RP_EXPERIMENT_ENVIRONMENT | 8 | 608 | 139 (1)| | 9 | HASH JOIN | | 1003 | 502K| 352 (1)| | 10 | NESTED LOOPS | | 997 | 458K| 268 (1)| | 11 | TABLE ACCESS FULL | EXPERIMENT_WORK | 510 | 214K| 166 (1)| | 12 | TABLE ACCESS BY INDEX ROWID| EXPERIMENTWORK_PACKAGE | 2 | 82 | 1 (0)| | 13 | INDEX RANGE SCAN | IDX_WORK_ID | 2 | | 1 (0)| | 14 | TABLE ACCESS FULL | RP_REPORT_INSTANCE_OBJECT | 24463 | 1003K| 84 (2)| | 15 | TABLE ACCESS BY INDEX ROWID | STANDARD_PACKAGE | 1 | 29 | 1 (0)| | 16 | INDEX UNIQUE SCAN | PK_STANDARD_PACKAGE | 1 | | 1 (0)| | 17 | FILTER | | | | | | 18 | CONNECT BY WITH FILTERING | | | | | | 19 | FILTER | | | | | | 20 | TABLE ACCESS FULL | STANDARD_CATALOG | 218 | 1744 | 3 (0)| | 21 | HASH JOIN | | | | | | 22 | CONNECT BY PUMP | | | | | | 23 | TABLE ACCESS FULL | STANDARD_CATALOG | 218 | 1744 | 3 (0)| | 24 | TABLE ACCESS FULL | STANDARD_CATALOG | 218 | 1744 | 3 (0)| -----------------------------------------------------------------------------------------------
统计信息 ---------------------------------------------------------- 1 recursive calls 0 db block gets 8804 consistent gets 0 physical reads 0 redo size 6811 bytes sent via SQL*Net to client 5334 bytes received via SQL*Net from client 3 SQL*Net roundtrips to/from client 85 sorts (memory) 0 sorts (disk) 18 rows processed