[20231116]降序索引取最大值.txt
[20231116]降序索引取最大值.txt
--//連結提到降序索引取最大最小值走的是INDEX FAST FULL SCAN.
--//我前面提過,許多場合下不需要建立降序索引,大部分普通索引都可以解決問題,我不像我以前系統建立一大堆降序索引.重複測試作者
--//的例子:
1.環境:
SCOTT@book> @ver1
PORT_STRING VERSION BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
create table t1 as select * from all_objects where rownum <= 10000;
alter table t1 modify object_name not null;
-- create index t1_i1a on t1(object_name);
create index t1_i1d on t1(object_name desc);
execute dbms_stats.gather_table_stats(user,'t1',cascade=>true)
2.測試:
SCOTT@book> @ sl all
alter session set statistics_level = all;
Session altered.
SCOTT@book> select max(object_name) from t1;
MAX(OBJECT_NAME)
------------------------------
_utl$_lnc_ind_parts
SCOTT@book> @ dpc '' '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID a5086qgsk6f7r, child number 0
-------------------------------------
select max(object_name) from t1
Plan hash value: 219064265
--------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers |
--------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 13 (100)| | 1 |00:00:00.01 | 48 |
| 1 | SORT AGGREGATE | | 1 | 1 | 19 | | | 1 |00:00:00.01 | 48 |
| 2 | INDEX FAST FULL SCAN| T1_I1D | 1 | 10000 | 185K| 13 (0)| 00:00:01 | 10000 |00:00:00.01 | 48 |
--------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1
2 - SEL$1 / T1@SEL$1
--//作者給出了一個重寫的sql語句,好像我以前也寫過類似語句.
SCOTT@book> select /*+ index(t1) */ utl_raw.cast_to_varchar2( sys_op_undescend( min(sys_op_descend(object_name)))) from t1;
UTL_RAW.CAST_TO_VARCHAR2(SYS_OP_UNDESCEND(MIN(SYS_OP_DESCEND(OBJECT_NAME))))
----------------------------------------------------------------------------
_utl$_lnc_ind_parts
SCOTT@book> @ dpc '' '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 8cqv0nbw9j5fn, child number 0
-------------------------------------
select /*+ index(t1) */ utl_raw.cast_to_varchar2( sys_op_undescend(
min(sys_op_descend(object_name)))) from t1
Plan hash value: 2867767823
--------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers |
--------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 44 (100)| | 1 |00:00:00.01 | 2 |
| 1 | SORT AGGREGATE | | 1 | 1 | 20 | | | 1 |00:00:00.01 | 2 |
| 2 | FIRST ROW | | 1 | 10000 | 195K| 44 (0)| 00:00:01 | 1 |00:00:00.01 | 2 |
| 3 | INDEX FULL SCAN (MIN/MAX)| T1_I1D | 1 | 10000 | 195K| 44 (0)| 00:00:01 | 1 |00:00:00.01 | 2 |
--------------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1
3 - SEL$1 / T1@SEL$1
SCOTT@book> create index t1_i1a on t1(object_name);
Index created.
SCOTT@book> select max(object_name) from t1;
MAX(OBJECT_NAME)
------------------------------
_utl$_lnc_ind_parts
SCOTT@book> @ dpc '' '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID a5086qgsk6f7r, child number 0
-------------------------------------
select max(object_name) from t1
Plan hash value: 1421318352
----------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers | Reads |
----------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 2 (100)| | 1 |00:00:00.01 | 2 | 1 |
| 1 | SORT AGGREGATE | | 1 | 1 | 19 | | | 1 |00:00:00.01 | 2 | 1 |
| 2 | INDEX FULL SCAN (MIN/MAX)| T1_I1A | 1 | 1 | 19 | 2 (0)| 00:00:01 | 1 |00:00:00.01 | 2 | 1 |
----------------------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1
2 - SEL$1 / T1@SEL$1
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2995778/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20191219]降序索引與取最大值.txt索引
- [20191209]降序索引疑問.txt索引
- [20231116]如何知道X表存在那些索引.txt索引
- [20191209]降序索引疑問2.txt索引
- [20200303]降序索引疑問5.txt索引
- [20191210]降序索引疑問3.txt索引
- [20191218]降序索引疑問4.txt索引
- [20181123]關於降序索引問題.txt索引
- [20190910]關於降序索引問題5.txt索引
- [20181124]關於降序索引問題4.txt索引
- [20181124]關於降序索引問題3.txt索引
- [20181124]關於降序索引問題2.txt索引
- MySQL資料庫表索引取樣統計MySql資料庫索引
- 使用sort方法實現陣列升序降序陣列
- 動態規劃求最長降序序列動態規劃
- 2397 求最大值
- 不能建立降序索引的問題的解決索引
- jQuery根據表格欄位升序和降序詳解jQuery
- 2397 求最大值 迴圈
- python-max()返回最大值Python
- mongodb 取欄位最大值MongoDB
- [劍指offer題解][Java]佇列的最大值/滑動視窗的最大值Java佇列
- 股票問題-求收益最大值
- 滑動視窗的最大值
- 修改陣列【並查集維護集合的最大值、連續數字的最大值】陣列並查集
- pta檢索
- ES:檢索
- jQuery 條件搜尋查詢 實時取值 升降序排序jQuery排序
- CRM中線索是什麼,如何管理線索?
- 數列區間最大值(ST表)
- 239. 滑動視窗最大值
- 最大值(最短路+最短路計數)
- 2419 求最大值和最小值
- Python求最大值的方法有哪些?Python
- 滑動視窗最大值問題
- JavaScript 獲取陣列中最大值JavaScript陣列
- 0 遞迴求最大值 (100分)遞迴
- JavaScript 陣列排序 與 求最大值JavaScript陣列排序