SQL> set linesize 150 SQL> set pagesize 2000 SQL> set autotrace traceonly exp SQL> select avg(SALARY),DEPARTMENT_NAME from employees e,departments d where e.DEPARTMENT_ID=d.DEPARTMENT_ID group by DEPARTMENT_NAME; Execution Plan ---------------------------------------------------------- Plan hash value: 3294250112 --------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 27 | 621 | 5 (20)| 00:00:01 | | 1 | HASH GROUP BY | | 27 | 621 | 5 (20)| 00:00:01 | | 2 | NESTED LOOPS | | 106 | 2438 | 4 (0)| 00:00:01 | | 3 | TABLE ACCESS FULL | EMPLOYEES | 107 | 749 | 3 (0)| 00:00:01 | | 4 | TABLE ACCESS BY INDEX ROWID| DEPARTMENTS | 1 | 16 | 1 (0)| 00:00:01 | |* 5 | INDEX UNIQUE SCAN | DEPT_ID_PK | 1 | | 0 (0)| 00:00:01 | --------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 5 - access("E"."DEPARTMENT_ID"="D"."DEPARTMENT_ID") SQL> show parameter cursor_sharing NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ cursor_sharing string EXACT SQL> show parameter statistics_level NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ statistics_level string TYPICAL SQL> set autotrace off; SQL> select /*+ gather_plan_statistics */ avg(SALARY),DEPARTMENT_NAME from employees e,departments d where e.DEPARTMENT_ID=d.DEPARTMENT_ID group by DEPARTMENT_NAME; SQL> select * from TABLE(dbms_xplan.display_cursor(NULL,NULL,'ALLSTATS LAST')); PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------ SQL_ID bctzu9xuxay18, child number 0 ------------------------------------- select /*+ gather_plan_statistics */ avg(SALARY),DEPARTMENT_NAME from employees e,departments d where e.DEPARTMENT_ID=d.DEPARTMENT_ID group by DEPARTMENT_NAME Plan hash value: 3294250112 ------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | ------------------------------------------------------------------------------------------------------- | 1 | HASH GROUP BY | | 1 | 27 | 11 |00:00:00.01 | 219 | | 2 | NESTED LOOPS | | 1 | 106 | 106 |00:00:00.01 | 219 | | 3 | TABLE ACCESS FULL | EMPLOYEES | 1 | 107 | 107 |00:00:00.01 | 7 | | 4 | TABLE ACCESS BY INDEX ROWID| DEPARTMENTS | 107 | 1 | 106 |00:00:00.01 | 212 | |* 5 | INDEX UNIQUE SCAN | DEPT_ID_PK | 107 | 1 | 106 |00:00:00.01 | 106 | ------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 5 - access("E"."DEPARTMENT_ID"="D"."DEPARTMENT_ID") /* 可以从starts列看到某种操作执行了多少次,例如这里的INDEX UNIQUE SCAN为107次 */ /*也可以通过SQL_ID来定位计划信息 */ SQL> select t.* from v$sql s , table(dbms_xplan.display_cursor(s.sql_id,s.child_number,'ALL IOSTATS LAST')) t where s.sql_id = '&SQL_ID' ; Enter value for sql_id: bctzu9xuxay18 old 3: , table(dbms_xplan.display_cursor(s.sql_id,s.child_number,'ALL IOSTATS LAST')) t where s.sql_id = '&SQL_ID' new 3: , table(dbms_xplan.display_cursor(s.sql_id,s.child_number,'ALL IOSTATS LAST')) t where s.sql_id = 'bctzu9xuxay18' PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------ SQL_ID bctzu9xuxay18, child number 0 ------------------------------------- select /*+ gather_plan_statistics */ avg(SALARY),DEPARTMENT_NAME from employees e,departments d where e.DEPARTMENT_ID=d.DEPARTMENT_ID group by DEPARTMENT_NAME Plan hash value: 3294250112 --------------------------------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers | --------------------------------------------------------------------------------------------------------------------------------------- | 1 | HASH GROUP BY | | 1 | 27 | 621 | 5 (20)| 00:00:01 | 11 |00:00:00.01 | 219 | | 2 | NESTED LOOPS | | 1 | 106 | 2438 | 4 (0)| 00:00:01 | 106 |00:00:00.01 | 219 | | 3 | TABLE ACCESS FULL | EMPLOYEES | 1 | 107 | 749 | 3 (0)| 00:00:01 | 107 |00:00:00.01 | 7 | | 4 | TABLE ACCESS BY INDEX ROWID| DEPARTMENTS | 107 | 1 | 16 | 1 (0)| 00:00:01 | 106 |00:00:00.01 | 212 | |* 5 | INDEX UNIQUE SCAN | DEPT_ID_PK | 107 | 1 | | 0 (0)| | 106 |00:00:00.01 | 106 | --------------------------------------------------------------------------------------------------------------------------------------- Query Block Name / Object Alias (identified by operation id): ------------------------------------------------------------- 1 - SEL$1 3 - SEL$1 / E@SEL$1 4 - SEL$1 / D@SEL$1 5 - SEL$1 / D@SEL$1 Predicate Information (identified by operation id): --------------------------------------------------- 5 - access("E"."DEPARTMENT_ID"="D"."DEPARTMENT_ID") Column Projection Information (identified by operation id): ----------------------------------------------------------- 1 - "DEPARTMENT_NAME"[VARCHAR2,30], AVG("SALARY")[22] 2 - "SALARY"[NUMBER,22], "DEPARTMENT_NAME"[VARCHAR2,30] 3 - "SALARY"[NUMBER,22], "E"."DEPARTMENT_ID"[NUMBER,22] 4 - "DEPARTMENT_NAME"[VARCHAR2,30] 5 - "D".ROWID[ROWID,10] SQL> alter session set statistics_level=ALL; Session altered. /* 在session级别设置statistics_level为ALL,可以为我们提供更为详尽的执行统计信息 */
Gather more plan statistics by gather_plan_statistics hint
原创maclean_007 ©著作权
文章标签 Oracle SQL tuning gather_plan_statisti v$sql_plan 文章分类 Oracle 数据库
-
使用Azure Automation自动调整App Services Plan大小
说到App Services Plan大家可能比较陌生,但是如果提到Azure App Services大家肯定都很熟悉,相信很多朋友都在其上托管了一些Web应用。其实我们所使用的App Services始终是在App Services Plan中运行的。App Services Plan的定价层确定了所提供的App Services功能和计划费用。这也就意味着,如果想要控制App Services所产生的费用,就需要从App Services Plan入手。
Azure 成本优化 App Services Plan Web应用 -
GATHER COMMAND
将当前选定表中当前记录的数据替换为某个数组、一组内存变量或对象中的数据
array 替换 command vfp gather scatter -
pg_hint_plan 使用hint固定SQL执行计划
背景有一个功能,是社区官方版”永远”不考虑引入的(参见PG TODO,查找”Ora
sql 数据库 bc SQL PostgreSQL -
Level Statistics
"A. Level Statistics" 思考的时候一定不要担心会浪费时间!! 要把问题考虑清楚!!
思维 ios #include c++