分析行連結的簡單方法
最近做優化,發現系統的行連線比較多,但是用analyze分析太慢,影響也比較大
於是從SESSION統計方面入手,寫了個簡單的分析行連線的指令碼。效果相當不錯
--------------------------------------------------------------------------------
--
-- File name: chains_stats.sql
-- Author: zhangqiao
-- Copyright: zhangqiaoc@olm.com.cn
--
--------------------------------------------------------------------------------
DECLARE
LN_ROW_CNT_1 NUMBER;
LN_ROW_CNT_2 NUMBER;
LN_ROW_CONTINUED_1 NUMBER;
LN_ROW_CONTINUED_2 NUMBER;
LN_CNT NUMBER;
LVC_SQL VARCHAR2(4000);
LVC_STATS_SQL VARCHAR2(4000) := '
SELECT SUM(DECODE(NAME, ''table scan rows gotten'', VALUE)) ROW_CNT,
SUM(DECODE(NAME, ''table fetch continued row'', VALUE)) ROW_CONTINUED
FROM V$MYSTAT A, V$STATNAME B
WHERE A.STATISTIC# = B.STATISTIC#
AND NAME IN (''table scan rows gotten'', ''table fetch continued row'')';
CURSOR C1 IS
SELECT OWNER, SEGMENT_NAME, PARTITION_NAME, SEGMENT_TYPE
FROM DBA_SEGMENTS
WHERE SEGMENT_TYPE LIKE 'TABLE%'
AND WNER = '&1';
BEGIN
BEGIN
EXECUTE IMMEDIATE 'create table zhangqiaoc_analyze_chains(
owner VARCHAR2(30),
table_name VARCHAR2(30),
partition_name varchar2(30),
segment_type VARCHAR2(30),
row_cnt NUMBER,
row_continued NUMBER,
ANALYZED_DATE DATE)';
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
FOR R1 IN C1 LOOP
EXECUTE IMMEDIATE LVC_STATS_SQL
INTO LN_ROW_CNT_1, LN_ROW_CONTINUED_1;
IF R1.SEGMENT_TYPE = 'TABLE' THEN
LVC_SQL := 'select /*+parallel(a,8)*/ count(*) from ' || R1.OWNER || '.' ||
R1.SEGMENT_NAME || ' a';
ELSIF R1.SEGMENT_TYPE = 'TABLE PARTITION' THEN
LVC_SQL := 'select /*+parallel(a,8)*/ count(*) from ' || R1.OWNER || '.' ||
R1.SEGMENT_NAME || ' partition(' || R1.PARTITION_NAME || ') a';
ELSIF R1.SEGMENT_TYPE = 'TABLE SUBPARTITION' THEN
LVC_SQL := 'select /*+parallel(a,8)*/ count(*) from ' || R1.OWNER || '.' ||
R1.SEGMENT_NAME || ' subpartition(' || R1.PARTITION_NAME || ') a';
END IF;
EXECUTE IMMEDIATE LVC_SQL
INTO LN_CNT;
EXECUTE IMMEDIATE LVC_STATS_SQL
INTO LN_ROW_CNT_2, LN_ROW_CONTINUED_2;
INSERT INTO ZHANGQIAOC_ANALYZE_CHAINS
SELECT R1.OWNER,
R1.SEGMENT_NAME,
R1.PARTITION_NAME,
R1.SEGMENT_TYPE,
LN_ROW_CNT_2 - LN_ROW_CNT_1,
LN_ROW_CONTINUED_2 - LN_ROW_CONTINUED_1,
SYSDATE
FROM DUAL;
COMMIT;
END LOOP;
END;
/
於是從SESSION統計方面入手,寫了個簡單的分析行連線的指令碼。效果相當不錯
--------------------------------------------------------------------------------
--
-- File name: chains_stats.sql
-- Author: zhangqiao
-- Copyright: zhangqiaoc@olm.com.cn
--
--------------------------------------------------------------------------------
DECLARE
LN_ROW_CNT_1 NUMBER;
LN_ROW_CNT_2 NUMBER;
LN_ROW_CONTINUED_1 NUMBER;
LN_ROW_CONTINUED_2 NUMBER;
LN_CNT NUMBER;
LVC_SQL VARCHAR2(4000);
LVC_STATS_SQL VARCHAR2(4000) := '
SELECT SUM(DECODE(NAME, ''table scan rows gotten'', VALUE)) ROW_CNT,
SUM(DECODE(NAME, ''table fetch continued row'', VALUE)) ROW_CONTINUED
FROM V$MYSTAT A, V$STATNAME B
WHERE A.STATISTIC# = B.STATISTIC#
AND NAME IN (''table scan rows gotten'', ''table fetch continued row'')';
CURSOR C1 IS
SELECT OWNER, SEGMENT_NAME, PARTITION_NAME, SEGMENT_TYPE
FROM DBA_SEGMENTS
WHERE SEGMENT_TYPE LIKE 'TABLE%'
AND WNER = '&1';
BEGIN
BEGIN
EXECUTE IMMEDIATE 'create table zhangqiaoc_analyze_chains(
owner VARCHAR2(30),
table_name VARCHAR2(30),
partition_name varchar2(30),
segment_type VARCHAR2(30),
row_cnt NUMBER,
row_continued NUMBER,
ANALYZED_DATE DATE)';
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
FOR R1 IN C1 LOOP
EXECUTE IMMEDIATE LVC_STATS_SQL
INTO LN_ROW_CNT_1, LN_ROW_CONTINUED_1;
IF R1.SEGMENT_TYPE = 'TABLE' THEN
LVC_SQL := 'select /*+parallel(a,8)*/ count(*) from ' || R1.OWNER || '.' ||
R1.SEGMENT_NAME || ' a';
ELSIF R1.SEGMENT_TYPE = 'TABLE PARTITION' THEN
LVC_SQL := 'select /*+parallel(a,8)*/ count(*) from ' || R1.OWNER || '.' ||
R1.SEGMENT_NAME || ' partition(' || R1.PARTITION_NAME || ') a';
ELSIF R1.SEGMENT_TYPE = 'TABLE SUBPARTITION' THEN
LVC_SQL := 'select /*+parallel(a,8)*/ count(*) from ' || R1.OWNER || '.' ||
R1.SEGMENT_NAME || ' subpartition(' || R1.PARTITION_NAME || ') a';
END IF;
EXECUTE IMMEDIATE LVC_SQL
INTO LN_CNT;
EXECUTE IMMEDIATE LVC_STATS_SQL
INTO LN_ROW_CNT_2, LN_ROW_CONTINUED_2;
INSERT INTO ZHANGQIAOC_ANALYZE_CHAINS
SELECT R1.OWNER,
R1.SEGMENT_NAME,
R1.PARTITION_NAME,
R1.SEGMENT_TYPE,
LN_ROW_CNT_2 - LN_ROW_CNT_1,
LN_ROW_CONTINUED_2 - LN_ROW_CONTINUED_1,
SYSDATE
FROM DUAL;
COMMIT;
END LOOP;
END;
/
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8242091/viewspace-720512/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 簡單的單向連結串列
- 連結串列基礎2(超簡單)--單連結串列的插入和刪除
- 簡單連結串列——尾插法
- 線性表中的單向連結串列的簡單操作
- 簡單介紹python中的單向連結串列實現Python
- 初始化ArrayList的簡單方法總結
- leetcode:21. 合併兩個有序連結串列(連結串列,簡單)LeetCode
- 反轉連結串列(C++簡單區)C++
- openGauss核心分析2:簡單查詢的執行
- 單執行緒-非阻塞-長連結執行緒
- 簡單總結nodejs處理tcp連線的核心流程NodeJSTCP
- hashCode()方法原始碼執行簡要分析原始碼
- 簡單的排序方法排序
- 如何製作一份帶超連結的工作表目錄,這裡有簡單的方法
- 用遞迴的方法將單連結串列逆向輸出遞迴
- 簡單分析ThreadPoolExecutor回收工作執行緒的原理thread執行緒
- 連結串列 - 單向連結串列
- 單連結串列的建立
- 簡單的UrlDns鏈分析DNS
- 資料結構系列之單連結串列實現一個簡單的LRU演算法資料結構演算法
- 簡簡單單的總結,意如生活的平淡
- 【leetcode 簡單】第三十七題 相交連結串列LeetCode
- 單連結串列
- 連結串列-單連結串列實現
- 使用tensorboard的簡單方法ORB
- 55-將單連結串列原地逆置(有頭結點的單連結串列)
- Linux 軟連結和硬連結簡介Linux
- spring 簡單的使用 Hikari連線池 和 jdbc連線mysql 的一個簡單例子SpringJDBCMySql單例
- Pygame的簡單總結GAM
- 單向連結串列的建立
- python中取絕對值簡單方法總結Python
- HTML 連結簡介HTML
- 簡單的php連線mysql類PHPMySql
- 簡談linux中軟連結和硬連結的區別Linux
- 建設外部連結的方法
- 用單連結串列實現多項式加,減,乘,簡單微分
- 《簡明的TensorFlow 2》連結表
- 資料結構-單連結串列、雙連結串列資料結構
- 在連結與執行地址不同時gdb的除錯方法除錯