Download presentation
Presentation is loading. Please wait.
Published byLogan Shaw Modified over 8 years ago
1
Optimization and Administartion of a Database Management Systems Krystian Zieja
2
Optimizer Modes There are two types of optimizer modes: Rule based Cost based
3
Diagnostic Tools STATSPACK Explain Plan SQL Trace and TKPROF SQL*Plus with autotrace feature Oracle SQL Analyze
4
Statspack The following reports on statements are provided by Statspack: SQL ordered by gets SQL ordered by reads SQL ordered by executions SQL ordered by parse calls
5
Explain Plan Can be used without tracing Needs PLAN_TABLE – use utlxplan.sql script to create it Example: EXPLAIN PLAN FOR SELECT last_name FROM hr.employees;
6
Explain Plan Remember to truncate PLAN_TABLE table before generating next plan You can also use STATEMENT ID Example: EXPLAIN PLAN SET STATEMENT_ID = ‘id’ FOR SELECT ….
7
Explain Plan Query the Plan_Table: Directly Using utlxpls.sql Using utlxplp.sql Using Dbms_xplan package
8
Task 1 Create PLAN_TABLE in Your schema Execute utlxplan.sql Describe its structure Explain plans for sample SELECT statements: EXPLAIN PLAN FOR SELECT * FROM EMP; EXPLAIN PLAN FOR SELECT ENAME FROM EMP WHERE EMPNO=7896
9
TASK 1Continue EXPLAIN PLAN FOR SELECT * FROM EMP WHERE EMPNO < 7000 Each time query plan table – operation, object name, option select operation, options, object_name, object_type, optimizer from plan_table
10
SQL Trace and TKPROF To set up SQL Trace: ALTER SESSION SET SQL_TRACE=TRUE Run your select statements ALTER SESSION SET SQL_TRACE=FALSE Format the trace using TKPROF utility Review the results
11
TKPROF
12
TKPROF statistics: Count: The number of execution calls CPU: CPU seconds used Elapsed: Total elapsed time Disk: Physical reads Query: Logical reads for consistent read Current: Logical reads in current mode Rows: Rows processed
13
Task 2 Enable Tracing in your user session (ALTER SESSION statement) Issues following statement: SELECT ename, dname, sal + nvl(comm,0) FROM emp, dept WHERE emp.deptno=dept.deptno;
14
Task 2 Continue Disable tracing in your session Using TKPROF utility prepare a report of your trace file Examine a report
15
SQL*Plus Autotrace Setup Autotrace: Create Plan_Table Create and grant plustrace role @ sqlplus\admin\plustrce.sql GRANT plustrace to SCOTT; Turn on Autotrace SET AUTOTRACE ON Turn off Autotrace SET AUTOTRACE OFF
16
SQL*Plus Autotrace Autotrace Levels: ON – SET AUTOTRACE ON OFF – SET AUTRACE OFF ON EXPLAIN – SET AUTOTRACE ON EXPLAIN ON STATISTICS - SET AUTOTRACE ON STATISTICS TRACEONLY – SET AUTOTRACE TRACEONLY
17
Task 3 Enable autotrace in SQL*Plus and deal with an option presented on previous slide Check following SQL statements SELECT sum(sal), deptno FROM emp Group by deptno Having sum(sal) > 7500
18
Task 3 Continue SELECT ename, sal, grade FROM emp, salgrade Where sal between losal and hisal and deptno in (20,30) SELECT avg(sal),dname FROM emp, dept WHERE emp.deptno = dept.deptno GROUP BY dname
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.