檢視儲存過程的執行計劃
儲存過程沒有執行計劃,檢視的是儲存過程中SQL語句的執行計劃,這裡用10046來看 ---------------------------------------------------- 建立儲存過程 Create Or Replace Procedure Lee_Xc(Eno Number) Is Begin Select Empno, Ename, Dname From Emp, Dept Where Emp.Deptno = Dept.Deptno And Emp.Deptno = Eno; Commit; End; / ---------------------------------------------------- 追蹤10046 SQL> alter session set events '10046 trace name context forever, level 12'; Session altered SQL> exec LEE_HK(8800186378); PL/SQL procedure successfully completed SQL> alter session set events '10046 trace name context off'; Session altered SQL> SQL> SELECT d.VALUE 2 || '/' 3 || LOWER (RTRIM (i.INSTANCE, CHR (0))) 4 || '_ora_' 5 || p.spid 6 || '.trc' as "trace_file_name" 7 FROM (SELECT p.spid 8 FROM v$mystat m, v$session s, v$process p 9 WHERE m.statistic# = 1 AND s.SID = m.SID AND p.addr = s.paddr) p, 10 (SELECT t.INSTANCE 11 FROM v$thread t, v$parameter v 12 WHERE v.NAME = 'thread' 13 AND (v.VALUE = 0 OR t.thread# = TO_NUMBER (v.VALUE))) i, 14 (SELECT VALUE 15 FROM v$parameter 16 WHERE NAME = 'user_dump_dest') d 17 ; trace_file_name -------------------------------------------------------------------------------- /oracle/admin/jsjdata0/udump/jsjdata0_ora_19658.trc ---------------------------------------------------- 格式轉換一下 [
[email protected] udump]$ tkprof jsjdata0_ora_19984.trc lee1 sys=no explain=gcbb/gcbb [[email protected] udump]$ more lee5.prf TKPROF: Release 10.2.0.1.0 - Production on Thu Apr 26 14:50:56 2012 Copyright (c) 1982, 2005, Oracle. All rights reserved. Trace file: jsjdata0_ora_19984.trc Sort options: default ******************************************************************************** count = number of times OCI procedure was executed cpu = cpu time in seconds executing elapsed = elapsed time in seconds executing disk = number of physical reads of buffers from disk query = number of buffers gotten for consistent read current = number of buffers gotten in current mode (usually for update) rows = number of rows processed by the fetch or execute call ******************************************************************************** alter session set events '10046 trace name context forever, level 12' call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 0 0.00 0.00 0 0 0 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 0 0.00 0.00 0 0 0 0 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 1 0.00 0.00 0 0 0 0 Misses in library cache during parse: 0 Misses in library cache during execute: 1 Optimizer mode: ALL_ROWS Parsing user id: 54 (SCOTT) Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ SQL*Net message to client 1 0.00 0.00 SQL*Net message from client 1 0.03 0.03 ******************************************************************************** begin :id := sys.dbms_transaction.local_transaction_id; end; call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 4 0.00 0.00 0 0 0 0 Execute 4 0.00 0.00 0 0 0 4 Fetch 0 0.00 0.00 0 0 0 0 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 8 0.00 0.00 0 0 0 4 Misses in library cache during parse: 0 Optimizer mode: ALL_ROWS Parsing user id: 54 (SCOTT) Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ SQL*Net message to client 4 0.00 0.00 SQL*Net message from client 4 8.29 16.08 ******************************************************************************** select 'x' from dual call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 2 0.00 0.00 0 0 0 0 Execute 2 0.00 0.00 0 0 0 0 Fetch 2 0.00 0.00 0 0 0 2 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 6 0.00 0.00 0 0 0 2 Misses in library cache during parse: 0 Optimizer mode: ALL_ROWS Parsing user id: 54 (SCOTT) Rows Row Source Operation ------- --------------------------------------------------- 1 FAST DUAL (cr=0 pr=0 pw=0 time=10 us) Rows Execution Plan ------- --------------------------------------------------- 0 SELECT STATEMENT MODE: ALL_ROWS 1 FAST DUAL Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ SQL*Net message to client 4 0.00 0.00 SQL*Net message from client 4 0.01 0.03 ******************************************************************************** begin lee_xc(7788); end; --這裡可以看到輸入的引數 call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.00 0.00 0 0 0 0 Execute 1 0.00 0.00 0 0 0 1 Fetch 0 0.00 0.00 0 0 0 0 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 2 0.00 0.00 0 0 0 1 Misses in library cache during parse: 1 Optimizer mode: ALL_ROWS Parsing user id: 54 (SCOTT) Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ log file sync 1 0.00 0.00 SQL*Net message to client 1 0.00 0.00 SQL*Net message from client 1 0.03 0.03 ******************************************************************************** UPDATE EMP SET SAL = 30000 --這裡看到帶參的SQL WHERE EMPNO = :B1 call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 0 0.00 0.00 0 0 0 0 Execute 1 0.00 0.00 0 1 2 1 Fetch 0 0.00 0.00 0 0 0 0 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 1 0.00 0.00 0 1 2 1 Misses in library cache during parse: 0 Optimizer mode: ALL_ROWS Parsing user id: 54 (SCOTT) (recursive depth: 1) Rows Execution Plan ---這裡就是執行計劃了 ------- --------------------------------------------------- 0 UPDATE STATEMENT MODE: ALL_ROWS 0 UPDATE OF 'EMP' 0 INDEX MODE: ANALYZED (UNIQUE SCAN) OF 'PK_EMP' (INDEX (UNIQUE)) ******************************************************************************** COMMIT call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 0 0.00 0.00 0 0 0 0 Execute 1 0.00 0.00 0 0 1 0 Fetch 0 0.00 0.00 0 0 0 0 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 1 0.00 0.00 0 0 1 0 Misses in library cache during parse: 0 Parsing user id: 54 (SCOTT) (recursive depth: 1) ******************************************************************************** alter session set events '10046 trace name context off' call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.00 0.00 0 0 0 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 0 0.00 0.00 0 0 0 0 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 2 0.00 0.00 0 0 0 0 Misses in library cache during parse: 1 Optimizer mode: ALL_ROWS Parsing user id: 54 (SCOTT) ******************************************************************************** OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 8 0.00 0.00 0 0 0 0 Execute 9 0.00 0.00 0 0 0 5 Fetch 2 0.00 0.00 0 0 0 2 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 19 0.00 0.00 0 0 0 7 Misses in library cache during parse: 2 Misses in library cache during execute: 1 Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ SQL*Net message to client 10 0.00 0.00 SQL*Net message from client 10 8.29 16.17 log file sync 1 0.00 0.00 OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 0 0.00 0.00 0 0 0 0 Execute 2 0.00 0.00 0 1 3 1 Fetch 0 0.00 0.00 0 0 0 0 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 2 0.00 0.00 0 1 3 1 Misses in library cache during parse: 0 11 user SQL statements in session. 0 internal SQL statements in session. 11 SQL statements in session. 2 statements EXPLAINed in this session. ******************************************************************************** Trace file: jsjdata0_ora_19984.trc Trace file compatibility: 10.01.00 Sort options: default 1 session in tracefile. 11 user SQL statements in trace file. 0 internal SQL statements in trace file. 11 SQL statements in trace file. 7 unique SQL statements in trace file. 2 SQL statements EXPLAINed using schema: SCOTT.prof$plan_table Default table was used. Table was created. Table was dropped. 144 lines in trace file. 16 elapsed seconds in trace file.
相關推薦
檢視儲存過程的執行計劃
儲存過程沒有執行計劃,檢視的是儲存過程中SQL語句的執行計劃,這裡用10046來看 ---------------------------------------------------- 建立儲存過程 Create Or Replace Procedure Lee_
mysql儲存過程和計劃任務【叢集下,計劃任務的執行控制】
DROP PROCEDURE IF EXISTS `p_test_cluster`; DELIMITER ;; CREATE PROCEDURE `p_test_cluster`() BEGIN DECLARE iState INTEGER DEFAULT 0;
ORACLE儲存過程執行報“ora-00942表或檢視不存在”、“ORA-01031:許可權不足”的解決方式
目錄: 一、案例 二、思索過程 三、解決方案 四、後記 正文 一、案例: 在userA使用者下書寫儲存過程如下: create or replace procedure sp_test is v_str1 varchar2(1000); begi
存儲過程執行計劃緩存查詢
bstr where 1=1 desc .text ast 計劃 oss 計劃緩存 outer SELECT st.Text,SUBSTRING(st.Text, (qs.statement_start_offset/2)+1,((CASE qs.statement_end
通過儲存過程執行通過DBLINK的查詢語句失敗-單個語句成功--ORA-00604
客戶遇到個問題,描寫敘述例如以下:--環境是ORACLE 9.2.0.8 (語句及場景非真實了。網上找的。情況是一致的) 建立了一個DB_LINK連線還有一個Oracle資料庫。 select * from [email protected]; 單句執行沒
MYSQL 儲存過程與計劃任務結合使用
使用計劃任務讓資料庫在某個時間自動執行一個儲存過程 儲存過程 delimiter // create procedure integral_ba
MySQL之刪除和檢視儲存過程
(1)一次只能刪除一個儲存過程或者函式。注意,要具有ALTER ROUTINE許可權 (2)刪除語句: DROP {PROCEDURE | FUNCTION} [IF EXISTS] sp_name 示例語句: DROP PROCEDURE film_in_
SQL Server 只讀賬號/只讀登入名可檢視儲存過程及函式許可權
公司為了收緊生產資料庫的登入名,目前我們公司生產資料庫登入名基本賦予了sa賬戶的許可權,這樣做是很危險的,所以領導要求給運維同事授予資料庫只讀查詢的賬號,但同時又需要讓運維同事可檢視儲存過程,因為儲存過程和函式中有很多攔截異常的判斷,當提示報錯內容時,運維同事可以通過報錯的關
Oracle儲存過程執行初體驗
1、首先在plsql中建立一個插入語句的儲存過程(已經建立好表,兩列,id,name) create or replace procedure proc_suibian_insert(id in var
java傳list到Oracle儲存過程執行慢
儲存過程功能是迴圈對list遍歷,對錶進行插入操作,插入異常則進行修改操作。 可能為update語句執行慢,可是表裡有主鍵,update時主鍵為條件,走主鍵應該不會慢。 單獨把update語句拿出執行,不慢。 最終找出原因,list中物件用的為nvarchar而表裡主鍵為varchar2,執行語句時Or
Mysql(增刪改查)+檢視+儲存過程【常用】
一,MySQL(一般): 1,建立資料庫: SET FOREIGN_KEY_CHECKS=0; // 修改外來鍵約束( Mysql中如果表和表之間建立的外來鍵約束,則無法刪除表及修改表結構 ) DROP TABLE IF EXISTS `user`; // DROP
DB2 檢視儲存過程內容並匯出
1.檢視儲存過程內容: [email protected]:~>db2 "select * from syscat.PROCEDURES where PROCNAME ='?'" 2.匯出儲存過程資訊: [email protected]:~&g
[轉]SqlServer中Sql檢視儲存過程
SqlServer中Sql檢視儲存過程 ( 一)利用Sql語句查詢資料庫中的所有表 1.利用sysobjects系統表 select * from sysobjects where xtype='U' 2,利用sys.tables目錄檢視 sys.t
sql相關:檢視儲存過程和表結構
sql資料庫相關: 1,檢視儲存過程的內建函式:sp_helptexteg:sp_helptext 儲存過程名 2,提供一個儲存過程用於檢視資料庫表的新結構tbinfo create procedu
遭瘟的pyodbc——關於儲存過程執行
由於需要使用django連線SQL Server,煩人的事情隨之而來。 首先Django 沒有自帶針對MSSQL的BackEnds,所以要自己包裝,這個很煩很煩,煩到死了,每次部署到新的機器上都要除錯很久。 可以見我之前寫的這篇文章:Django連線SQL Server配置
mysql 方法或者儲存過程執行慢的除錯方法
第一步:修改/etc/my.cnf檔案,找到[mysqld] 裡面加入 #執行的sql log=/tmp/logs/mysqld.log #記錄sql執行超過下面設定時間的sql log-slow-queries = /tmp/mysqlslowquery.log #
oracle字符集亂碼及返回 REF CURSOR 的儲存過程執行問題
關於oracle字符集亂碼問題: 1.OracleClient方式 存在亂碼問題。(比如:當Oracle資料庫伺服器端採用英文字符集比如 US7ASCII 時,客戶端不管字符集如何設定,讀出的中文都是亂碼;若伺服器端用中文字符集比如 ZHS16GBK ,則無亂碼問題。
儲存過程執行速度優化
儲存過程做的報表在實際運用中時快時慢: 1.首先檢視儲存過程中是否有很多重複的實體表(一般給報表寫儲存過程,第一步就是使用臨時表); 2.如果反覆使用的實體表很多,就要考慮將這個實體表最小範圍的資料放到臨時表中,這樣就可以大大提高查詢效率
儲存過程執行很慢,請求優化
SELECT TD.CourseID,TU.StudentUserID,COUNT(EU.ExerciseSubjectID) AS SubmitCouont ,COUNT(ES.ExerciseSubjectID)-COUNT(EU.ExerciseSubjectI
mysql儲存過程執行動態sql語句並返回值
Java程式碼 set @sql=’xxx’; prepare stmt from @sql; execute stmt; deallocate prepare stmt; select @curd1; set @sql=’xxx’; prepare stmt f