高效的SQL(Function-based Indexes 函式、運算優化思路)
高效的SQL(Function-based Indexes 函式、運算優化思路)
①Function-based Indexes situations
1、 UPPER function http://www.oracle-base.com/articles/8i/function-based-indexes.php
2、 col1+col2
②experiment following
1、【create table t and function-based indexes idx-t (col1 and col2)】 AND 【create table t1 and indexes idx_t1_col1(col1) 、idx_t2_col2(col2)】
doudou@TEST> desc t
Name Null? Type
----------------------------------------------------- -------- ------------------------------------
COL1 NUMBER
COL2 NUMBER
doudou@TEST> select count(*) from t;
COUNT(*)
----------
100000
doudou@TEST> create index idx_t on t(col1+col2);
Index created.
doudou@TEST> select index_type from user_indexes where table_name='T';
INDEX_TYPE
------------------------------
FUNCTION-BASED NORMAL
doudou@TEST> create table t1 as select * from t;
Table created.
doudou@TEST> create index idx_t1_col1 on t1 (col1);
Index created.
doudou@TEST> create index idx_t1_col2 on t1(col2);
Index created.
doudou@TEST> select index_type from user_indexes where table_name='T1';
INDEX_TYPE
------------------------------
NORMAL
NORMAL
2、funciton-based indexes and indexes differents
doudou@TEST> select col1+col2 from t where col1+col2<2000;
997 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 2296882198
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 3 | 78 | 4 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| IDX_T | 3 | 78 | 4 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("COL1"+"COL2"<2000)
Note
-----
- dynamic sampling used for this statement
Statistics
----------------------------------------------------------
4 recursive calls
0 db block gets
139 consistent gets
0 physical reads
0 redo size
14017 bytes sent via SQL*Net to client
1126 bytes received via SQL*Net from client
68 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
997 rows processed
【function-based indexes 中where 謂語中使用了函式也會使用索引】
doudou@TEST> select col1+col2 from t1 where col1+col2 <2000;
997 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 3617692013
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 38 | 988 | 49 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T1 | 38 | 988 | 49 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("COL1"+"COL2"<2000)
Note
-----
- dynamic sampling used for this statement
Statistics
----------------------------------------------------------
28 recursive calls
0 db block gets
326 consistent gets
0 physical reads
0 redo size
14017 bytes sent via SQL*Net to client
1126 bytes received via SQL*Net from client
68 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
997 rows processed
【normal indexes 中where謂語中使用了函式不走索引】
③總結:
基於函式的索引:
1、 可以有針對函式運算、函式進行優化。
2、 瞭解不同索引為優化提供多方位的方式。
附表
Using Function-based Indexes for Performance
http://docs.oracle.com/cd/E11882_01/server.112/e16638/data_acc.htm#PFGRF94785
A function-based index includes columns that are either transformed by a function, such as the UPPER function, or included in an expression, such as col1 + col2. With a function-based index, you can store computation-intensive expressions in the index.
Function-Based Indexes
http://docs.oracle.com/cd/E11882_01/server.112/e25789/indexiot.htm#autoId15
You can create indexes on functions and expressions that involve one or more columns in the table being indexed. A function-based index computes the value of a function or expression involving one or more columns and stores it in the index. A function-based index can be either a B-tree or a bitmap index.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26442936/viewspace-752260/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 高效的SQL(函式索引優化VIEW一例)SQL函式索引優化View
- 建立Function-Based IndexesFunctionIndex
- SQL優化--函式索引SQL優化函式索引
- 使用自定義函式創Function-Based Indexes時需要使用DETERMINISTIC Functions!函式FunctionIndex
- Function-Based Indexes (199)FunctionIndex
- Uses of Function-Based Indexes (200)FunctionIndex
- 慢Sql優化思路SQL優化
- Optimization with Function-Based Indexes (201)FunctionIndex
- Dependencies of Function-Based Indexes (202)FunctionIndex
- Resolve Dependencies of Function-Based Indexes (205)FunctionIndex
- SQL優化例項-思路分析SQL優化
- 高效的SQL(bitmap indexes optimize low cardinality columns)SQLIndex
- javascript 冪函式運算JavaScript函式
- SQL優化案例-自定義函式索引(五)SQL優化函式索引
- 關於函式索引(function-based index)函式索引FunctionIndex
- NumPy常用的位運算函式函式
- 8 連續函式的運算函式
- 高效的SQL(Index unique scan最優化)SQLIndex優化
- 高效的SQL(index range scan優化排序)SQLIndex優化排序
- SQL Server 聚合函式演算法優化技巧SQLServer函式演算法優化
- sql優化用group by 函式代替分析函式SQL優化函式
- 基於函式的索引(function-based index,FBI)函式索引FunctionIndex
- SQL優化之把運算放在列的另一端SQL優化
- Excel 優化函式Excel優化函式
- 通過IP定位區域的SQL優化思路SQL優化
- 函式計算進行自動化運維專題函式運維
- 高效的SQL【Composite Indexes(最佳前導列的選擇)】SQLIndex
- React函式式元件的效能優化React函式元件優化
- SQL優化思路&結果集重用優化、分割槽索引優化測試SQL優化索引
- 記錄一次SQL函式和優化的問題SQL函式優化
- [Oracle]高效的SQL語句之分析函式(三)OracleSQL函式
- Oracle 函式大全(字串函式,數學函式,日期函式,邏輯運算函式,其他函式)Oracle函式字串
- SQL語言運算子與函式SQL函式
- 目標函式存在累加的非線性優化問題的求解思路zzzzzzzzzzzzzzzzzzzz(1)函式優化
- SQL優化中索引列使用函式之靈異事件SQL優化索引函式事件
- SQL優化] 避免在WHERE子句中對列使用函式SQL優化函式
- [Oracle]高效的SQL語句之分析函式(一)(二)OracleSQL函式
- 系統的優化思路優化