1. 程式人生 > >[20181124]關於降序索引問題3.txt

[20181124]關於降序索引問題3.txt

[20181124]關於降序索引問題3.txt

--//連結:blog.itpub.net/267265/viewspace-2221425/,探討降序索引中索引的鍵值。
--//實際上使用函式sys_op_descend.

--//連結:http://blog.itpub.net/267265/viewspace-2221527/,探討了僅僅設計字串的編碼.
--//字串0x00,0x0000,0x0001,0x00NN(0xNN>=0x02),0x01,0x0100,0x0101,0x01NN(0xNN>=0x02) 單獨編碼。畫一個表格:
ascii碼                 編碼
---------------------------------------------
0x00                    FEFE
0x0000                  FEFD
0x0001                  FEFC
0x00NN(0xNN>=0x02)      FEFB
0x01                    FEFA
0x0100                  FEF9
0x0101                  FEF8        
0x01NN(0xNN>=0x02)      FEF7
---------------------------------------------

--//對於numbe,date型別如何呢?
--//我在沒有測試前,感覺不會出現像字串那樣的編碼,因為資料型別,日期型別儲存格式規避0x00,這樣不會出現像字串那樣的情況.
--//還是通過測試說明問題.

1.環境:

[email protected]> @ 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.測試:
[email protected]
> select sys_op_descend(10001),dump(10001,16) c30 from dual ;
SYS_OP_DESCE C30
------------ ------------------------------
3CFDFEF7FDFF Typ=2 Len=4: c3,2,1,2

--//還是有點出乎我的意料,可以發現還是按照上面字串編碼的規律:
3C FD FEF7 FD
c3 02 01  02
--//中間 01 編碼 FEF7(按照0x01NN編碼).

[email protected]> select sys_op_descend(1000001),dump(1000001,16) c30 from dual ;
SYS_OP_DESCE C30
------------ ------------------------------
3BFDFEF8FDFF Typ=2 Len=5: c4,2,1,1,2

3B FD FEF8 FD
c4 02 0101 02
--//中間 0101 對應編碼 0x0101.

3.繼續測試日期看看:
--//注意一個細節date型別,oracle存在2種類型(12,13),儲存在資料庫塊中的型別是type=12.
[email protected]
> select dump(to_date('1980-12-17 00:00:00','yyyy-mm--dd hh24:mi:ss'),16) c40 ,dump(hiredate,16) c40 ,hiredate from emp where rownum=1 ;
C40                                      C40                                      HIREDATE
---------------------------------------- ---------------------------------------- -------------------
Typ=13 Len=8: bc,7,c,11,0,0,0,0          Typ=12 Len=7: 77,b4,c,11,1,1,1           1980-12-17 00:00:00

--//可以發現type=12,時分秒都在原來的基礎上+1,這樣規避0x00.月份在1-12不會出現0的情況,不加1.日期在1-31,也是一樣0的情況.
--//一些細節可以看連結:http://blog.itpub.net/4227/viewspace-68514/

[email protected]> select sys_op_descend(hiredate) c40 ,dump(hiredate,16) c40,hiredate from emp where rownum=1 ;
C40                                      C40                                      HIREDATE
---------------------------------------- ---------------------------------------- -------------------
884BF3EEFEF8FEFAFF                       Typ=12 Len=7: 77,b4,c,11,1,1,1           1980-12-17 00:00:00


88 4B F3 EE FEF8 FEFA
77 b4 0c 11 0101 01
--//對照前面的編碼都可以對上.

4.是否真實是這樣呢?建立表測試看看:

[email protected]> create table t ( id number,cr_date date);
Table created.

insert into t values (1,sysdate);
insert into t values (10001,trunc(sysdate));
insert into t values (1000001,to_date('1980-12-17 00:00:00','yyyy-mm-dd hh24:mi:ss'));
commit ;

[email protected]> select * from t;
        ID CR_DATE
---------- -------------------
         1 2018-11-24 20:31:32
     10001 2018-11-24 00:00:00
   1000001 1980-12-17 00:00:00

--//分別看看降序索引的情況:
[email protected]> create  index if_t_all on t(id ,id desc ,cr_date,cr_date desc);
Index created.

[email protected]> select segment_name,header_file,header_block from dba_segments where owner=user and segment_name in ('IF_T_ALL');
SEGMENT_NAME         HEADER_FILE HEADER_BLOCK
-------------------- ----------- ------------
IF_T_ALL                      11          194

[email protected]> alter system flush buffer_cache;
System altered.

[email protected]> alter system dump datafile 11 block 195;
System altered.

--//檢查轉儲檔案:
row#0[8003] flag: -------, lock: 0, len=33
col 0; len 2; (2):  c1 02
col 1; len 3; (3):  3e fd ff
col 2; len 7; (7):  78 76 0b 18 15 20 21
col 3; len 8; (8):  87 89 f4 e7 ea df de ff
col 4; len 6; (6):  02 c0 00 be 00 00
row#1[7964] flag: -------, lock: 0, len=39
col 0; len 4; (4):  c3 02 01 02
col 1; len 6; (6):  3c fd fe f7 fd ff
col 2; len 7; (7):  78 76 0b 18 01 01 01
col 3; len 9; (9):  87 89 f4 e7 fe f8 fe fa ff
col 4; len 6; (6):  02 c0 00 be 00 01
row#2[7924] flag: -------, lock: 0, len=40
col 0; len 5; (5):  c4 02 01 01 02
col 1; len 6; (6):  3b fd fe f8 fd ff
col 2; len 7; (7):  77 b4 0c 11 01 01 01
col 3; len 9; (9):  88 4b f3 ee fe f8 fe fa ff
col 4; len 6; (6):  02 c0 00 be 00 02
----- end of leaf block Logical dump -----

--//可以發現與前面單獨測試都一樣.看來我以前思考問題簡單化了.^_^.