分析行連結的簡單方法
最近做優化,發現系統的行連線比較多,但是用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(超簡單)--單連結串列的插入和刪除
- C++連結串列類的簡單操作含圖書結構體 簡單易懂C++結構體
- 資料結構之連結串列與陣列(3):單向連結串列上的簡單操作資料結構陣列
- 線性表中的單向連結串列的簡單操作
- 連結a的download屬性簡單介紹
- 初始化ArrayList的簡單方法總結
- 資料結構之連結串列與陣列(2):單向連結串列上的簡單操作問題資料結構陣列
- 簡單瞭解 oracle update 原理(測試)、 行遷移/行連結基本認識Oracle
- Linux 上分析死鎖的最簡單方法Linux
- 簡單介紹python中的單向連結串列實現Python
- 快排單連結串列;及乾坤大挪移的分析
- 反轉連結串列(C++簡單區)C++
- 菜鳥圖解簡單連結串列(轉)圖解
- 單執行緒-非阻塞-長連結執行緒
- animate動畫連續執行簡單介紹動畫
- 簡單的排序方法排序
- openGauss核心分析2:簡單查詢的執行
- 最多連續數的子集及單連結串列和之戀分析及解答
- leetcode:21. 合併兩個有序連結串列(連結串列,簡單)LeetCode
- 如何製作一份帶超連結的工作表目錄,這裡有簡單的方法
- 簡單總結nodejs處理tcp連線的核心流程NodeJSTCP
- 長 URL 轉短連結的簡單設計與實現
- 簡單高效的短連結生成服務C#實現C#
- 簡單的UrlDns鏈分析DNS
- Photoshop學習方法論簡單總結(轉)
- 提高程式執行效率的10個簡單方法
- 【效能優化】消除行連結和行遷移的思路和方法優化
- 資料結構系列之單連結串列實現一個簡單的LRU演算法資料結構演算法
- 簡簡單單的總結,意如生活的平淡
- 連結串列-單連結串列實現
- hashCode()方法原始碼執行簡要分析原始碼
- 簡單分析ThreadPoolExecutor回收工作執行緒的原理thread執行緒
- ExplosionField簡單分析
- Pygame的簡單總結GAM
- 【效能最佳化】消除行連結和行遷移的思路和方法
- 簡單的php連線mysql類PHPMySql