0429建立Extended Statistics函式索引問題
[20160429]建立Extended Statistics 和函式索引問題.txt
--11G支援相關資料的統計分析,比如如果兩個欄位存在相關性透過分析,能夠得到更加良好的統計資訊,以及生成好的執行計劃.
--但是如果結合函式索引呢?透過一個簡單的例子來說明:
--前次做的測試:
http://blog.itpub.net/267265/viewspace-2089119/
1.環境:
SCOTT@book> @ &r/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
SCOTT@book> create table t (a number, b date);
Table created.
2.建立Extended Statistics:
SCOTT@book> select dbms_stats.create_extended_stats(user,'T','(a,trunc(b))') from dual;
select dbms_stats.create_extended_stats(user,'T','(a,trunc(b))') from dual
*
ERROR at line 1:
ORA-20001: Invalid Extension: Column group can contain only columns seperated by comma
--可以看出建立 Column group僅僅包含欄位,使用,隔開.
SCOTT@book> select dbms_stats.create_extended_stats(user,'T','(a,b)') from dual;
DBMS_STATS.CREATE_EXTENDED_STATS(USER,'T','(A,B)')
--------------------------------------------------
SYS_STUNA$6DVXJXTP05EH56DTIR0X
SCOTT@book> exec dbms_stats.drop_extended_stats(user,'T','(a,b)') ;
PL/SQL procedure successfully completed.
--上次我透過建立索引來實現函式+欄位的Extended Statistics ,如果仔細看前面的提示建立索引後建立了一個hidden以及虛擬列
--SYS_NC00003$,如果我先建立一個虛擬列應該也可以實現.測試:
--建立虛擬列:
SCOTT@book> alter table t add (c date generated always as (trunc(b)));
Table altered.
SCOTT@book> select owner,table_name,column_name,data_type,data_default,hidden_column,virtual_column from DBA_TAB_COLS where owner=user and table_name='T';
OWNER TABLE_NAME COLUMN_NAME DATA_TYPE DATA_DEFAULT HID VIR
------ ---------- -------------------- ---------- -------------------- --- ---
SCOTT T C DATE TRUNC("B") NO YES
SCOTT T B DATE NO NO
SCOTT T A NUMBER NO NO
SCOTT@book> select dbms_stats.create_extended_stats(user,'T','(a,trunc(b))') c40 from dual;
C40
----------------------------------------
SYS_STU021V7H9RNW$DK6GQ1ZFI5B#
--OK!不過明顯跟以前定義的名字不一樣.前面測試如下:
SCOTT@book> select dbms_stats.create_extended_stats(user,'T','(a,trunc(b))') from dual;
DBMS_STATS.CREATE_EXTENDED_STATS(USER,'T','(A,TRUNC(B))')
----------------------------------------------------------
SYS_STUE4B2X1G802ME0XHTBYWFY_Q
--SYS_STUE4B2X1G802ME0XHTBYWFY_Q 與 SYS_STU021V7H9RNW$DK6GQ1ZFI5B# 不同.
SCOTT@book> select owner,table_name,column_name,data_type,data_default,hidden_column,virtual_column from DBA_TAB_COLS where owner=user and table_name='T';
OWNER TABLE_NAME COLUMN_NAME DATA_TYPE DATA_DEFAULT HID VIR
------ ---------- ------------------------------ ---------- ---------------------------------------- --- ---
SCOTT T SYS_STU021V7H9RNW$DK6GQ1ZFI5B# NUMBER SYS_OP_COMBINED_HASH("A",TRUNC("B")) YES YES
SCOTT T C DATE TRUNC("B") NO YES
SCOTT T B DATE NO NO
SCOTT T A NUMBER NO NO
SCOTT@book> select dbms_stats.create_extended_stats(user,'T','(a,c)') c40 from dual;
select dbms_stats.create_extended_stats(user,'T','(a,c)') c40 from dual
*
ERROR at line 1:
ORA-20001: Error when processing extension - virtual column is referenced in a column expression
ORA-06512: at "SYS.DBMS_STATS", line 8676
ORA-06512: at "SYS.DBMS_STATS", line 33335
--可以看出實際上建立的(a,c)的Extended Statistics.
SCOTT@book> exec dbms_stats.drop_extended_stats(user,'T','(a,trunc(b))');
PL/SQL procedure successfully completed.
--而刪除後如用如下建立Extended Statistics
SCOTT@book> select dbms_stats.create_extended_stats(user,'T','(a,c)') c40 from dual;
select dbms_stats.create_extended_stats(user,'T','(a,c)') c40 from dual
*
ERROR at line 1:
ORA-20001: Error when processing extension - virtual column is referenced in a column expression
ORA-06512: at "SYS.DBMS_STATS", line 8676
ORA-06512: at "SYS.DBMS_STATS", line 33335
--很明顯不能包含virtual column.
SCOTT@book> alter table t drop column c;
Table altered.
SCOTT@book> create index if_t_ab on t(a,trunc(b));
Index created.
SCOTT@book> select owner,table_name,column_name,data_type,data_default,hidden_column,virtual_column from DBA_TAB_COLS where owner=user and table_name='T';
OWNER TABLE_NAME COLUMN_NAME DATA_TYPE DATA_DEFAULT HID VIR
------ ---------- ------------------------------ ---------- ---------------------------------------- --- ---
SCOTT T SYS_NC00003$ DATE TRUNC("B") YES YES
SCOTT T B DATE NO NO
SCOTT T A NUMBER NO NO
SCOTT@book> select dbms_stats.create_extended_stats(user,'T','(a,SYS_NC00003$)') c40 from dual;
select dbms_stats.create_extended_stats(user,'T','(a,SYS_NC00003$)') c40 from dual
*
ERROR at line 1:
ORA-20001: Error when processing extension - virtual column is referenced in a column expression
ORA-06512: at "SYS.DBMS_STATS", line 8676
ORA-06512: at "SYS.DBMS_STATS", line 33335
--一樣不行.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2090522/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 0427建立Extended Statistics函式索引問題函式索引
- 函式索引的問題函式索引
- 建立聯合函式索引解決top sql效能問題函式索引SQL
- 關於函式索引的問題?函式索引
- 建立函式索引須知DETERMINISTIC函式索引
- 測試建立基於函式的索引函式索引
- [20180509]函式索引問題.txt函式索引
- [Q]怎樣建立基於函式索引zt函式索引
- [20180212]函式索引問題.txt函式索引
- 利用函式索引解決複雜的約束問題函式索引
- [20190918]關於函式索引問題.txt函式索引
- 函式索引陷阱函式索引
- oracle函式索引Oracle函式索引
- 函式索引使用細節——自定義函式的索引化函式索引
- 不能建立降序索引的問題的解決索引
- SQL SERVER建立索引需要注意的問題SQLServer索引
- [20150803]使用函式索引注意的問題.txt函式索引
- 建立函式函式
- Oracle之函式索引Oracle函式索引
- 說說函式索引函式索引
- 索引中使用函式索引函式
- 關於Hash 函式 雜湊索引表 解決位置衝突的問題函式索引
- 函式呼叫棧的問題函式
- itoa函式的奇怪問題函式
- 窗體建立和函式關聯相關的兩個小問題函式
- 基於函式的索引函式索引
- deterministic function 函式索引Function函式索引
- 函式索引的儲存函式索引
- SQL優化--函式索引SQL優化函式索引
- sequence 和索引函式呼叫索引函式
- 函式內部This的指向問題函式
- 關於scanf函式的問題函式
- 批量註冊事件處理函式索引總是最後一個問題解決事件函式索引
- 建立函式失敗函式
- Oracle索引梳理系列(六)- Oracle索引種類之函式索引Oracle索引函式
- MySQL函式索引及優化MySql函式索引優化
- Oracle基於函式的索引Oracle函式索引
- 索引ROWID轉換函式索引函式