Oracle學習系列—資料庫優化—Sort Operation
Ø SORT UNIQUE
假如使用者指定Distinct語法或者下一步操作需要唯一值,將會導致Sort Unique
Ø SORT AGGREGATE
Sort Aggregate不一定涉及到排序,當聚合用來計算所有行值時,會使用到Sort Aggregates
Ø SORT GROUP BY
當聚合用來計算不同組的資料時將會使用Sort Group By,排序需要將把行值分成不同的組
Ø SORT JOIN
假如行按照連線鍵排序,在排序合併連線時將會發生Sort Join
Ø SORT ORDER BY
指定一個不能滿足索引列的排序將需要一個Sort Order By
Example
drop table testindex; create table testindex as select * from dba_objects; alter table testindex modify owner not null; alter table testindex modify object_name not null; alter table testindex modify object_type not null; create index testfullindex on testindex(owner,object_name,object_type); analyze table testindex compute statistics; analyze index testfullindex compute statistics; |
SQL*Plus: Release 9.2.0.1.0 - Production on Wed Apr 18 20:37:41 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
SQL> connect wbq/wbq Connected. SQL> set autotrace ? Usage: SET AUTOT[RACE] {OFF | ON | TRACE[ONLY]} [EXP[LAIN]] [STAT[ISTICS]] SQL> set autotrace trace explain; SQL> select distinct owner from testindex;
Execution Plan ---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=CHOOSE (Cost=65 Card=28 Bytes=140) 1 0 SORT (UNIQUE) (Cost=65 Card=28 Bytes=140) 2 1 INDEX (FAST FULL SCAN) OF 'TESTFULLINDEX' (NON-UNIQUE) (Cost=21 Card=29530 Bytes=147650)
SQL> select sum(object_id) from testindex;
Execution Plan ---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=CHOOSE (Cost=42 Card=1 Bytes=4) 1 0 SORT (AGGREGATE) 2 1 TABLE ACCESS (FULL) OF 'TESTINDEX' (Cost=42 Card=29530 Bytes=118120)
SQL> select owner,sum(object_id) from testindex 2 group by owner;
Execution Plan ---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=CHOOSE (Cost=98 Card=28 Bytes=252) 1 0 SORT (GROUP BY) (Cost=98 Card=28 Bytes=252) 2 1 TABLE ACCESS (FULL) OF 'TESTINDEX' (Cost=42 Card=29530 Bytes=265770)
SQL> select sum(a.object_id),b.created from testindex a,testindex b 2
where a.owner<>b.owner and a.object_name 3 group by b.created;
Execution Plan ---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=CHOOSE (Cost=3891962 Card=2752 Bytes=184384) 1 0 SORT (GROUP BY) (Cost=3891962 Card=2752 Bytes=184384) 2 1 MERGE JOIN (Cost=516 Card=42043865 Bytes=2816938955) 3 2 SORT (JOIN) (Cost=251 Card=29530 Bytes=944960) 4 3 TABLE ACCESS (FULL) OF 'TESTINDEX' (Cost=42 Card=29530 Bytes=944960) 5 2 FILTER 6 5 SORT (JOIN) 7 6 TABLE ACCESS (FULL) OF 'TESTINDEX' (Cost=42 Card=29530 Bytes=1033550)
SQL> select * from testindex 2 order by created;
Execution Plan ---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=CHOOSE (Cost=794 Card=29530 Bytes=2510050) 1 0 SORT (ORDER BY) (Cost=794 Card=29530 Bytes=2510050) 2 1 TABLE ACCESS (FULL) OF 'TESTINDEX' (Cost=42 Card=29530 Bytes=2510050)
|
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/6517/viewspace-145524/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle學習系列—資料庫優化—Statistics SummaryOracle資料庫優化
- Oracle學習系列—資料庫優化—Collect StatisticsOracle資料庫優化
- Oracle學習系列—資料庫優化—效能優化工具Oracle資料庫優化
- Oracle學習系列—資料庫優化—Access Path和join學習Oracle資料庫優化
- Oracle學習系列—資料庫優化—In和Exists的使用Oracle資料庫優化
- Oracle學習系列—資料庫優化—Analyze語句和資料字典Oracle資料庫優化
- Oracle學習系列—資料庫優化—RBO訪問路徑Oracle資料庫優化
- 【原】學習系列—資料庫優化—建立效能良好的資料庫資料庫優化
- Oracle資料庫優化Oracle資料庫優化
- redis學習(六) 排序(sort,by,store,效能優化)Redis排序優化
- Oracle資料庫效能優化Oracle資料庫優化
- Oracle學習系列—資料庫備份—熱備份Oracle資料庫
- 【效能優化】ORACLE資料庫效能優化概述優化Oracle資料庫
- Oracle學習系列—資料庫最佳化—Full Scans和Fast Full Index ScansOracle資料庫ASTIndex
- oracle performance tuning效能優化學習系列(三)OracleORM優化
- oracle performance tuning效能優化學習系列(五)OracleORM優化
- oracle performance tuning效能優化學習系列(四)OracleORM優化
- oracle performance tuning效能優化學習系列(二)OracleORM優化
- oracle performance tuning效能優化學習系列(一)OracleORM優化
- ORACLE資料庫效能優化概述Oracle資料庫優化
- 【原】Oracle學習系列—資料庫備份—RMAN備份Oracle資料庫
- oracle performance tuning效能優化學習系列(四)_補OracleORM優化
- Oracle資料庫訪問效能優化Oracle資料庫優化
- Oracle資料庫效能優化總結Oracle資料庫優化
- 【原】Oracle學習系列—資料庫備份—離線備份Oracle資料庫
- Mysql資料庫優化系列(一)------Mysql伺服器優化思路MySql資料庫優化伺服器
- 【轉】Oracle資料庫優化之資料庫磁碟I/OOracle資料庫優化
- Oracle資料庫資料恢復、效能優化 ASKMACLEANOracle資料庫資料恢復優化Mac
- Oracle效能優化視訊學習筆記-資料庫配置和I/O問題Oracle優化筆記資料庫
- oracle performance tuning效能優化學習系列(三)_補二OracleORM優化
- oracle performance tuning效能優化學習系列(三)_補一OracleORM優化
- 資料庫優化 - SQL優化資料庫優化SQL
- Oracle學習系列—Window作業系統下Oracle資料庫的手工建立Oracle作業系統資料庫
- oracle資料庫巡檢優化-快速定位資料庫瓶頸Oracle資料庫優化
- 大型ORACLE資料庫優化設計方案Oracle資料庫優化
- Oracle資料庫效能優化技術(zt)Oracle資料庫優化
- 資料庫優化資料庫優化
- oracle statpack優化學習(1)Oracle優化