總結SQL語句中的優化提示
會話級:
ALTER SESSION SET optimizer_goal= rule | first_rows | all_rows | choose ;
Hints提示:
- 提示將使語句強制執行基於成本的優化器 (除了提示RULE外)
- Use ALIASES for the tablenames in the hints.
- Ensure tables are analyzed.
語法: /*+ HINT HINT ... */
(在PLSQL中, '+'與hint的第一個字元之間的空格是很重要的
/*+ ALL_ROWS */ 是正確的,但/*+ALL_ROWS */ 是錯誤的)
1 Optimizer Mode優化模式:
FIRST_ROWS, ALL_ROWS | Force CBO first rows or all rows |
RULE | Force Rule if possible |
ORDERED | Access tables in the order of the FROM clause |
ORDERED_PREDICATES | Use in the WHERE clause to apply predicates in the order that they appear. Does not apply predicate evaluation on index keys |
.
2 子查詢或檢視:
PUSH_SUBQ | Causes all subqueries in a query block to be executed at the earliest possible time. Normally subqueries are executed as the last is applied is outerjoined or remote or joined with a merge join. (>=7.2) |
NO_MERGE(v) | Use this hint in a VIEW to PREVENT it being merged into the parent query. (>=7.2) or use NO_MERGE(v) in parent query block to prevent view V being merged |
MERGE(v) | Do merge view V |
MERGE_AJ(v) } | Put hint in a NOT IN subquery to perform (>=7.3) |
HASH_AJ(v) } | SMJ anti-join or hash anti-join. (>=7.3) Eg: SELECT .. WHERE deptno is not null AND deptno NOT IN(SELECT /*+ HASH_AJ */ deptno ...) |
HASH_SJ(v) } | Transform EXISTS subquery into HASH or MERGE |
MERGE_SJ(v) } | semi-join to access "v" |
PUSH_JOIN_PRED(v) | Push join predicates into view V |
NO_PUSH_JOIN_PRED(v) | Do NOT push join predicates |
3 讀取方式:
FULL(tab) | Use FTS on tab |
CACHE(tab) | If table within |
NOCACHE(tab) | Do not cache table even if it has CACHE option set. Only relevant for FTS |
ROWID(tab) | Access tab by ROWID directly SELECT /*+ ROWID( table ) */ ... FROM tab WHERE ROWID between '&1' and '&2'; |
CLUSTER(tab) | Use cluster scan to access 'tab' |
HASH(tab) | Use hash scan to access 'tab' |
INDEX( tab index ) | Use 'index' to access 'tab' |
INDEX_ASC( tab index ) | Use 'index' to access 'tab' for range scan. |
INDEX_DESC( tab index ) | Use descending index range scan (Join problems pre 7.3) |
INDEX_FFS( tab index) | Index fast full scan - rather than FTS. |
INDEX_COMBINE( tab i1.. i5 ) | Try to use some boolean combination of bitmap index/s i1,i2 etc |
AND_EQUAL(tab i1.. i5 ) | Merge scans of 2 to 5 single column indexes. |
USE_CONCAT | Use concatenation (Union All) for OR (or IN) statements. (>=7.2). See(7.2 requires <10078>, 7.3 no hint req)10078> |
NO_EXPAND | Do not perform OR-expansion (Ie: Do not use Concatenation). |
DRIVING_SITE(table) | Forces query execution to be done at the site where "table" resides |
4 連線:
USE_NL(tab) | Use table 'tab' as the driving table in a Nested Loops join. If the driving row source is a combination of tables name one of the tables in the inner join and the NL should drive off the entire row-source. Does not work unless accompanied by an ORDERED hint. |
USE_MERGE(tab..) | Use 'tab' as the driving table in a sort-merge join. Does not work unless accompanied by an ORDERED hint. |
USE_HASH(tab1 tab2) | Join each specified table with another row source with a hash join. 'tab1' is joined to previous row source using a hash join. (>=7.3) |
STAR | Force a star query plan if possible. A star plan has the largest table in the query last in the join order and joins it with a nested loops join on a concatenated index. The STAR hint applies when there are at least 3 tables and the large table's concatenated index has at least 3 columns and there are no conflicting access or join method hints. (>=7.3) |
STAR_TRANSFORMATION | Use best plan containing a STAR transformation(if there is one) |
5 並行查詢選項:
PARALLEL ( table, | Use parallel degree / instances as specified |
PARALLEL_INDEX(table, [ index, [ degree [,instances] ] ] ) | Parallel range scan for partitioned index |
PQ_DISTRIBUTE(tab,out,in) | How to distribute rows from tab in a PQ(out/in may be HASH/NONE/BROADCAST/PARTITION) |
NOPARALLEL(table) | No parallel on "table" |
NOPARALLEL_INDEX(table [,index]) |
|
6 Miscellaneous
APPEND | Only valid for INSERT .. SELECT. Allows INSERT to work like direct load or to perform parallel insert. |
NOAPPEND | Do not use INSERT APPEND functionality |
REWRITE(v1[,v2]) | 8.1+ With a view list use eligible materialized view Without view list use any eligible MV |
NOREWRITE | 8.1+ Do not rewrite the query |
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/35489/viewspace-84299/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SQL語句中聚合函式忽略NULL值的總結SQL函式Null
- Oracle的語句中的提示Oracle
- 總結出10條SQL語句優化精髓SQL優化
- sql語句中as的用法SQL
- Oracle SQL優化總結OracleSQL優化
- Oracle SQL優化 總結OracleSQL優化
- MySQL的SQL效能優化總結MySql優化
- 通過分析SQL語句的執行計劃優化SQL(總結)SQL優化
- sql語句中JOIN ON 的使用SQL
- sql語句中#{}和${}的區別SQL
- sql語句中as的用法和作用SQL
- sql語句中select……as的用法SQL
- SQL 優化經驗總結34條SQL優化
- SQL優化經驗總結34條SQL優化
- SQL語句中exists和in的區別SQL
- SQL語句中not in 和not exist的區別SQL
- sql語句中as的意思是什麼SQL
- 在sql語句中替換Not In 的方法SQL
- sql語句中常量的處理SQL
- SQL語句的優化SQL優化
- SQL Server優化之SQL語句優化SQLServer優化
- MySQL 52個SQL效能優化策略SQL語句彙總MySql優化
- Oracle SQL效能優化技巧大總結_水OracleSQL優化
- SQL優化經驗總結34條(一)SQL優化
- SQL優化經驗總結34條(二)SQL優化
- SQL 語句中關於 NULL 的那些坑SQLNull
- SQL語句中NULL的真實含義SQLNull
- MyBatis在SQL語句中取list的大小MyBatisSQL
- SQL精華總結索引型別優化SQL優化事務大表優化思維導圖❤️SQL索引型別優化
- SQL語句優化SQL優化
- SQL 語句的優化方法SQL優化
- SQL優化] 避免在WHERE子句中對列使用函式SQL優化函式
- sql語法總結SQL
- SQL語句中SELECT語句的執行順序SQL
- Bad SQL 優化加提示 /*+ordered */SQL優化
- SQL Server資料庫查詢優化的方法總結SQLServer資料庫優化
- 【效能優化】查詢繫結變數的sql語句優化變數SQL
- MyBatis的使用三(在sql語句中傳值)MyBatisSQL