LES13

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
• Number of rows
• Number of blocks and empty blocks
• Average available free space • Number of chained or migrated rows • Average row length • Last ANALYZE date and sample size • Data dictionary view: DBA_TABLES
SQL> @$ORACLE_HOME/rdbms/admin/utlxplan
2. Run the EXPLAIN PLAN SQL command. 3. Query PLAN_TABLE to display the execution plans.
13-6
Copyright Ó Oracle Corporation, 1999. All rights reserved.
• Create PLAN_TABLE • Run plustrce.sql from the ORACLE_HOME/sqlplus/admin directory
SQL> @ORACLE_HOME/sqlplus/admin/plustrce.sql to scott;
Column Statistics
• Number of distinct values • Lowest value, highest value
• Last ANALYZE date and sample size
• Data dictionary view: USER_TAB_COL_STATISTICS
ANALYZE TABLE ... FOR COLUMNS ...
• Data dictionary view: DBA_HISTOGRAMS
13-18
Copyright Ó Oracle Corporation, 1999. All rights reserved.
Copying Statistics Between Databases
6. Interpret the output.
13-7
Copyright Ó Oracle Corporation, 1999. All rights reserved.
Enabling and Disabling SQL Trace
• Instance level: SQL_TRACE = {TRUE|FALSE} • Session level:
SQL> alter session set SQL_TRACE = {true|false}; SQL> execute DBMS_SESSION.SET_SQL_TRACE 2 ({true|false}); SQL> execute DBMS_SYSTEM.SET_SQL_TRACE_IN_SESSION 2 (session_id, serial_id, {true|false});
13-8
Copyright Ó Oracle Corporation, 1999. All rights reserved.
Formatting the Trace File with TKPROF
$ tkprof tracefile.trc output.txt [options]
tracefile.trc
Setting the Optimizer Mode
• Instance level:
optimizer_mode = {choose|rule|first_rows|all_rows}
• Session level:
alter session set optimizer_mode = {choose|rule|first_rows|all_rows}
• Reconfigure systems on a temporary basis for particular needs
13-3
Copyright Ó Oracle Corporation, 1999. All rights reserved.
The Role of the DBA
• Application tuning is the most important part of tuning. • DBAs may not be directly involved in application tuning. • DBAs must be familiar with the impact that poorly written SQL statements can have upon database performance.
• Rule-based:
– Uses a ranking system
– Syntax- and data dictionary–driven
• Cost-based:
– Chooses least-cost path
– Statistics-driven
13-12
Copyright Ó Oracle Corporation, 1999. All rights reserved.
• Elapsed: Total elapsed time
• Current: Logical reads in current mode
13-10
Copyright Ó Oracle Corporation, 1999. All rights reserved.
SQL*Plus AUTOTRACE
• Statement level: Using hints
13-13
Copyright Ó Oracle Corporation, 1999. All rights reserved.
Managing Statistics
• Use the ANALYZE command to collect or delete statistics. • Use the DBMS_STATS package:
13-15
Copyright Ó Oracle Corporation, 1999. All rights reserved.
Index Statistics
• Index level (height) • Number of leaf blocks and distinct keys
• Average number of leaf blocks per key
Data dictionary
User-defined statistics table
Copy to user table
2 1
Export 3 Import
Copy user table to DD
4
User-defined statistics table
13-19
Data dictionary
SQL Trace and TKPROF
1. Set the initialization parameters. 2. Invoke SQL Trace.
3. Run the application.
4. Turn off SQL Trace. 5. Format the trace file with TKPROF.
13
SQL Issues and Tuning Considerations for Different Applications
Copyright Ó Oracle Corporation, 1999. All rights reserved.
Objectives
After completing this lesson, you should be able to do the following: • Identify the role of the DBA in application tuning • Use optimizer modes to enhance SQL statement performance • Manage stored outlines to store execution paths as a series of hints
13-5
Copyright Ó Oracle Corporation, 1999. All rights reserved.
Explain Plan
• Can be used without tracing • To use the explain plan:
1. Create PLAN_TABLE with utlxplan.sql.
• AUTOTRACE syntax:
set autotrace [ off | on | traceonly ] [ explain | statistics ]
13-11
Copyright Ó Oracle Corporation, 1999. All rights reserved.
Optimizer Modes
• Average number of data blocks per key • Number of index entries
• Clustering factor
• Data dictionary view: DBA_INDEXES
13-16
Copyright Ó Oracle Corporation, 1999. All rights reserved.
13-4
Copyright Ó Oracle Corporation, 1999. All rights reserved.
Diagnostic Tools Overview
• EXPLAIN PLAN • SQL Trace and TKPROF
• SQL*Plus AUTOTRACE
• Oracle SQL Analyze
13-2
Copyright Ó Oracle Corporation, 1999. All rights reserved.
Objectives
• Use the available data access methods to tune the physical design of the database • Identify the demands of online transaction processing (OLTP) systems • Identify the demands of decision support systems (DSS)
13-17
Copyright Ó Oracle Corporation, 1999. All rights reserved.
Histograms
• Describe the data distribution of a particular column in more detail • Better predicate selectivity estimates for unevenly distributed data • Create histograms with
– GATHER_TABLE_STATS – GATHER_INDEX_STATS
– GATHER_SCHEMA_STATS
– GATHER_DATABASE_STATS
13-14
Copyright Ó Oracle Corporation, 1999. All rights reserved.
Table Statistics
output.txt
USER_DUMP_DEST
13-9
Copyright Ó Oracle Corporation, 1999. All rights reserved.
TKPROF Statistics
• Count: • CPU: • Disk: • Query: • Rows: Number of execution calls CPU seconds used Physical reads Logical reads for consistent read Rows processed
相关文档
最新文档