[20181124]關於降序索引問題4.txt
[20181124]關於降序索引問題4.txt
--//連續寫3篇關於降序索引相關問題,連結:
http://blog.itpub.net/267265/viewspace-2221425/
http://blog.itpub.net/267265/viewspace-2221527/
http://blog.itpub.net/267265/viewspace-2221529/
--//我自己還有一個小疑問,沒有答案,在解答前,自己在測試如果插入字串lpad('a',3999,'a')||chr(0),降序索引如何儲存鍵值的.
1.環境:
SCOTT@test01p> @ ver1
PORT_STRING VERSION BANNER CON_ID
------------------------------ -------------- -------------------------------------------------------------------------------- ----------
IBMPC/WIN_NT64-9.1.0 12.2.0.1.0 Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production 0
2.測試:
create table t (id number,name varchar2(4000));
insert into t values (1,lpad('a',3999,'a')||chr(0));
insert into t values (2,lpad('a',3999,'a')||chr(1));
commit ;
SCOTT@test01p> create index if_t_name on t(name desc);
create index if_t_name on t(name desc)
*
ERROR at line 1:
ORA-01706: user function result value was too large
D:\tools\rlwrap>oerr ora 1706
oerr ora 1706
01706, 00000, "user function result value was too large"
// *Cause:
// *Action:
--//應該是長度超出範圍.
3.繼續測試:
SCOTT@test01p> delete from t;
2 rows deleted.
SCOTT@test01p> commit ;
Commit complete.
insert into t values (1,'aaaaa');
insert into t values (2,'bbbbb');
commit;
SCOTT@test01p> create index if_t_name on t(name desc);
Index created.
SCOTT@test01p> create index if_t_namex on t(sys_op_descend(name));
create index if_t_namex on t(sys_op_descend(name))
*
ERROR at line 1:
ORA-01408: such column list already indexed
--//可以發現實際上降序索引,就是建立sys_op_descend(name)的索引.
SCOTT@test01p> alter session set statistics_level=all;
Session altered.
SCOTT@test01p> select * from t where name='aaaaa';
ID NAME
---------- --------------------
1 aaaaa
SCOTT@test01p> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 5xp1axyac2pgj, child number 0
-------------------------------------
select * from t where name='aaaaa'
Plan hash value: 4146574435
-------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers |
-------------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 2 (100)| | 1 |00:00:00.01 | 2 |
| 1 | TABLE ACCESS BY INDEX ROWID BATCHED| T | 1 | 1 | 9 | 2 (0)| 00:00:01 | 1 |00:00:00.01 | 2 |
|* 2 | INDEX RANGE SCAN | IF_T_NAME | 1 | 1 | | 1 (0)| 00:00:01 | 1 |00:00:00.01 | 1 |
-------------------------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / T@SEL$1
2 - SEL$1 / T@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("T"."SYS_NC00003$"=HEXTORAW('9E9E9E9E9EFF'))
filter(SYS_OP_UNDESCEND("T"."SYS_NC00003$")='aaaaa')
--//我有點不理解的是為什麼還有加一層fliter.不理解.
SCOTT@test01p> drop index if_t_name;
Index dropped.
SCOTT@test01p> create index if_t_namex on t(sys_op_descend(name));
Index created.
SCOTT@test01p> select * from t where sys_op_descend(name)=hextoraw('9E9E9E9E9EFF');
ID NAME
---------- --------------------
1 aaaaa
SCOTT@test01p> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID cvyst4uqj6rxy, child number 0
-------------------------------------
select * from t where sys_op_descend(name)=hextoraw('9E9E9E9E9EFF')
Plan hash value: 3955378873
---------------------------------------------------------------------------------------------------
| Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time |
---------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 2 (100)| |
| 1 | TABLE ACCESS BY INDEX ROWID BATCHED| T | 1 | 9 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | IF_T_NAMEX | 1 | | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / T@SEL$1
2 - SEL$1 / T@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("T"."SYS_NC00003$"=HEXTORAW('9E9E9E9E9EFF'))
--//噢.明白了.實際上如果這樣寫sys_op_descend(name)=hextoraw('9E9E9E9E9EFF')查詢條件,就不會存在過濾了.
SCOTT@test01p> drop index if_t_namex;
Index dropped.
SCOTT@test01p> create index if_t_name on t(name desc);
Index created.
SCOTT@test01p> select * from t where sys_op_descend(name)=hextoraw('9E9E9E9E9EFF');
ID NAME
---------- --------------------
1 aaaaa
SCOTT@test01p> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID cvyst4uqj6rxy, child number 1
-------------------------------------
select * from t where sys_op_descend(name)=hextoraw('9E9E9E9E9EFF')
Plan hash value: 4146574435
-------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers |
-------------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 2 (100)| | 1 |00:00:00.01 | 2 |
| 1 | TABLE ACCESS BY INDEX ROWID BATCHED| T | 1 | 1 | 9 | 2 (0)| 00:00:01 | 1 |00:00:00.01 | 2 |
|* 2 | INDEX RANGE SCAN | IF_T_NAME | 1 | 1 | | 1 (0)| 00:00:01 | 1 |00:00:00.01 | 1 |
-------------------------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / T@SEL$1
2 - SEL$1 / T@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("T"."SYS_NC00003$"=HEXTORAW('9E9E9E9E9EFF'))
--//也可以這樣寫:
SCOTT@test01p> select * from t where sys_op_descend(name)=hextoraw(sys_op_descend('aaaaa'));
ID NAME
---------- --------------------
1 aaaaa
SCOTT@test01p> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 8m2ns5w7bk60d, child number 0
-------------------------------------
select * from t where sys_op_descend(name)=hextoraw(sys_op_descend('aaaa
a'))
Plan hash value: 4146574435
-------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers |
-------------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 2 (100)| | 1 |00:00:00.01 | 2 |
| 1 | TABLE ACCESS BY INDEX ROWID BATCHED| T | 1 | 1 | 9 | 2 (0)| 00:00:01 | 1 |00:00:00.01 | 2 |
|* 2 | INDEX RANGE SCAN | IF_T_NAME | 1 | 1 | | 1 (0)| 00:00:01 | 1 |00:00:00.01 | 1 |
-------------------------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / T@SEL$1
2 - SEL$1 / T@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("T"."SYS_NC00003$"=HEXTORAW('9E9E9E9E9EFF'))
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2221532/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20181124]關於降序索引問題3.txt索引
- [20181124]關於降序索引問題2.txt索引
- [20181123]關於降序索引問題.txt索引
- [20191218]降序索引疑問4.txt索引
- [20190910]關於降序索引問題5.txt索引
- 不能建立降序索引的問題的解決索引
- [20191209]降序索引疑問.txt索引
- [20191209]降序索引疑問2.txt索引
- [20200303]降序索引疑問5.txt索引
- [20191210]降序索引疑問3.txt索引
- [20210520]關於主鍵索引問題.txt索引
- [20190918]關於函式索引問題.txt函式索引
- 關於聯合索引,範圍查詢,時間列索引的幾個問題索引
- 關於索引索引
- [20231116]降序索引取最大值.txt索引
- [20191219]降序索引與取最大值.txt索引
- 關於this指向的問題
- 關於跨域問題跨域
- [20191202]關於hugepages相關問題.txt
- 關於 go-micro 相關問題Go
- 關於盒模型相關的問題模型
- 關於 Puerts 的效能問題
- 關於django跨域問題Django跨域
- 關於並查集問題並查集
- 關於 swoole 除錯問題除錯
- 關於dcat-admin問題
- 關於JQuery操作checkbox問題jQuery
- 關於rem佈局問題REM
- 關於MQTT 使用遇到問題MQQT
- 關於DrawerLayout的小問題
- 關於javascript的this指向問題JavaScript
- 關於pcl索引的使用索引
- 關於安裝nbextensions的問題
- 關於 a 標籤跳轉問題
- 關於影像識別的問題
- 關於redis配置找不到問題Redis
- 關於 Laravel 分頁的問題?Laravel
- [20191129]關於hugepages的問題.txt