Oracle SQL optimization-2(zt)
Oracle SQL optimization(摘自SAP Note 766349)
17. What must be considered in terms of the index design?
For more information, see Note 912620.
18. What analysis tools are available at Oracle level?
For various reasons, an SQL analysis may be useful at database level directly (for example, if no R/3 functions are available in a Java-only environment). Therefore, useful Oracle functions for SQL analysis are described below:
- Creating an SQL trace
You can use ORADEBUG (Note 613872) or DBMS_SYSTEM (Note 602667) to create an SQL trace of any session.
- Displaying an Explain plan
With the following command, the run schedule is displayed for all subsequent SQL statements, instead of them being executed:
SET AUTOTRACE TRACEONLY EXPLAIN
You can deactivate this mode with:
SET AUTOTRACE OFF
If you want to create an Explain for a statement with bind variables, the above approach does not work. You can use the following option instead:
EXPLAIN PLAN FOR ;
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);
- Display block accesses of an SQL statement
Among other things, the following command counts the Disk Reads and Buffer Gets of the subsequent SQL statements (without the actual result of the query being returned):
SET AUTOTRACE TRACEONLY
You can deactivate this mode with:
SET AUTOTRACE OFF
- PLAN statistics (Oracle >=9i)
As of Oracle 9i you can collect detailed PLAN statistics such as processed records, buffer gets, disk reads or required time. Since the collection of these extensive statistics has a significant effect on database performance, this option is normally deactivated. You can use SQLPLUS to activate and evaluate these PLAN statistics on session level for individual tests. To do this, proceed as follows:
- Activating the PLAN statistics:
ALTER SESSION SET STATISTICS_LEVEL=ALL;
- Executing the relevant SQL statements
- Query from V$SQL_PLAN_STATISTICS_ALL
SELECT
SUBSTR(LPAD(' ', PS.DEPTH) || OPERATION || ' ' ||
OPTIONS || DECODE(OBJECT_NAME, NULL, NULL, ' (' ||
OBJECT_NAME || ')'), 1, 40) ACTION,
PS.COST,
PS.CARDINALITY,
PS.LAST_OUTPUT_ROWS "ROWS_PROC",
PS.LAST_CR_BUFFER_GETS + PS.LAST_CU_BUFFER_GETS BUFFER_GETS,
PS.LAST_DISK_READS DISK_READS,
PS.LAST_ELAPSED_TIME TIME
FROM V$SQL_PLAN_STATISTICS_ALL PS, V$SQL S WHERE
S.SQL_TEXT LIKE '' AND
PS.ADDRESS = S.ADDRESS
ORDER BY PS.ID;
The columns COST and CARDINALITY contain the CBO estimates, while the columns ROWS_PROC, BUFFER_GETS, DISK_READS and TIME (in microseconds) display the actual statistics of the last execution.
- Deactivating the PLAN statistics:
ALTER SESSION SET STATISTICS_LEVEL=TYPICAL;
- PLAN-Statistiken (Oracle >= 10g)
As of Oracle 10g, you can also use the GATHER_PLAN_STATISTICS hint:
- Execute the SQL statement using the GATHER_PLAN_STATISTICS hint:
SELECT /*+ GATHER_PLAN_STATISTICS */ ...
- Indicate the execution plan using the following command:
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL,
NULL, 'ALLSTATS'));
The records and the time for each execution step are contained in the columns "A-Rows" and "A-Time".
- Sample data
In some situations, it is useful to get an impression of the data composition without having to scan the entire table or without having to rely on how representative the first records of a table are. You can use the following command to randomly select data records:
SELECT * FROM SAMPLE (
SELECT * FROM
相關文章
- oracle enqueue(zt)OracleENQ
- SQL Access Advisor(zt)SQL
- ORACLE LARGE MEMORY(zt)Oracle
- oracle event 2 (zt)Oracle
- oracle job管理(zt)Oracle
- oracle time_zone(zt)Oracle
- AUTO START ORACLE ON LINUX(zt)OracleLinux
- ORACLE MTS的介紹(zt)Oracle
- Oracle's Parallel Execution Features(zt)OracleParallel
- How Oracle Store Number internal(zt)Oracle
- SQL優化器探討(zt)SQL優化
- SQL Server 2005效能調整一(zt)SQLServer
- SQL Server 2005效能調整二(zt)SQLServer
- 修改Oracle資料庫字符集(zt)Oracle資料庫
- oracle9i下streams複製(zt)Oracle
- Oracle多粒度封鎖機制研究二(zt)Oracle
- ORACLE9I升級到10G(zt)Oracle
- Oracle PL/SQLOracleSQL
- Oracle 叢集軟體資源的手工註冊(zt)Oracle
- [Oracle]Oracle良性SQL建議OracleSQL
- 關於SQL Server中索引使用及維護簡介(zt)SQLServer索引
- 【SQL】Oracle SQL處理的流程SQLOracle
- 【SQL】Oracle SQL共享池檢查SQLOracle
- Oracle 10046 SQL TRACEOracleSQL
- Oracle SQL處理OracleSQL
- Hacking Oracle with Sql InjectionOracleSQL
- Oracle SQL Model ClauseOracleSQL
- [ORACLE] SQL執行OracleSQL
- INSTEAD OF(zt)
- lsof(zt)
- Oracle SQL精妙SQL語句講解OracleSQL
- Oracle SQL優化之sql tuning advisorOracleSQL優化
- Oracle中的sql hintOracleSQL
- Oracle 常用SQL筆記OracleSQL筆記
- Oracle基本SQL語句OracleSQL
- Oracle SQL調優系列之SQL Monitor ReportOracleSQL
- Oracle叢集檔案系統(OCFS2)使用者指南(zt)Oracle
- 【SQL】Oracle 19c SQL隔離詳解(SQL Quarantine)SQLOracle