|
10-2
[php]
* Tuning Sort Operations
Diagnosing Problems
如果数据曾经sort,避免重新进行sort操作
当排序操作不太大,sort area过小的结果是导致增加与disk进行交换的性能开销,要保障排序操作发生在内存中
使用大量内存进行sorting可能导致paging and swapping,降低整个系统的性能 ????
经常性地在permanent tablespace上发生临时段的分配和回收
Tuning Goals
尽可能地避免不必要的排序操作
Using NOSORT to create indexes -- 在单CPU机器上使用SQL*Loader时, 如果数据已经按升序预排序
-- 在一个多CPU机器,尽管没有按次序load,并行load数据也可能快些,故可使用parallel index creation来加速sort
Using UNION ALL instead of UNION -- UNION ALL不必去除重复项,所以也不必排序
Using index access for table joins -- Nested Loop Joins 等值连接使用索引
示例:
select dept_id, id
from s_emp, s_dept
where s_emp.dept_id = s_dept.id;
-- Oracle优化器选择nested loop join代替sort-merge join,前者不请求sort操作
1. Perform a full table scan of the S_EMP table.
2. 对每个DEPT_ID,在索引PK_ID上寻找唯一匹配值,返回ROWID
3. 使用ROWID从S_DEPT表中定位匹配的row
4. 对于S_EMP的每一行,将按上述方式匹配的S_DEPT中的row合并
Creating indexes on columns referenced in the ORDER BY clause
-- 对于经常order by的列建立索引
Selecting the columns for analysis
ANALYZE... FOR COLUMNS
ANALYZE...FOR ALL INDEXED COLUMNS
ANALYZE... SIZE n -- 对指定的列创建一个柱状图(表示数据分布)
Using ESTIMATE rather than COMPUTE for large objects
ANALYZE ESTIMATE -- 对于大表或大cluster,使用ESTIMATE子句,因为COMPUTE尽管精确但需要大量的sort空间
优化内存sort和disk overhead
避免对临时段的空间分配和回收
Diagnostic Tools for Tuning Sort Operations
V$SYSSTAT -- 显示所有sorts (memory),sorts (disk),sorts (rows)的数量(since instance startup)
- sorts (disk): Number of sorts requiring I/O to temporary segments
- sorts (memory): Number of sorts performed entirely in memory
- sorts (rows): Total rows sorted in the period being monitored
select * from v$sysstat where name like '%sorts%';
STATISTIC# NAME CLASS VALUE
---------- ---------------- ---------- ----------
180 sorts (memory) 64 989221
181 sorts (disk) 64 16
182 sorts (rows) 64 78077
report.txt中提供了和V$SYSSTAT类似的信息
Statistic Total Per Transact Per Logon Per Second
-------------- --------- ------------- ------------ -----------
sorts (disk) 4 .02 .41 .01
sorts (memory) 154 .27 5.77 .12
sorts (rows) 571768 39.62 862.59 18.19
V$SORT_SEGMENT and V$SORT_USAGE 显示临时段的使用和使用的user
OEM --> Performance Manager—>Database_Instance—>System Statistics
Performance Manager—>Load—>Sort Rows Rate
[/php] |
|